Skip to main content
InterviewHubPRO
Section Overview
Q331

Question 331 of 536

Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

62%
JavaScript & V8 Internals (536 Qs)•Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

What are the problems with postmessage target origin as wildcard

senior LevelCode ExampleAsync & PromisesEvent LoopHTTP & REST APIs

The second argument of postMessage method specifies which origin is allowed to receive the message. If you use the wildcard “*” as an argument then any origin is allowed to receive the message. In this case, there is no way for the sender window to know if the target window is at the target origin when sending the message. If the target window has been navigated to another origin, the other origin would receive the data. Hence, this may lead to XSS vulnerabilities.

javascript
  targetWindow.postMessage(message, "*");