Skip to content

Commit 5ecd18d

Browse files
authored
Merge pull request #1762 from HackTricks-wiki/update_CAPIG_XSS__Meta_Conversions_API_Gateway___postMess_20260115_012759
CAPIG XSS (Meta Conversions API Gateway) postMessage origin ...
2 parents f9fa192 + 9fa377d commit 5ecd18d

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

  • src/pentesting-web/postmessage-vulnerabilities

src/pentesting-web/postmessage-vulnerabilities/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,44 @@ For **more information**:
247247
- Link to page about [**XSS**](../xss-cross-site-scripting/index.html)
248248
- Link to page about [**client side prototype pollution to XSS**](../deserialization/nodejs-proto-prototype-pollution/index.html#client-side-prototype-pollution-to-xss)
249249

250+
### Origin-derived script loading & supply-chain pivot (CAPIG case study)
251+
252+
`capig-events.js` only registered a `message` handler when `window.opener` existed. On `IWL_BOOTSTRAP` it checked `pixel_id` but stored `event.origin` and later used it to build `${host}/sdk/${pixel_id}/iwl.js`.
253+
254+
<details>
255+
<summary>Handler writing attacker-controlled origin</summary>
256+
257+
```javascript
258+
if (window.opener) {
259+
window.addEventListener("message", (event) => {
260+
if (
261+
!localStorage.getItem("AHP_IWL_CONFIG_STORAGE_KEY") &&
262+
!localStorage.getItem("FACEBOOK_IWL_CONFIG_STORAGE_KEY") &&
263+
event.data.msg_type === "IWL_BOOTSTRAP" &&
264+
checkInList(g.pixels, event.data.pixel_id) !== -1
265+
) {
266+
localStorage.setItem("AHP_IWL_CONFIG_STORAGE_KEY", {
267+
pixelID: event.data.pixel_id,
268+
host: event.origin,
269+
sessionStartTime: event.data.session_start_time,
270+
})
271+
startIWL() // loads `${host}/sdk/${pixel_id}/iwl.js`
272+
}
273+
})
274+
}
275+
```
276+
277+
</details>
278+
279+
**Exploit (origin → script-src pivot):**
280+
1. Get an opener: e.g., in Facebook Android WebView reuse `window.name` with `window.open(target, name)` so the window becomes its own opener, then post a message from a malicious iframe.
281+
2. Send `IWL_BOOTSTRAP` from any origin to persist `host = event.origin` in `localStorage`.
282+
3. Host `/sdk/<pixel_id>/iwl.js` on any CSP-allowed origin (takeover/XSS/upload on a whitelisted analytics domain). `startIWL()` then loads attacker JS in the embedding site (e.g., `www.meta.com`), enabling credentialed cross-origin calls and account takeover.
283+
284+
If direct opener control was impossible, compromising a third-party iframe on the page still allowed sending the crafted `postMessage` to the parent to poison the stored host and force the script load.
285+
286+
**Backend-generated shared script → stored XSS:** the plugin `AHPixelIWLParametersPlugin` concatenated user rule parameters into JS appended to `capig-events.js` (e.g., `cbq.config.set(...)`). Injecting breakouts like `"]}` injected arbitrary JS, creating stored XSS in the shared script served to all sites loading it.
287+
250288
### Trusted-origin allowlist isn't a boundary
251289

252290
A strict `event.origin` check only works if the **trusted origin cannot run attacker JS**. When privileged pages embed third-party iframes and assume `event.origin === "https://partner.com"` is safe, any XSS in `partner.com` becomes a bridge into the parent:
@@ -314,6 +352,7 @@ iframe.location = fbMsg // sends postMessage from facebook.com with forged callb
314352
- [https://dev.to/karanbamal/how-to-spot-and-exploit-postmessage-vulnerablities-36cd](https://dev.to/karanbamal/how-to-spot-and-exploit-postmessage-vulnerablities-36cd)
315353
- [Leaking fbevents: OAuth code exfiltration via postMessage trust leading to Instagram ATO](https://ysamm.com/uncategorized/2026/01/16/leaking-fbevents-ato.html)
316354
- To practice: [https://github.com/yavolo/eventlistener-xss-recon](https://github.com/yavolo/eventlistener-xss-recon)
355+
- [CAPIG postMessage origin trust → script loading + stored JS injection](https://ysamm.com/uncategorized/2025/01/13/capig-xss.html)
317356
- [Self XSS Facebook Payments](https://ysamm.com/uncategorized/2026/01/15/self-xss-facebook-payments.html)
318357
- [Facebook JavaScript SDK Math.random callback prediction → DOM XSS writeup](https://ysamm.com/uncategorized/2026/01/17/math-random-facebook-sdk.html)
319358
- [V8 Math.random() state recovery (Z3 predictor)](https://github.com/PwnFunction/v8-randomness-predictor)

0 commit comments

Comments
 (0)