Skip to content

Commit 547d033

Browse files
authored
Merge pull request #1697 from HackTricks-wiki/research_update_src_pentesting-web_xs-search_cookie-bomb-+-onerror-xs-leak_20251219_083005
Research Update Enhanced src/pentesting-web/xs-search/cookie...
2 parents a2b1c87 + eb1b3dc commit 547d033

File tree

1 file changed

+46
-21
lines changed

1 file changed

+46
-21
lines changed

src/pentesting-web/xs-search/cookie-bomb-+-onerror-xs-leak.md

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@
44

55
This technique combines:
66
- Cookie bombing: stuffing the victim’s browser with many/large cookies for the target origin so that subsequent requests hit server/request limits (request header size, URL size in redirects, etc.).
7-
- Error-event oracle: probing a cross-origin endpoint with a <script> (or other subresource) and distinguishing states with onload vs onerror.
7+
- Error-event oracle: probing a cross-origin endpoint with a `<script>` (or other subresource) and distinguishing states with `onload` vs `onerror`.
88

99
High level idea
1010
- Find a target endpoint whose behavior differs for two states you want to test (e.g., search “hit” vs “miss”).
1111
- Ensure the “hit” path will trigger a heavy redirect chain or long URL while the “miss” path stays short. Inflate request headers using many cookies so that only the “hit” path causes the server to fail with an HTTP error (e.g., 431/414/400). The error flips the onerror event and becomes an oracle for XS-Search.
1212

1313
When does this work
14-
- You can cause the victim browser to send cookies to the target (e.g., cookies are SameSite=None or you can set them in a first-party context via a popup window.open).
14+
- You can cause the victim browser to send cookies to the target (e.g., cookies are SameSite=None or you can set them in a first-party context via a popup `window.open`).
1515
- There is an app feature you can abuse to set arbitrary cookies (e.g., “save preference” endpoints that turn controlled input names/values into Set-Cookie) or to make post-auth redirects that incorporate attacker-controlled data into the URL.
1616
- The server reacts differently on the two states and, with inflated headers/URL, one state crosses a limit and returns an error response that triggers onerror.
1717

1818
Note on server errors used as the oracle
19-
- 431 Request Header Fields Too Large is commonly returned when cookies inflate request headers; 414 URI Too Long or a server-specific 400 may be returned for long request targets. Any of these result in a failed subresource load and fire onerror. [MDN documents 431 and typical causes like excessive cookies.]()
19+
- 431 Request Header Fields Too Large is commonly returned when cookies inflate request headers; 414 URI Too Long or a server-specific 400 may be returned for long request targets. Any of these result in a failed subresource load and fire onerror. See [MDN’s 431 entry](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/431) for typical causes like excessive cookies.
20+
21+
<details>
22+
<summary>Practical example (angstromCTF 2022)</summary>
2023

21-
Practical example (angstromCTF 2022)
2224
The following script (from a public writeup) abuses a feature that lets the attacker insert arbitrary cookies, then loads a cross-origin search endpoint as a script. When the query is correct, the server performs a redirect that, together with the cookie bloat, exceeds server limits and returns an error status, so script.onerror fires; otherwise nothing happens.
2325

2426
```html
@@ -76,11 +78,41 @@ The following script (from a public writeup) abuses a feature that lets the atta
7678
</script>
7779
```
7880

79-
Why the popup (window.open)?
81+
</details>
82+
83+
Why the popup (`window.open`)?
8084
- Modern browsers increasingly block third-party cookies. Opening a top-level window to the target makes cookies first‑party so Set-Cookie responses from the target will stick, enabling the cookie-bomb step even with third‑party cookie restrictions.
8185

