Security rules

NGB006: Wildcard postMessage origin

Reports targetWindow.postMessage(message, '*') (or { targetOrigin: '*' }) to another window.

Property Value
Rule ID NGB006
Category iframe & cross-window communication
Default severity high
CWE CWE-201, CWE-345
Built-in presets recommended: error, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Reports targetWindow.postMessage(message, '*') (or { targetOrigin: '*' }) to another window. When the payload is identified as a credential or payment value (by name, by its type's properties or along its data flow), the finding is high severity with high/medium confidence; a wildcard with a payload not identified as sensitive is reported as low severity and low confidence.

Why it matters

'*' delivers the message to whatever document is currently loaded in the target window. If an attacker can navigate that frame or popup (very common for popups and embeddable frames), they receive the data — tokens, session identifiers or card data leak cross-origin.

Detection behavior and supported patterns

  • win.postMessage(data, '*') where win is a Window (iframe contentWindow, window.opener, window.parent, window.open() result)
  • win.postMessage(data, { targetOrigin: '*' }) and wildcard values held in constants (const ANY = '*')
  • Payload sensitivity: names such as accessToken, password, cvv, cardNumber on the payload, its object-literal keys, its declared type properties, or variables/properties it was derived from
  • Recognized redaction (mask…(), .slice(-4), hashing) downgrades the payload to non-sensitive

Example

TypeScript
this.frame.nativeElement.contentWindow.postMessage({ accessToken: this.auth.token }, '*');

Safer alternative

TypeScript
this.frame.nativeElement.contentWindow.postMessage({ accessToken: this.auth.token }, 'https://widget.example.com');

Remediation

Always pass the exact expected origin (win.postMessage(data, 'https://app.example.com')). For iframes you created, derive it from the URL you loaded (new URL(src).origin). Never send credentials to '*'.

False-positive considerations

  • Broadcasting intentionally public, non-sensitive events (resize notifications, analytics pings) to an embedding page with * is reported only as low severity / low confidence.

Known limitations

  • Worker.postMessage / MessagePort.postMessage are not reported (no target-origin parameter).
  • Sensitivity is inferred from names and types; secrets in generically named variables (value, payload) are only detected when their data flow passes through a sensitive name.

References

Run it

Shell
ngbastion explain NGB006