13.10 Lab: DOM XSS in document.write sink using source location.search inside a select element | 2024

This lab contains a DOM-based cross-site scripting vulnerability in the stock checker functionality. It uses the JavaScript document.write function, which writes data out to the page. The document.write function is called with data from location.search which you can control using the website URL. The data is enclosed within a select element | Karthikeyan Nagaraj

Karthikeyan Nagaraj
2 min readMar 14, 2024

Description

This lab contains a DOM-based cross-site scripting vulnerability in the stock checker functionality. It uses the JavaScript document.write function, which writes data out to the page. The document.write function is called with data from location.search which you can control using the website URL. The data is enclosed within a select element.

To solve this lab, perform a cross-site scripting attack that breaks out of the select element and calls the alert function.

Solution

  1. On the product pages, notice that the dangerous JavaScript extracts a storeId parameter from the location.search source. It then uses document.write to create a new option in the select element for the stock checker functionality.
  2. Add a storeId query parameter to the URL and enter a random alphanumeric string as its value. Request this modified URL.
  3. In the browser, notice that your random string is now listed as one of the options in the drop-down list.
  4. Right-click and inspect the drop-down list to confirm that the value of your storeId parameter has been placed inside a select element.

Exploitation

  1. Click a product and add the below payload at the end of the URL
    &storeId=”></select><img src=1 onerror=alert(1)>
  2. The final URL should be like this
    https://LAB_ID/product?productId=1&storeId=”></select><img%20src=1%20onerror=alert(1)>

--

--

Karthikeyan Nagaraj

Entrepreneur | Writer | Cyber Security Consultant | AI Researcher