Reflected XSS into a JavaScript string with angle brackets HTML encoded
Description
The website in this lab contains a reflected cross-site scripting vulnerability in the search query tracking functionality where angle brackets are encoded. The reflection occurs inside a JavaScript string. Also see the HackTricks XSS page, in the section on Inside JavaScript code.
Reproduction and proof of concept
Put a random alphanumeric string in the search box, then use Burp Suite to intercept the search request and send it to Burp Repeater.
<script>
var searchTerms = '<alphanumeric';
document.write('<img src="/resources/images/tracker.gif?searchTerms='+encodeURIComponent(searchTerms)+'">');
</script>
The random string has been reflected inside a JavaScript string: The script accepts input, assigns it to the variable
searchTerms
, and does adocument.write
with the encoded URL usingencodeURIComponent
.Replace the input with this payload to break out of the JavaScript string and inject an alert:
'-alert('XSS')-'