Skip to content
XSS Write-up Advanced

Bypassing CSP with dangling iframes

A cross-domain iframe could be navigated to about:blank, after which its window.name became readable and writable, allowing an attacker to bypass CSP and exfiltrate data via dangling markup. The technique was demonstrated in a lab where an injected iframe captured a victim's email address.

Gareth Heyes Follow

Published on portswigger.net

Our Web Security Academy has a topic on dangling markup injection - a technique for exploiting sites protected by CSP. But something interesting happened when we came to update to Chrome 97 - because one of our interactive labs mysteriously stopped working.

Gareth Heyes (@garethheyes), on portswigger.net

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the browser's handling of about:blank iframes, which inherit the origin of the parent but become readable by the attacker after navigation, combined with incomplete mitigation of dangling markup attacks.

Impact

An attacker could bypass CSP to read cross-domain information via dangling markup, potentially exfiltrating sensitive data such as email addresses, even with JavaScript disabled in the CSP.

What the attacker needed

Victim visits a malicious page; attacker can inject HTML into the target page; browser allows cross-domain iframe navigation to about:blank

The fix

The browser should be fixed to prevent cross-domain iframes from becoming readable after navigation to about:blank, and to properly mitigate dangling markup attacks.

How it was found

  1. Inject an iframe with a name attribute and an onload handler that calls a function with the iframe's contentWindow.
  2. In the function, set the iframe's location to about:blank.
  3. After a short delay, read the iframe's name property and alert it.

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 write-up has not been written yet. The Original tab links to the source.

Content Security Policy (CSP) is a browser feature that restricts what scripts and resources a page can load, to reduce the impact of injection attacks. Dangling markup is a trick where an attacker injects an unclosed HTML tag so that the browser treats following page content as part of that tag, potentially sending it to an attacker-controlled server. This article shows a way to bypass CSP by abusing how browsers handle iframes that are navigated to about:blank.

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 Gareth Heyes

View all

15 more disclosed reports, best first.

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.