8286
2024–2025 notes on cookie availability
83-
- Chromium-based browsers still commonly send third‑party cookies unless the user or site opts out, but Safari and Firefox block most third‑party cookies by default. Plan for both: (1) use a first‑party cookie planting flow (window.open + auto-submit to a cookie-setting endpoint) and then (2) probe with a subresource that only succeeds when those cookies are sent. If third‑party cookies are blocked, move the probe into a same-site context (e.g., run the oracle in the popup via a same-site gadget and exfiltrate the boolean with postMessage or a beacon to your server).
87+
- Chrome’s Tracking Protection rollout (January 2024) is already blocking third-party cookies for a random cohort and is slated to expand to the entire user base once the UK CMA signs off, so assume any victim can abruptly lose 3P cookies. Automate the fallback: detect when your script probe fails without ever hitting the target and transparently pivot to the popup/first-party flow. Safari and Firefox already block most third-party cookies by default and CHIPS/partitioned cookies mean each top-level site now has its own jar.
88+
- Use a first‑party cookie planting flow (`window.open` + auto-submit to a cookie-setting endpoint) and then probe with a subresource that only succeeds when those cookies are sent. If third‑party cookies are blocked, move the probe into a same-site context (e.g., run the oracle in the popup via a same-site gadget and exfiltrate the boolean with `postMessage` or a beacon to your server), or enroll the victim origin in Chrome’s deprecation trial if you legitimately control it.
89+
90+
<details>
91+
<summary>Tracking-Protection-safe first-party planting helper</summary>
92+
93+
When you need to stuff dozens of cookies from a cross-site context, stage a temporary top-level window and fire a series of oversized form submissions into the vulnerable Set-Cookie endpoint:
94+
```js
95+
async function plantFirstPartyCookies(endpoint, fields) {
96+
for (let i = 0; i < 5; i++) {
97+
const name = crypto.randomUUID();
98+
const form = Object.assign(document.createElement('form'), {action:endpoint, method:'POST', target:name});
99+
Object.entries(fields).forEach(([k, v]) => {
100+
const input = document.createElement('input');
101+
input.name = k;
102+
input.value = v + '_'.repeat(400 + 120 * i);
103+
form.appendChild(input);
104+
});
105+
document.body.appendChild(form);
106+
window.open('about:blank', name, 'noopener');
107+
form.submit();
108+
await new Promise(r => setTimeout(r, 120));
109+
form.remove();
110+
}
111+
}
112+
```
113+
Call it right before you begin probing so every oracle run starts with a freshly inflated cookie jar.
114+
115+
</details>
84116

85117
Generic probing helper
86118
If you already have a way to set many cookies on the target origin (first-party), you can reuse this minimal oracle against any endpoint whose success/failure leads to different network outcomes (status/MIME/redirect):
@@ -130,11 +162,15 @@ Tips to build the oracle
130162
- Force the “positive” state to be heavier: chain an extra redirect only when the predicate is true, or make the redirect URL reflect unbounded user input so it grows with the guessed prefix.
131163
- Inflate headers: repeat cookie bombing until a consistent error is observed on the “heavy” path. Servers commonly cap header size and will fail sooner when many cookies are present.
132164
- Stabilize: fire multiple parallel cookie set operations and probe repeatedly to average out timing and caching noise.
133-
- Bust caches and avoid pooling artifacts: add a random `#fragment` or `?r=` to probe URLs, and prefer distinct window names when using window.open loops.
165+
- Bust caches and avoid pooling artifacts: add a random `#fragment` or `?r=` to probe URLs, and prefer distinct window names when using `window.open` loops.
134166
- Alternate subresources: if `<script>` is filtered, try `<link rel=stylesheet>` or `<img>`. The onload/onerror boolean is the oracle; content never needs to be parsed.
135167

