JavaScript · Senior · Question 16 of 75

What must you check in a message handler when talking to an iframe via postMessage?

Explanation

postMessage works across origins, and any window can send a message. Without checking origin, an attacker can send forged commands. When sending, specify a concrete targetOrigin instead of '*'. Between tabs of the same site, BroadcastChannel is handy.

Further reading

Problem with a question

JavaScript · Senior · question 16

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz