Skip to content
XSS Disclosed report Intermediate

XSS from Mastodon embeds

lotsofloops Follow

Originally disclosed on HackerOne

Bounty$500 High View original
  • Fixed in 2 days
  • Paid in 18 hours
  • Disclosed after 7 months

By default, the IRCCloud web client embeds Mastodon toots when a link to one is sent. Anyone can run a Mastodon server, and so the server from which toot data is fetched might be malicious. It is possible for an attacker to cause a web client user to execute arbitrary JavaScript in the context of the IRCCloud web client by tricking the web client into embedding a javascript: URL.

POC:

  1. Ensure "Embed social media links" is enabled in settings under "Chat & embeds" (I think this is on by default)
  2. Send a message with a link to https://sm4.ca/@a/123456789012345678 (the link itself 404s but IRCCloud only tries to use Mastodon API so it doesn't matter)
  3. Wait a few seconds for the embed to load
  4. Look at your session cookie

When the web client sees what looks like a toot URL, it tries to get canonical toot URL by making a query to [domain]/api/v1/statuses/[toot ID]. Here is what I serve at https://sm4.ca/api/v1/statuses/123456789012345678:

JSON
{
  "account": {
    "url": "https://sm4.ca/@a"
  },
  "url": "javascript:top.document.body.innerHTML = \"hi your cookie is \" + document.cookie;//"
}

(.account.url is only present because the web client ensures it matches the original link)

The web client creates an iframe using .url as the src, which in this case is a javascript: URL. The specified script runs in a seperate document that has access to its parent, and can access anything the parent can. The // is needed at the end since the web client appends /embed to the embed URL.

(also apart from this particular issue, I don't think Mastodon embeds should be enabled unless "Embed 3rd party image and video links" is enabled since even when the Mastodon server isn't malicious your IP address is still leaked to an arbitrary server)

Impact

An attacker who can send a message to an web-client-using IRCCloud user can obtain their session token and act as them. By sending a message with a malicious URL to a large channel an attacker could compromise many users at once.

The original report as published on HackerOne, by lotsofloops. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

IRCCloud is a web-based IRC client. Its web client has a feature that automatically embeds social media links when a message containing one is posted. By default, the client embeds Mastodon toots when a link to one is sent.

The important property of this feature is that anyone can run a Mastodon server. The server from which toot data is fetched is chosen by whoever wrote the link, so it may be malicious. The researcher's finding is that a malicious server can cause a web client user to execute arbitrary JavaScript in the context of the IRCCloud web client by tricking the client into embedding a javascript: URL.

Setup

The only precondition is that the "Embed social media links" setting is enabled under "Chat & embeds". The researcher believes this is on by default. No accounts, tools or versions beyond that are described.

Finding it

The answer was the toot's url, which the client uses as the src of an iframe.

Exploitation

Step 1: Confirm the setting is on

Ensure "Embed social media links" is enabled in settings under "Chat & embeds". The researcher notes it is probably on by default.

Step 2: Send a message containing a toot link

Send a message with a link to:

Text
https://sm4.ca/@a/123456789012345678

The link itself 404s, but that does not matter: IRCCloud only tries to use the Mastodon API, so the page behind the link is never needed.

Step 3: Wait for the embed

Wait a few seconds for the embed to load.

Step 4: Observe the result

Look at your session cookie. The script served by the malicious server has run in the context of the IRCCloud web client and read the cookie.

What the client requests

When the web client sees what looks like a toot URL, it tries to get the canonical toot URL by making a query to [domain]/api/v1/statuses/[toot ID]. For the link above, the researcher served this response at https://sm4.ca/api/v1/statuses/123456789012345678:

JSON
{
  "account": {
    "url": "https://sm4.ca/@a"
  },
  "url": "javascript:top.document.body.innerHTML = \"hi your cookie is \" + document.cookie;//"
}

The .account.url field is only present because the web client ensures it matches the original link. The url field is the payload: it is a javascript: URL.

What the client does with it

The web client creates an iframe using .url as the src, which in this case is a javascript: URL. The specified script runs in a separate document that has access to its parent, and can access anything the parent can. The // at the end is needed because the web client appends /embed to the embed URL; without the comment marker, that suffix would break the script.

Root cause

The client creates an iframe using .url from the API response as the src, which in this case is a javascript: URL. A javascript: URL in an iframe src executes script in a document that is same-origin with, and has access to, the parent page.

