Skip to content
XSS Disclosed report Intermediate CVE-2022-22759

Appending elements to sandboxed iframe can trigger javascript execution even if allow-scripts is not set

A sandboxed iframe with allow-same-origin but without allow-scripts allowed JavaScript execution when a new element with an event handler was appended to its body in Firefox. An attacker could use this to run script in the context of the iframe's origin, leading to cross-site scripting.

johanaxelcarlsson Follow

Originally disclosed on Mozilla

  • Fixed in 2 months
  • Paid in 2 months
  • Disclosed after 2 months
Text
Created attachment 9249715
index.html

This issue was discovered while testing the security of a web application that uses sandboxed iframes to render user supplied HTML as part of a templeting tool. The application assumes (rightfully?) that adding elements to a sandboxed iframe will not trigger any supplied JavaScript. This is the case when using the webapp in Chromium based browsers, but when testing the application in Firefox appending a "broken image XSS payload" to the body of the iframe did trigger JavaScript execution.

If the page contains an iframe such as:

<iframe title="test" id="frame01" sandbox="allow-same-origin" src="temp.html"></iframe>

and a new element is added to the body like this:

let newDiv = document.createElement("div");
newDiv.innerHTML = "<img src='x' onerror='parent.window.alert(document.domain)'>";
frame.contentWindow.document.body.appendChild(newDiv);

The alert box will trigger in Firefox. Important to note is the sandbox attribute allow-same-origin which is needed to be able to write to the iframe at all. Otherwise, writing will be blocked by cross-origin policies. But this attribute should not allow JavaScript execution. The src="temp.html" part is only needed when testing on Chromium as the image will not be added if the body is empty. In Firefox one can omit the src="temp.html" part and still have the JavaScript trigger.

I have tested this on Firefox 94.0.1 (64-bit) on Windows 10 (OS build 19042.1288) and Firefox 94.0.1 on MacOS

I have attached a HTML file to use as a POC. (Or just visit the linked CodePen snippet from the URL section)

POC:
1. Download the file and put it in a new directory on disk
2. Start a HTTP server from the directory (for example with the command:  python3 -m http.server )
3. Go to the webpage with Firefox. If started with python http.server the default is http://localhost
4. The alert box will pop
5. Go to the same site in Chrome
6. No alert box will pop

This behavior did, in the case of the mentioned web app, lead to an XSS issue that only appeared in Firefox and led to a compromise of the user account.

I have not digged any deeper into why Firefox does this, but as I read in your guidelines, you wanted researchers to send in bugs as soon as discovered and add context later. I hope that this information is sufficient for now, and please ask me for more information if needed!

Best regards
Johan Carlsson

The original report as published on Mozilla's Bugzilla, by johanaxelcarlsson. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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 a Firefox bug where appending elements with event handlers to a sandboxed iframe's document does not properly enforce the missing allow-scripts flag.

Impact

This could lead to an XSS issue that only appeared in Firefox and led to a compromise of the user account.

What the attacker needed

Firefox browser; sandboxed iframe with allow-same-origin; ability to append elements to iframe body

How it was found

  1. Create an HTML file with a sandboxed iframe that has allow-same-origin and a src.
  2. Serve the file from a local HTTP server.
  3. Open the page in Firefox.
  4. Observe the alert box triggered by the appended image's onerror handler.
  5. Open the same page in Chrome and observe no alert.

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 sandboxed iframe is a web page embedded in another page with restrictions, like a locked room. The allow-same-origin setting lets the parent page access the iframe's content, but it should not let scripts run. In Firefox, adding an image with an error handler to the iframe's body caused the handler to run, which is a security bug because it bypasses the sandbox.

What is XSS?

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

More by johanaxelcarlsson

View all

2 more disclosed reports, best first.

More from Mozilla

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.