You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The origin of the received message is not checked. This means any site (even malicious) can send message to this window. If you don't expect this, consider checking the origin of sender.
postMessage is a feature to perform cross-origin communication between JavaScript Window objects. This can be done by:
The sender using the targetWindow.postMessage(message, targetOrigin) to send a message to the targetWindow but only if the origin in that window matches targetOrigin (or if targetOrigin is set to the special value *);
The receiver listening for the message event in the window object.
However, if no validation is done by the receiver, this could allow any window to send arbitrary data to the handler. This vulnerability could be leveraged by an attacker to disclose sensitive data to a malicious origin, or perform actions on a vicitim's behalf.
Example:
window.addEventListener("message",(event)=>{// DANGEROUS: No validation of origindoStuff(event.data);});
Best practices for prevention
Adopt a zero-trust model in which all input is considered potentially suspect.
Specify the targetOrigin instead of designating a wildcard *.
Snyk seems to confuse a PeerJS data channel with a multi-window message exchange. This is definitely a false positive.
There’s probably a way to mute that in Snyk directly, but you can also just replace
`.addEventListener("message",...)` with `.on("message", ...)`
peers
locked and limited conversation to collaborators
Dec 3, 2023
Insufficient postMessage Validation
The origin of the received message is not checked. This means any site (even malicious) can send message to this window. If you don't expect this, consider checking the origin of sender.
peerjs.js (line : 4232)
Fix Analysis
Details
postMessage is a feature to perform cross-origin communication between JavaScript Window objects. This can be done by:
The sender using the
targetWindow.postMessage(message, targetOrigin)
to send a message to thetargetWindow
but only if the origin in that window matchestargetOrigin
(or if targetOrigin is set to the special value*
);The receiver listening for the message event in the window object.
However, if no validation is done by the receiver, this could allow any window to send arbitrary data to the handler. This vulnerability could be leveraged by an attacker to disclose sensitive data to a malicious origin, or perform actions on a vicitim's behalf.
Example:
Best practices for prevention
*
.Example:
References
Introduction to postMessage() Vulnerabilities
The text was updated successfully, but these errors were encountered: