I am new to the field of Web Security and am practising labs from Portswigger Web Security Academy. In this lab, we have to call the alert function with 1337 as the parameter.
The solution given on the website is
https://your-lab-id.web-security-academy.net/post?postId=5&%27},x=x=%3E{throw/**/onerror=alert,1337},toString=x,window%2b%27%27,{x:%27
The decoded version for reference is
https://your-lab-id.web-security-academy.net/post?postId=5&'},x=x=>{throw/**/onerror=alert,1337},toString=x,window+'',{x:'
From what I understand, there is a JavaScript statement like
var a = "get_parms"
and we are trying to break out of the string, close the block and execute our own code.
x=x=>{throw/**/onerror=alert,1337}
is the arrow function which assigns alert as global error handler and throws 1337.
toString=x, window+''
assigns x to toString and then forces a string conversion on window.
Now, I have two questions:
- Why does this work only when I click the back to blog button, in spite of forcing the string conversion on window?
- What is the use of the bolded characters in the URL (the
&
and the{x:'
)?
https://your-lab-id.web-security-academy.net/post?postId=5&'},x=x=>{throw/****/onerror=alert,1337},toString=x,window+'',{x:'