Script via XSLT stylesheet bypasses <iframe sandbox> attribute restrictions
Scripts injected through an XSLT stylesheet transformation of an XML document inside a sandboxed iframe were not subject to the sandbox restrictions. An attacker could therefore run script in that frame, open pop-ups and redirect the top-level page.
Originally disclosed on Mozilla
- Fixed in 38 days
- Paid in 49 days
- Disclosed after 38 days
Created attachment 9239890 iframe-sandbox-xsl-demo-selfcontained.html
The security restrictions applied via an <iframe>'s sandbox attribute can be bypassed by injecting scripts through XSLT stylesheets.
Description
A blank sandbox attribute adds several restrictions to the content of an <iframe>, such as blocking script execution and top-level navigation. However, those restrictions are not applied correctly to an XML content document which is transformed by an XSLT stylesheet. If a sheet's transformation directives create a new XHTML <script> tag, the sandbox rules don't take effect. That is, the script code executes normally and it may create pop-ups or issue top-level redirects (top.location = ...).
Proof of concept
The proof-of-concept embeds an XML document via <iframe sandbox src="...">. The XML doc then references an XSLT stylesheet via <?xml-stylesheet type="text/xsl" href="..."> which applies an <xsl:template> containing a <script> with the payload to execute.
Attached is a self-contained PoC. It uses data:-URIs for convenience, but the resources may as well be in different files (and on different hosts), e.g.:
parent.html:
<iframe sandbox src='child.xml'></iframe>
child.xml:
<?xml-stylesheet type="text/xsl" href="sheet.xsl"?>
<root/>
sheet.xsl: (must send permissive Access-Control-Allow-Origin to load!)
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
<template match="/">
<script xmlns="http://www.w3.org/1999/xhtml">
prompt(location.href);
top.location = `http://example.com/`;
</script>
</template>
</stylesheet>
NB: To be clear, the bug only defeats the sandbox attribute, but not the default SOP boundary between cross-origin frames.
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 browser applied sandbox checks to the original XML document but not to the XHTML document produced by the XSLT transformation, so the generated script element escaped the sandbox rules.
Impact
Script inside the sandboxed frame could run, allowing pop-ups and top-level redirects, though the cross-origin same-origin policy boundary still held.
What the attacker needed
Victim loads a page with a sandboxed iframe; attacker controls the XML and XSLT content
How it was found
- Embed an XML document in an iframe that has a blank sandbox attribute.
- Have the XML document reference an XSLT stylesheet that builds a script element in the output.
- Load the parent page and observe that the script runs despite the sandbox.
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 sandbox attribute on an iframe is meant to stop the embedded page from running scripts or navigating the whole page. Here the embedded page was XML that got transformed by an XSLT stylesheet, and the browser failed to apply those restrictions to the result. So the script still ran, which should not have been possible.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.