I was doing the following PortSwigger Lab on cross site scripting (XSS).
The following payload works perfectly.
http://foo?'-alert(1)-'
Which is input into the following section of the webpage.
<img src="/resources/images/avatarDefault.svg" class="avatar">
<a id="author" href="http://foo.com'-alert(1)-'" onclick="var tracker={track(){}};tracker.track('http://foo.com'-alert(1)-'');">last</a> | 16 June 2022
Could someone please explain how the payload works, for example whether the &apos
escapes the HTML or the JavaScript code, and why that results in alert()
being executed?