Note
web
javascript
postmessage
html-injection
xss
origin-check
Send a message a receiver treats as trusted HTML because it skips strict origin and schema checks.
postMessage HTML Injection
postMessage is not dangerous by itself; the danger appears when the receiver treats message data as
trusted HTML or trusted commands without strict origin and schema checks.
Why It Works
- A handler that inserts
message.htmlinto the DOM without validatingorigin/sourceaccepts your attacker-sent payload.
Vulnerable Pattern
- Widgets or iframes receiving messages like
{type, html}and directly insertinghtmlinto the DOM.
Exploit Flow
- Identify the message format by reading bundled JS or probing with benign messages.
- Confirm whether the receiver validates
origin,source, both, or neither. - Once HTML is inserted, adapt the payload to the sink context and CSP.
Variations
- JSON-stringified messages, command messages that later load templates, or message-driven route changes reaching a second sink.
Common Blockers
- Strict
originchecks, structured schema validation, or rendering through text APIs.
PoC Sketch
iframe.contentWindow.postMessage({type:"render",html:"<img src=x onerror=alert(1)>"}, "*");
Good Situations To Use It
- A page embeds a widget/iframe that renders message HTML.
- Origin/source checks are missing or weak.
- The message schema is discoverable.
Sources
labossi_2026/web/trusted_support