When Math.random() Guards the Door: A $66,000 Meta Bug Built on a Predictable Secret
The Facebook JavaScript SDK generated a callback identifier used to authenticate postMessage replies with Math.random(), a predictable PRNG whose outputs leaked through iframe names. Combined with an origin-relay endpoint and an unsanitised iconSVG field in the Customer Chat handler, an attacker could achieve DOM XSS on www.facebook.com and read a same-origin OAuth token, leading to account takeover.
The Facebook JavaScript SDK lets third-party sites embed Facebook features such as a Customer Chat widget or a Feedback plugin. Those plugins appear as iframes.
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 SDK used a non-cryptographic PRNG (Math.random) to generate a security-sensitive callback identifier, and the same generator's outputs were exposed via iframe names, allowing prediction; additionally, a message handler inserted an untrusted field into the DOM without sanitisation.
Impact
An attacker could take over a victim's Facebook account by opening a link in the mobile app, though the exploit required several chained steps and specific conditions.
What the attacker needed
Victim opens a link in Facebook mobile app; attacker can frame Facebook pages; attacker can control session state
The fix
The issue was fixed by using a cryptographically secure random number generator for secrets and sanitising all fields, even from trusted origins.
How it was found
- The victim opens the attacker's page in the Facebook app webview.
- The attacker frames a Facebook page holding a sensitive value (an OAuth token) and controls session state with logout/login CSRF.
- The attacker loads a page with the Customer Chat plugin and harvests PRNG outputs from iframe names, forcing repeated re-initialisation to collect more.
- The attacker predicts the next callback id and sends a crafted message that appears to come from Facebook.
- DOM XSS on www.facebook.com reads the same-origin frame containing the OAuth token, enabling account takeover.
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.
A website can embed parts of Facebook, like a chat widget, inside a small frame. The page and the frame talk to each other using messages, and the SDK tried to keep these messages safe with a secret code. The problem was that the code was made with a random number generator that is not truly random, so an attacker could work out the next code and send fake messages that the page trusted, eventually taking over an account.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.