Skip to content
XSS Write-up Beginner

DOM XSS in document.write Sink Using Source location.search Inside a <select> Element

The application uses document.write to insert a storeId parameter from the URL into a <select> element without sanitisation. An attacker can break out of the select element and inject JavaScript, leading to DOM-based XSS.

infosecwriteups.com

Published on infosecwriteups.com

In this scenario, the vulnerable application uses JavaScript’s document.write to dynamically generate part of a page, including a <select> dropdown. The values injected into this select element are not properly sanitized and originate from location.search, which reflects any query string passed via the URL.

Bash Overflow, on infosecwriteups.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The application fails to sanitise user input from location.search before inserting it into the DOM using document.write, allowing HTML injection.

Impact

Attackers could steal cookies or session tokens, and in advanced cases chain with browser or extension vulnerabilities to deploy malware.

What the attacker needed

Victim clicks a crafted link

How it was found

  1. Open the lab environment.
  2. Visit a product detail page.
  3. Inspect the JavaScript that uses document.write with storeId from location.search.
  4. Inject a payload to close the select tag.
  5. Inject a script tag to trigger an alert.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

The website takes a value from the web address and writes it directly into the page without cleaning it. An attacker can craft a link that makes the browser run their own code, which could steal login details or do other harmful things.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.