Origins-verified cross-origin communications High

Unverified origins of messages and identities in cross-origin communications can allow attackers access to web applications and servers through unauthenticated requests. This access can result in redirection to malicious websites, information leakage, or modification of target applications through the takeover of user accounts.

Detector ID
javascript/origins-verified-cross-origin-communications@v1.0
Category
Common Weakness Enumeration (CWE) external icon

Noncompliant example

1function originsVerifiedCrossOriginCommunicationsNoncompliant() {
2    var iframe = document.getElementsByClassName(".testiframe")
3    // Noncompliant: the wildcard keyword `*` is used.
4    iframe.contentWindow.postMessage("secret_value", "*")
5}

Compliant example

1function originsVerifiedCrossOriginCommunicationsCompliant() {
2    var iframe = document.getElementsByClassName(".testiframe")
3    // Compliant: using secure origin.
4    iframe.contentWindow.postMessage("secret_value", "https://secure.example.com")
5}