# PostMessage Vulnerabilities ## Send **PostMessage** **PostMessage** uses the following function to send a message: ```bash targetWindow.postMessage(message, targetOrigin, [transfer]); # postMessage to current page window.postMessage('{"__proto__":{"isAdmin":True}}', '*') # postMessage to an iframe with id "idframe" document.getElementById('idframe').contentWindow.postMessage('{"__proto__":{"isAdmin":True}}', '*') # postMessage to an URL window.postMessage('{"__proto__":{"isAdmin":True}}', 'https://company.com') ``` Note that **targetOrigin** can be a '\*' or an URL like _https://company.com._ In the **second scenario**, the **message can only be sent to that domain** \(even if the origin of the window object is different\). If the **wildcard** is used, **messages could be sent to any domain**, and will be sent to the origin of the Window object. ### Attacking iframe & wilcard in **targetOrigin** As explained in [**this report**](https://blog.geekycat.in/google-vrp-hijacking-your-screenshots/) if you find a page that can be **iframed** \(no `X-Frame-Header` protection\) and that is **sending sensitive** message via **postMessage** using a **wildcard** \(\*\), you can **modify** the **origin** of the **iframe** and **leak** the **sensitive** message to a domain controlled by you. Note that if the page can be iframed but the **targetOrigin** is **set to a URL and not to a wildcard**, this **trick won't work**. ```markup ``` For **more information**: * Link to page about [**prototype pollution**](deserialization/nodejs-proto-prototype-pollution.md)\*\*\*\* * Link to page about [**XSS**](xss-cross-site-scripting/)\*\*\*\* * Link to page about [**client side prototype pollution to XSS**](deserialization/nodejs-proto-prototype-pollution.md#client-side-prototype-pollution-to-xss)\*\*\*\* ## References * [https://jlajara.gitlab.io/web/2020/07/17/Dom\_XSS\_PostMessage\_2.html](https://jlajara.gitlab.io/web/2020/07/17/Dom_XSS_PostMessage_2.html) * [https://dev.to/karanbamal/how-to-spot-and-exploit-postmessage-vulnerablities-36cd](https://dev.to/karanbamal/how-to-spot-and-exploit-postmessage-vulnerablities-36cd)