Web Security · Middle · Question 75 of 75
What must a message event handler for postMessage check?
window.addEventListener('message', (e) => {
applySettings(e.data);
});- ✓Correct answer: That
e.originis an expected origin, and thate.datahas the expected shape - 2Only that
e.datais not empty - 3Nothing,
postMessageonly works within the same origin
Explanation
Any window that holds a reference to yours can post messages. Without an origin check, another site can feed data into applySettings.