Skip to main content
MediumClient-sideOWASP A05:2021CWE-346

How to fix: postMessage Sent to Another Window With Wildcard Target Origin

A .postMessage() call targeting another window (contentWindow, opener, parent, top, or a captured event.source) passes the literal string "*" as the targetOrigin argument, so the message is delivered to whatever origin that window currently holds rather than a specific expected origin.

Why it matters

If the target window has since navigated, or was navigated by an attacker (a compromised ad iframe, a clickjacked redirect, a popup the page still holds a reference to), any sensitive data in the message payload is delivered straight to whatever page now occupies that window.

postMessage's second argument restricts delivery to a specific origin. Passing "*" disables that restriction entirely for messages sent to another window: the browser delivers the message regardless of what page currently lives there. This only matters for cross-window sends; a page posting a message to itself (bare window.postMessage or self.postMessage, used by several polyfills to schedule a same-page callback) never leaves the page and carries none of this risk, which is why this check only fires on contentWindow/opener/parent/top/source targets.

How to fix it

  1. 1Replace "*" with the specific expected origin string (e.g. https://app.example.com).
  2. 2If the target's origin can vary legitimately, validate it against an allowlist before calling postMessage.
  3. 3Avoid putting sensitive data (tokens, PII) in postMessage payloads even when targeting a fixed origin.

Code examples

Target a specific origin

JavaScript
// Bad
iframeRef.contentWindow.postMessage(payload, '*');

// Good
const TARGET_ORIGIN = 'https://app.example.com';
iframeRef.contentWindow.postMessage(payload, TARGET_ORIGIN);

References

Detected automatically by VulnRadar. The check id is cs-postmessage-wildcard-origin, stable across every scan so you can filter or diff on it.

See every client-side check

Questions

How severe is postMessage Sent to Another Window With Wildcard Target Origin?
VulnRadar rates this medium severity in the client-side category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id cs-postmessage-wildcard-origin, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does postMessage Sent to Another Window With Wildcard Target Origin map to?
It maps to CWE-346. In the OWASP Top 10 it falls under A05:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for postmessage sent to another window with wildcard target origin

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

postMessage Sent to Another Window With Wildcard Target Origin | VulnRadar