November 18, 2026
When Math.random() Guards the Door: A $66,000 Meta Bug Built on a Predictable Secret
How a non-cryptographic random number generator, a postMessage handler and a missing sanitiser chained into a Facebook account takeover…

By T4nv1
7 min read
How a non-cryptographic random number generator, a postMessage handler and a missing sanitiser chained into a Facebook account takeover, with a toy model you can run
Credit and scope:_ This finding belongs to Youssef Sammouda (sam0, @samm0uda), who published his own detailed write-up on his blog in January 2026. This post is my explanation of the ideas in it. I did not test Meta, and I'm deliberately leaving out payloads, exact endpoints and request details. The code below is an in-memory simulation I wrote; it contains no Facebook code and touches no network._
The Short Version
Researcher Youssef Sammouda Target Facebook mobile app (webview) and the Facebook JavaScript SDK Core flaws Predictable Math.random() used as an authentication secret, plus DOM XSS in an SDK message handler Impact Account takeover when a victim opens an attacker-controlled link in the Facebook mobile app Reported 22 June 2023 Acknowledged 23 June 2023 Bounty awarded 28 June 2023, $66,000 Fixed 15 December 2023 Write-up published 17 January 2026
On the amount and the sources: the $66,000 figure and the timeline come from the researcher's own blog post. I searched for independent coverage or a Meta statement confirming the amount and did not find any, so please treat it as the researcher's account of his own payout. I also read his post through a summarising fetch tool, not as raw text, so check specifics against the original before you quote anything precisely.
Part 1: The Setting, Plugins Talking Through Windows
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 iframe and the host page need to talk, and the browser mechanism for that is postMessage: one window sends a structured message, another listens for it.
Because any page can send a postMessage to any window, listeners have to decide who to trust. According to the researcher, the SDK accepted a message only when two conditions held:
- It came from
www.facebook.com(an origin check). - It carried the matching callback identifier (a secret that the SDK generated and expected back).
That is a perfectly reasonable design. The origin proves who; the callback id proves this is a reply to something we sent. Together they act as a two-lock door.
The bug is that each lock turned out to be pickable, and the handler behind the door trusted its content too much.
Part 2: Lock One, a Secret From the Wrong Kind of Randomness
The callback identifier was generated with Math.random(). That function is built for speed and statistical spread, not for secrecy. In V8, the JavaScript engine behind Chrome, it is based on an xorshift128+ style generator, which has the key weakness of all ordinary PRNGs: if you observe enough of its outputs, you can work out its internal state and predict everything it will produce next.
Two more details made this worse, per the write-up:
- The same generator also named the plugin iframes. Those names are visible to code running on the same origin. So every iframe the SDK created leaked one output of the very generator that produced the secret.
- The attacker could create as many leaks as they liked. The write-up describes an SDK event that re-parses the page and rebuilds the plugin iframes, each time producing a new name and advancing the generator. That hands the attacker a stream of outputs on demand.
With enough outputs, a seed-recovery solver (the researcher adapted one to cope with outputs that weren't consecutive) can reconstruct the generator's state and compute the next callback id before the SDK issues it.
The principle is the lesson, not the specific generator: a value that is derived from a stream you can observe is not a secret.
Part 3: See It Happen in a Toy
Real engines use larger generators, which is why the real attack needed a solver. To make the principle visible, I built a deliberately weak model: a 32-bit xorshift generator, where one leaked output reveals the whole state.
class XorShift32:
"""Toy non-cryptographic PRNG (stand-in for Math.random)."""
def __init__(self, seed):
self.state = seed & MASK
def next(self):
x = self.state
x ^= (x << 13) & MASK
x ^= x >> 17
x ^= (x << 5) & MASK
self.state = x
return xclass XorShift32:
"""Toy non-cryptographic PRNG (stand-in for Math.random)."""
def __init__(self, seed):
self.state = seed & MASK
def next(self):
x = self.state
x ^= (x << 13) & MASK
x ^= x >> 17
x ^= (x << 5) & MASK
self.state = x
return xA toy widget names its iframes and issues its callback id from the same source. The attacker reads the leaked name, steps its own copy of the generator, and predicts the callback before it exists:
widget.render_iframe()
leaked = int(widget.iframe_names[-1][1:], 16)
mimic = XorShift32(leaked)
predicted = "cb" + format(mimic.next(), "x")
actual = widget.issue_callback()widget.render_iframe()
leaked = int(widget.iframe_names[-1][1:], 16)
mimic = XorShift32(leaked)
predicted = "cb" + format(mimic.next(), "x")
actual = widget.issue_callback()The result when I ran it:
predictable generator (like a non-crypto PRNG)
leaked iframe name : ff89b3e70
predicted callback : cb75fb4a9a
actual callback : cb75fb4a9a
handler says : ACCEPTED -> would insert untrusted field into the page: 'MARKER'
cryptographically secure generator
leaked iframe name : f51bb0aa3
predicted callback : cb2d012854
actual callback : cb8a987bde
handler says : dropped (bad callback id)predictable generator (like a non-crypto PRNG)
leaked iframe name : ff89b3e70
predicted callback : cb75fb4a9a
actual callback : cb75fb4a9a
handler says : ACCEPTED -> would insert untrusted field into the page: 'MARKER'
cryptographically secure generator
leaked iframe name : f51bb0aa3
predicted callback : cb2d012854
actual callback : cb8a987bde
handler says : dropped (bad callback id)The predicted and actual callbacks match exactly in the first case, and the handler accepts the message. With a cryptographically secure source, the prediction is wrong and the handler rejects it. (The secure values change on every run, as they should.)
In the toy I assume the origin check has already been satisfied, because that is a separate barrier, covered next.
Part 4: Lock Two, Looking Like Facebook
The origin check is the other half of the door. The researcher describes finding a Facebook plugin endpoint that would relay attacker-influenced text into a message, so that the message genuinely originated from www.facebook.com. That gets the attacker past the origin check without breaking it.
This is a pattern worth remembering: origin checks are only as strong as the least careful page on that origin. If any page on the trusted origin can be coaxed into reflecting your content in a postMessage, "it came from the trusted origin" stops meaning "the content is trustworthy."
Part 5: The Prize Behind the Door, DOM XSS
Once a message passes both checks, what does the handler do with it? According to the write-up, the Customer Chat message handler inserted a field called iconSVG into the DOM without sanitising it. A message that got through the two locks could therefore inject script into a page on [www.facebook.com](http://www.facebook.com.).
Why does that matter so much? Script running on the main Facebook origin can read other same-origin content. In the researcher's chain, that included a frame holding the victim's OAuth token, which is what converts "XSS" into "take over the account."
I won't reproduce the payload or exact field handling. What matters for learning is the shape: a trusted channel carrying an untrusted field into an HTML sink.
Part 6: Getting the Victim Into Position
A complete chain needs the victim's browser in the right state. The write-up describes several supporting pieces, which I'll summarise only at a high level:
- Framing. Reading the leaked iframe names required the attacker's page to frame the relevant Facebook page. Some Facebook mobile-app responses carried a legacy framing header,
X-Frame-Options: ALLOW-FROM, which is obsolete and not honoured by many modern browsers and webviews, effectively leaving those responses frameable. - Session state. The chain used logout and login CSRF to control which session the victim's browser was in, so that the right page with the right token sat in a frame the attacker could reach.
- Trigger. The victim only needs to open an attacker-controlled link inside the Facebook mobile app's webview.
Put together, the researcher's high-level chain is:
- 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.comreads the same-origin frame containing the OAuth token, enabling account takeover.
Five moving parts, each of which looks minor alone. That is exactly why chains pay so well.
Part 7: Why the Payout Was Large
Bounty size follows impact times plausibility. Here:
- Impact: full account takeover of a platform with billions of users.
- Plausibility: a single link opened in the mobile app is a realistic trigger.
- Difficulty and novelty: the chain required cryptanalysis of a PRNG, a clever origin-relay trick and several session-state tricks. Programs reward work that is hard to find and hard to defend against.
The timeline is also instructive. Meta acknowledged the report the next day and awarded the bounty within a week, but the fix shipped about six months after the report. Real fixes for chained logic bugs, especially ones that touch SDKs embedded across the web, are slow and careful. Patience is part of the job.
Part 8: What Hunters Can Take From This
(My own takeaways, not part of the original write-up.)
1. Grep for weak randomness near trust decisions. Anywhere a token, nonce, callback id, CSRF value or message identifier comes from Math.random, Date.now, a counter, or a timestamp, ask whether an attacker can observe related values. The value of the bug is not the randomness itself but what it protects.
2. Hunt for leaks of generator output. Predictability only matters if you can see outputs. Iframe names, element IDs, filenames, request IDs, error messages and DOM attributes can all quietly expose them.
- Review
postMessagehandlers as a unit. For each listener, write down: what origin does it accept, what secret does it require, what does it do with the content. Three questions, three potential bugs.
4. Treat each barrier as its own puzzle. The chain succeeded because the researcher separated "pass the origin check" from "know the secret" from "reach the sink" and solved them one at a time. Big chains are lists of small problems.
5. Don't stop at XSS. The impact came from asking what a script on that origin could read. Always connect your primitive to a concrete asset.
6. Keep your write-ups safe. The researcher published long after the fix and kept the story focused on the mechanics. That's a good model for community posts.
Part 9: What Defenders Should Do
- Use a cryptographically secure source for anything secret. In browsers, that's
crypto.getRandomValues()orcrypto.randomUUID(). On servers, use the platform's CSPRNG. Never useMath.random()for tokens, callbacks or identifiers that protect anything. - Don't expose generator output next to a secret. If you must use a fast PRNG for names or IDs, use a separate instance from your secrets, so leaks can't reveal secret values.
- Sanitise every field, even from trusted origins. A trusted origin means "the sender's page is trusted," not "every string it relays is safe." Insert data as text, not HTML, or run it through a strict sanitiser.
- Audit your relay endpoints. Anything on your trusted origin that reflects user input into a postMessage should be treated as a potential bridge across your origin check.
- Use modern framing controls. Prefer
Content-Security-Policy: frame-ancestorsover the obsoleteALLOW-FROM, and test the behaviour in the webviews your mobile apps actually use. - Defend against login and logout CSRF. State changes that look harmless can be the setup step for a longer chain.
- Keep tokens out of reach of embedded content. Limit what sensitive values live in same-origin frames that other scripts could read.
I like this chain because every individual link is "known." Weak PRNGs, unsafe innerHTML, frameable pages and CSRF are all textbook. What's rare is the person who stitches them together patiently, and who notices that the safest-looking part of the design (a secret callback id) was built on a function that was never meant to keep secrets.
The next time you see a "random" value protecting something, ask two questions: who generated it, and what else did they generate with the same machine?