-
Notice that the home page contains an
addEventListener()
call that listens for a web message. The JavaScript contains a flawedindexOf()
check that looks for the strings"http:"
or"https:"
anywhere within the web message. It also contains the sinklocation.href
. -
Go to the exploit server and add the following
iframe
to the body, remembering to replaceYOUR-LAB-ID
with your lab ID:<iframe src="https://YOUR-LAB-ID.web-security-academy.net/" onload="this.contentWindow.postMessage('javascript:print()//http:','*')">
- Store the exploit and deliver it to the victim.
This script sends a web message containing an arbitrary JavaScript payload, along with the string "http:"
. The second argument specifies that any targetOrigin
is allowed for the web message.
When the iframe
loads, the postMessage()
method sends the JavaScript payload to the main page. The event listener spots the "http:"
string and proceeds to send the payload to the location.href
sink, where the print()
function is called.