Impact

An attacker who can send a message to a web-client-using IRCCloud user can obtain their session token and act as them. By sending a message with a malicious URL to a large channel, an attacker could compromise many users at once.

Separately, the researcher notes that Mastodon embeds should probably not be enabled unless "Embed 3rd party image and video links" is enabled, since even when the Mastodon server is not malicious, the user's IP address is still leaked to an arbitrary server.

Fix

The report does not describe a fix.

Variants to test

  1. Other embed providers. Any feature that fetches metadata from a user-chosen domain and renders a URL from the response is a candidate. A positive result is a javascript: or data: URL reaching an iframe src or similar sink.
  2. Other fields in the same response. The report shows .url being used as a src; check whether other fields such as avatar or media URLs reach HTML or attribute sinks.
  3. Scheme handling in link rendering. Try links whose scheme is not http or https and see whether the client normalises or rejects them before embedding.

Hunting notes

This kind of bug hides in features that fetch data from third-party servers chosen by the sender: link previews, social embeds, oEmbed and Open Graph unfurlers. During recon, look for settings toggles that enable automatic embedding, and for client-side code that builds iframes from fetched metadata. The signal is a response field used directly as a URL in a DOM sink.

To show impact, the researcher demonstrated reading document.cookie from the parent context, which is enough to show session theft, and pointed out that a message to a large channel reaches many users at once.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 12 min read.

What happened, in plain words

IRCCloud is a chat service you use in a web browser. It connects to IRC, an old and still popular text chat system, and shows the conversations in a web page. One of its conveniences is that when someone posts a link to a social media post, the client does not just show a bare link: it fetches some information about that post and draws a small preview card, called an embed, right inside the chat.

Mastodon is a social network where anyone can set up their own server, a bit like anyone can set up their own email server. A "toot" is a Mastodon post. Because anyone can run a Mastodon server, the server that IRCCloud asks for information about a toot can be a server controlled by an attacker. The researcher found that a malicious server can answer with a specially crafted piece of data that makes the IRCCloud web page run JavaScript chosen by the attacker. JavaScript is the programming language that web pages run in your browser; if an attacker can run their own JavaScript inside a site you are logged into, they can do things as you, such as read your login session and take it over.

This class of bug is called cross-site scripting, or XSS. The everyday comparison: imagine a receptionist who reads out whatever address is written on a parcel. If someone writes "go and open the safe" instead of an address, and the receptionist follows it as an instruction, that is the problem. The web page here followed a value from an untrusted server as if it were a harmless web address.

Context

IRCCloud is a web-based IRC client. Its web client has a feature that automatically embeds social media links when a message containing one is posted. By default, the client embeds Mastodon toots when a link to one is sent.

An embed is a small preview shown inside the chat instead of a plain link. To build it, the client has to ask the server that hosts the linked post for details. That server is chosen by whoever wrote the link, so it may be malicious. The researcher's finding is that a malicious server can cause a web client user to execute arbitrary JavaScript in the context of the IRCCloud web client by tricking the client into embedding a javascript: URL.

A javascript: URL is a special kind of address. Instead of pointing at a page on the internet, it contains code that the browser runs when the address is used. It is the same idea as a phone number that, when dialled, plays a recorded instruction rather than connecting you to a person.

Setup

The only precondition is that the "Embed social media links" setting is enabled under "Chat & embeds". The researcher believes this is on by default. No accounts, tools or versions beyond that are described.

A setting is just a switch in the product's preferences. If the switch is on, the client will fetch and draw previews for links it recognises; if it is off, the feature does nothing and the attack has no path.

Finding it

A trust boundary is the line between data you can rely on and data you cannot. Data from your own program is trusted; data from a stranger's server is not, because the stranger can write anything in it.

An API is a way for one program to ask another for data in a structured format, like a waiter taking your order to the kitchen and bringing back a specific dish. Here, the IRCCloud web client asks the Mastodon server for details about a toot, and the server answers with a structured response. The answer was the toot's url, which the client uses as the src of an iframe.

An iframe is a frame inside a web page that loads another page, like a small window set into a wall. Its src attribute is the address of what to load in that frame. If that address is a javascript: URL, the browser runs the code in it instead of loading a page.

Exploitation

Step 1: Confirm the setting is on

