Concepts
Message origin and source validation
Application validation combining exact origin and known source with a data schema. Synthetic events do not prove transport security.
Formal Syntax & Structure
javascript syntaxjavascript
event.origin === expectedOrigin && event.source === expectedWindowReturn Value
boolean
Application validation combining exact origin and known source with a data schema. Synthetic events do not prove transport security.
Working Example
Example Snippetjavascript
(async () => {const origin="https://app.example";const accept=e=>e.origin===origin&&e.source===window&&e.data?.kind==="ready";const a=new MessageEvent("message",{origin,source:window,data:{kind:"ready"}});const b=new MessageEvent("message",{origin:"https://app.example.invalid",source:window,data:{kind:"ready"}});console.log(accept(a),accept(b));})()