no-message-origin-string-matching
Compare incoming browser message origins against exact trusted origins.
Why
Prefix, suffix and substring checks do not establish an origin trust boundary. For example, https://trusted.example.attacker.invalid passes a prefix check against https://trusted.example.
Fix
Compare exact allowlisted origins or parse the origin and validate the intended scheme, host and port. Reject opaque null origins unless a separately verified source/capability contract establishes trust; do not require an experimental Origin API.
Examples
window.addEventListener("message", (event) => { if (event.origin.startsWith("https://trusted.example")) accept(event.data);});window.addEventListener("message", (event) => { if (event.origin === "https://trusted.example") accept(event.data);});References
- https://github.com/GoogleChrome/modern-web-guidance/blob/4dd968349e54ca45a05dd5c818fb035c9054b022/skills/modern-web-guidance/guides/security/validate-origins.md
- https://github.com/GoogleChrome/modern-web-guidance/blob/4dd968349e54ca45a05dd5c818fb035c9054b022/skills/modern-web-guidance/guides/security/security.md