Ensure "Embed social media links" is enabled in settings under "Chat & embeds". The researcher notes it is probably on by default.

This step matters because the whole attack depends on the client trying to build an embed. If the switch is off, the client never contacts the attacker's server and nothing happens.

Step 2: Send a message containing a toot link

Send a message with a link to:

Text
https://sm4.ca/@a/123456789012345678

This is the bait. It looks like an ordinary link to a Mastodon post on the domain sm4.ca, with a user handle @a and a long numeric post identifier. The link itself 404s, but that does not matter: IRCCloud only tries to use the Mastodon API, so the page behind the link is never needed. A 404 is the standard "page not found" answer from a web server. The point is that the client does not load the page; it asks the server's API for data about the post, and the attacker controls what that API answers.

Step 3: Wait for the embed

Wait a few seconds for the embed to load.

During those seconds the client makes its API request to the attacker's server, receives the crafted answer, and builds the embed from it. The delay is simply network and rendering time.

Step 4: Observe the result

Look at your session cookie. The script served by the malicious server has run in the context of the IRCCloud web client and read the cookie.

A cookie is a small piece of data a website stores in your browser so it can recognise you on later requests. A session cookie is the one that proves you are logged in; it works like a wristband at an event, which the staff check instead of asking for your name and password every time. If someone else gets your session cookie, they can present it to the site and be treated as you, without knowing your password.

What the client requests

When the web client sees what looks like a toot URL, it tries to get the canonical toot URL by making a query to [domain]/api/v1/statuses/[toot ID]. "Canonical" means the official, normalised address of the post, as opposed to whatever variant the sender typed. For the link above, the researcher served this response at https://sm4.ca/api/v1/statuses/123456789012345678:

JSON
{
  "account": {
    "url": "https://sm4.ca/@a"
  },
  "url": "javascript:top.document.body.innerHTML = \"hi your cookie is \" + document.cookie;//"
}

This is JSON, a text format for structured data built from names and values, like a labelled form. Line by line:

  • The outer braces { and } wrap one object, a collection of named fields.
  • "account" is a field whose value is itself an object, nested inside the outer one. It describes the account that posted the toot.
  • Inside it, "url": "https://sm4.ca/@a" gives the account's address. The .account.url field is only present because the web client ensures it matches the original link. In other words, the client does check this one field against the link the sender typed, so the attacker fills it in to pass that check.
  • "url" at the outer level is the toot's own address, and this is the payload. Its value starts with javascript:, so it is not a web address at all but a piece of code for the browser to run.
  • The code is top.document.body.innerHTML = "hi your cookie is " + document.cookie;. top means the outermost page in the browser window, which here is the IRCCloud client itself. document.body.innerHTML is the content of that page. document.cookie is the browser's stored cookies for that site. So the code replaces the page's content with the text "hi your cookie is " followed by the cookies, which demonstrates that the attacker's code can read them.
  • The trailing // starts a comment in JavaScript, meaning everything after it on that line is ignored. It is there for a reason explained below.

What the client does with it

The web client creates an iframe using .url as the src, which in this case is a javascript: URL. The specified script runs in a separate document that has access to its parent, and can access anything the parent can. The // at the end is needed because the web client appends /embed to the embed URL; without the comment marker, that suffix would break the script.

In plain words: the client takes the value of the url field, puts it into the address slot of a frame, and the browser runs it as code. The frame's document is treated as belonging to the same site as the IRCCloud page around it, so it is not walled off: it can reach into the parent page and read what the parent can read, including the session cookie. The client also sticks the text /embed onto the end of the address it builds. If the payload ended with ; and then /embed followed, that would be a syntax error and the code would not run. The // turns the appended /embed into a comment, so the code stays valid.

Root cause

The client creates an iframe using .url from the API response as the src, which in this case is a javascript: URL. A scheme is the first part of a web address before the colon, such as https or javascript; it tells the browser what kind of address this is and how to handle it. A javascript: URL in an iframe src executes script in a document that is same-origin with, and has access to, the parent page. Same-origin means the browser considers both to be the same website, so its usual walls between different sites do not apply.

Impact

An attacker who can send a message to a web-client-using IRCCloud user can obtain their session token and act as them. A session token here is the value in the session cookie that proves who you are. By sending a message with a malicious URL to a large channel, an attacker could compromise many users at once.

