This lab contains a reflected cross-site scripting (XSS) vulnerability in the search query tracking functionality.
Angle brackets < > are HTML-encoded, but the reflection occurs inside a JavaScript string.
Perform a cross-site scripting attack that breaks out of the JavaScript string and calls the alert function.
The search term is reflected inside JavaScript code, e.g.:
var q = 'USER-INPUT';
Because the input is inside quotes, injecting HTML tags will not work (<script>...</script>).
Instead, we must break out of the JavaScript string using quotes and inject our payload.
Submit a random alphanumeric string in the search box (e.g., abc123).
Using Burp Suite Repeater, observe that it is reflected in the response:
var q = 'abc123';
Replace the input with the payload:
'-alert(1)-'
The response becomes:
var q = ''-alert(1)-'';
' closes the string.alert(1)- is executed as JavaScript.' reopens/closes to keep the script valid.
Copy the crafted URL, paste it in the browser, and load the page.
An alert(1) popup is triggered → exploit successful. ✅