Skip to content

Commit 738bcf0

Browse files
authored
Merge pull request #2008 from HackTricks-wiki/research_update_src_pentesting-web_xss-cross-site-scripting_iframes-in-xss-and-csp_20260315_130540
Research Update Enhanced src/pentesting-web/xss-cross-site-s...
2 parents e1f142a + 783a439 commit 738bcf0

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/pentesting-web/xss-cross-site-scripting/iframes-in-xss-and-csp.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ The research community continues to discover creative ways of abusing iframes to
126126
console.log(victim.name); // → leaked value
127127
```
128128

129-
* **Nonce theft via same-origin iframe (2024)** – CSP nonces are not removed from the DOM; they are merely hidden in DevTools. If an attacker can inject a *same-origin* iframe (for example by uploading HTML to the site) the child frame can simply query `document.querySelector('[nonce]').nonce` and create new `<script nonce>` nodes that satisfy the policy, giving full JavaScript execution despite `strict-dynamic`. The following gadget escalates a markup injection into XSS:
129+
* **Nonce reuse via same-origin iframe** – CSP nonces are readable from the DOM by same-origin documents. If an attacker can inject or upload a *same-origin* HTML page and load it in an iframe, the child frame can read `top.document.querySelector('[nonce]').nonce` and mint new `<script nonce>` elements. This turns a same-origin HTML injection into full script execution even under `strict-dynamic` (because the nonce is already trusted). The following gadget escalates a markup injection into XSS:
130130

131131
```javascript
132132
const n = top.document.querySelector('[nonce]').nonce;
@@ -191,7 +191,9 @@ Since **Chrome 110 (February 2023) the feature is enabled by default** and the s
191191

192192
* Scripts in different credentialless iframes **still share the same top-level origin** and can freely interact via the DOM, making multi-iframe self-XSS attacks feasible (see PoC below).
193193
* Because the network is **credential-stripped**, any request inside the iframe effectively behaves as an unauthenticated session – CSRF protected endpoints usually fail, but public pages leakable via DOM are still in scope.
194+
* Storage is **partitioned by a top-level document nonce**: credentialless frames on the same page can share storage with each other, but it is cleared when the top-level document is discarded.
194195
* Pop-ups spawned from a credentialless iframe get an implicit `rel="noopener"`, breaking some OAuth flows.
196+
* Browsers are expected to **disable autofill/password managers** inside credentialless iframes, limiting credential theft via autofill in these contexts.
195197

196198
```javascript
197199
// PoC: two same-origin credentialless iframes stealing cookies set by a third
@@ -231,6 +233,13 @@ alert(window.top[1].document.cookie);
231233

232234
As indicated in [this article](https://blog.slonser.info/posts/make-self-xss-great-again/) The API `fetchLater` allows to configure a request to be executed later (after a certain time). Therefore, this can be abused to for example, login a victim inside an attackers session (with Self-XSS), set a `fetchLater` request (to change the password of the current user for example) and logout from the attackers session. Then, the victim logs in in his own session and the `fetchLater` request will be executed, changing the password of the victim to the one set by the attacker.
233235

236+
Operational notes:
237+
238+
- `fetchLater` is still an emerging API with limited browser support; feature-detect before relying on it.
239+
- The response is **not** available to JavaScript; body/headers are ignored once the deferred request is sent.
240+
- CSP enforcement uses `connect-src` (not `script-src`) for deferred requests.
241+
- Requests fire on page unload or when `activateAfter` expires (whichever happens first).
242+
234243
This way even if the victim URL cannot be loaded in an iframe (due to CSP or other restrictions), the attacker can still execute a request in the victim's session.
235244

236245

@@ -272,5 +281,7 @@ Check the following pages:
272281
## References
273282

274283
* [PortSwigger Research – Using form hijacking to bypass CSP (March 2024)](https://portswigger.net/research/using-form-hijacking-to-bypass-csp)
284+
* [PortSwigger Research – Bypassing CSP with dangling iframes (Jun 2022)](https://portswigger.net/research/bypassing-csp-with-dangling-iframes)
275285
* [Chrome Developers – Iframe credentialless: Easily embed iframes in COEP environments (Feb 2023)](https://developer.chrome.com/blog/iframe-credentialless)
286+
* [MDN – Window.fetchLater()](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetchLater)
276287
{{#include ../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)