+The "message" event is used to send messages between windows.
+An untrusted window can send a message to a trusted window, and it is up to the receiver to verify the legitimacy of the message. One way of performing that verification is to check the origin of the message ensure that it originates from a trusted window.
+
+Always verify the origin of incoming messages. +
++The example below uses a received message to execute some code. However, the +origin of the message is not checked, so it might be possible for an attacker +to execute arbitrary code. +
++The example is fixed below, where the origin is checked to be trusted. +It is therefore not possible for a malicious user to perform an attack using an untrusted origin. +
+If you use cross-origin communication between Window objects and do expect to receive messages from other sites, always verify the sender's identity using the origin and possibly source properties of the recevied `MessageEvent`.
- -Unexpected behaviours, like `DOM-based XSS` could occur, if the event handler for incoming data does not check the origin of the data received and handles the data in an unsafe way.
--Always verify the sender's identity of incoming messages. -
- -In the first example, the `MessageEvent.data` is passed to the `eval` function withouth checking the origin. This means that any window can send arbitrary messages that will be executed in the window receiving the message
-In the second example, the `MessageEvent.origin` is verified with an unsecure check. For example, using `event.origin.indexOf('www.example.com') > -1` can be bypassed because the string `www.example.com` could appear anywhere in `event.origin` (i.e. `www.example.com.mydomain.com`)
-In the third example, the `MessageEvent.origin` is properly checked against a trusted origin.
-