A channel is a group chat room. One message posted there is seen by everyone in it, so a single send can reach many people, each of whom may load the embed and run the attacker's code.

Separately, the researcher notes that Mastodon embeds should probably not be enabled unless "Embed 3rd party image and video links" is enabled, since even when the Mastodon server is not malicious, the user's IP address is still leaked to an arbitrary server. An IP address is the numeric address your connection comes from, which can reveal roughly where you are and which network you use. Because the client contacts whichever server the link names, the person who wrote the link learns that you loaded it.

Fix

The report does not describe a fix.

In everyday terms: the receptionist should only accept real street addresses, and refuse anything that reads like an instruction.

Variants to test

  1. Other embed providers. Any feature that fetches metadata from a user-chosen domain and renders a URL from the response is a candidate. A positive result is a javascript: or data: URL reaching an iframe src or similar sink. A sink is any place where data ends up being interpreted, such as a frame address or page content; a data: URL is another kind of address that carries its content inline rather than pointing at a server.
  2. Other fields in the same response. The report shows .url being used as a src; check whether other fields such as avatar or media URLs reach HTML or attribute sinks.
  3. Scheme handling in link rendering. Try links whose scheme is not http or https and see whether the client normalises or rejects them before embedding.

Hunting notes

This kind of bug hides in features that fetch data from third-party servers chosen by the sender: link previews, social embeds, oEmbed and Open Graph unfurlers. These are all variations on the same idea: the chat client contacts a stranger's server to build a preview, and trusts what comes back. During recon, look for settings toggles that enable automatic embedding, and for client-side code that builds iframes from fetched metadata. The signal is a response field used directly as a URL in a DOM sink. The DOM is the browser's in-memory model of the page, and a DOM sink is a spot in it where a value gets acted on rather than merely displayed.

To show impact, the researcher demonstrated reading document.cookie from the parent context, which is enough to show session theft, and pointed out that a message to a large channel reaches many users at once.

Glossary

  • API: a way for one program to ask another for data in a structured format, like a waiter carrying a specific order to the kitchen and back.
  • Attribute: a named setting on an HTML element, such as the address an iframe should load.
  • Canonical URL: the official, normalised address of a resource, as opposed to a variant someone typed.
  • Channel: a group chat room in IRC where one message is seen by everyone present.
  • Cookie: a small piece of data a website stores in your browser so it can recognise you later.
  • Cross-site scripting (XSS): a bug where an attacker gets their own code to run inside a site a victim is using, so the code acts with the victim's privileges.
  • data: URL: an address that carries its content inline instead of pointing at a server.
  • DOM: the browser's in-memory model of a page, which scripts can read and change.
  • DOM sink: a place in the page model where a value is acted on, such as a frame address, rather than just shown as text.
  • Embed: a preview of a linked post or media item drawn inside the chat instead of a bare link.
  • Field: a named value inside a structured response, such as url or account.
  • 404: the standard answer from a web server meaning the requested page was not found.
  • iframe: a frame inside a web page that loads another page or runs content in its own document.
  • IP address: the numeric address your connection comes from, which can reveal roughly where you are and which network you use.
  • IRC: an old, widely used text chat protocol; IRCCloud is a web client for it.
  • JavaScript: the programming language web pages run in your browser.
  • javascript: URL: an address whose content is code the browser runs when the address is used.
  • JSON: a text format for structured data made of named fields and values.
  • Mastodon: a social network where anyone can run their own server.
  • oEmbed / Open Graph unfurler: features that fetch metadata from a linked page to build a preview.
  • Payload: the part of an attack that carries the harmful content.
  • Same-origin: the browser treats two documents as the same website, so its usual walls between sites do not apply.
  • Scheme: the first part of an address before the colon, such as https or javascript, telling the browser how to handle it.
  • Session cookie / session token: the cookie value that proves you are logged in, like a wristband checked instead of a password.
  • Setting: a switch in a product's preferences that turns a feature on or off.
  • Sink: any place where data ends up being interpreted rather than merely displayed.
  • src: the attribute of an iframe that holds the address of what to load.
  • Toot: a post on Mastodon.
  • Trust boundary: the line between data you can rely on and data from someone else that you cannot.
  • // comment: in JavaScript, two slashes make the rest of the line ignored, which here neutralises text the client appends to the address.

More from IRCCloud

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.