136168
Common header/URL limits (useful thresholds)
137-
- Reverse proxies/CDNs and servers enforce different caps. As of October 2025, Cloudflare documents 128 KB total for request headers (and 16 KB URL) on the edge, so you may need more/larger cookies when targets sit behind it. Other stacks (e.g., Apache via LimitRequestFieldSize) are often closer to ~8 KB per header line and will hit errors earlier. Adjust bomb size accordingly. [Cloudflare docs show the 128 KB header limit.]
169+
- Reverse proxies/CDNs and servers enforce different caps. As of October 2025, Cloudflare documents 128 KB total for request headers (and 16 KB URL) on the edge, so you may need more/larger cookies when targets sit behind it. Other stacks (e.g., Apache via LimitRequestFieldSize) are often closer to ~8 KB per header line and will hit errors earlier. Adjust bomb size accordingly (see [Cloudflare’s documented limit](https://developers.cloudflare.com/fundamentals/reference/connection-limits/)).
170+
171+
Browser hardening watchlist (2025+)
172+
- Firefox 139/ESR 128.11 (May 2025) tightened script tag load/error accounting for cross-origin resources (CVE-2025-5266). On patched clients the `onerror` signal for certain redirected responses is suppressed, so diversify the oracle (parallel `<link rel=stylesheet>`, `<img>`, or `fetch` with mismatched MIME) and fingerprint the victim UA before assuming the boolean still fires.
173+
- Expect enterprise Chromium builds with Tracking Protection or Fetch Metadata policies to intermittently strip cookies or rewrite redirects. Detect these cases by probing a short endpoint first; when it fails, automatically pivot to running the entire attack inside the popup and relaying bits through `postMessage`/`BroadcastChannel`.
138174

139175
Related XS-Search tricks
140176
- URL length based oracles (no cookies needed) can be combined or used instead when you can force a very long request target:
@@ -143,19 +179,6 @@ Related XS-Search tricks
143179
url-max-length-client-side.md
144180
{{#endref}}
145181

146-
Defenses and hardening
147-
- Make success/failure responses indistinguishable:
148-
- Avoid conditional redirects or large differences in response size between states. Return the same status, same content type, and similar body length regardless of state.
149-
- Block cross-site subresource probes:
150-
- SameSite cookies: set sensitive cookies to SameSite=Lax or Strict so subresource requests like <script src> don’t carry them; prefer Strict for auth tokens when possible.
151-
- Fetch Metadata: enforce a Resource Isolation Policy to reject cross-site subresource loads (e.g., if Sec-Fetch-Site != same-origin/same-site).
152-
- Cross-Origin-Resource-Policy (CORP): set CORP: same-origin (or at least same-site) for endpoints not meant to be embedded as cross-origin subresources.
153-
- X-Content-Type-Options: nosniff and correct Content-Type on JSON/HTML endpoints to avoid load-as-script quirks.
154-
- Reduce header/URL amplification:
155-
- Cap the number/size of cookies set; sanitize features that turn arbitrary form fields into Set-Cookie.
156-
- Normalize or truncate reflected data in redirects; avoid embedding attacker-controlled long strings in Location URLs.
157-
- Keep server limits consistent and fail uniformly (avoid special error pages only for one branch).
158-
159182
Notes
160183
- This class of attacks is discussed broadly as “Error Events” XS-Leaks. The cookie-bomb step is just a convenient way to push only one branch over server limits, producing a reliable boolean oracle.
161184

@@ -166,4 +189,6 @@ Notes
166189
- MDN: 431 Request Header Fields Too Large (common with many cookies): https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/431
167190
- LA CTF 2024 writeup note showing a de Bruijn cookie-bomb oracle: https://gist.github.com/arkark/5787676037003362131f30ca7c753627
168191
- Cloudflare edge limits (URLs 16 KB, request headers 128 KB): https://developers.cloudflare.com/fundamentals/reference/connection-limits/
192+
- Chrome Tracking Protection rollout details: https://blog.google/products/chrome/privacy-sandbox-tracking-protection/
193+
- Mozilla MFSA 2025-44 (CVE-2025-5266) tightening script tag onerror behavior: https://www.mozilla.org/en-US/security/advisories/mfsa2025-44/
169194
{{#include ../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)