Skip to content
XSS Write-up Beginner

DOM XSS in document.write sink inside a select element — Cr

The stock-checker on a product page read a storeId value from the URL and wrote it into the page with document.write inside a select element without escaping. An attacker could craft a link that breaks out of the select context and injects an element with an event handler, running JavaScript in the victim's browser.

Zeyad Naguib Follow

Published on cybersecuritywriteups.com

The product page’s stock-checker feature uses document.write() to insert a storeId option taken directly from the URL fragment/query. Because the input is neither validated nor escaped, a crafted storeId can close the <select>/<option> context and inject an element with an event handler (e.g., <img onerror=alert(1)>)…

Zeyad Naguib, on cybersecuritywriteups.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 client-side code passed a URL parameter directly to document.write() inside an HTML select/option context without encoding or validation, so the value could break out of that context and inject markup.

Impact

Arbitrary JavaScript could run in the vulnerable origin, allowing theft of non-HttpOnly session tokens, DOM manipulation, unauthorised actions or data exfiltration, and the payload could be delivered via phishing links.

What the attacker needed

Victim opens a crafted product URL

The fix

The code should stop using document.write() with untrusted input, create option elements with DOM APIs and textContent, validate storeId against an expected format, and add a CSP and HttpOnly/SameSite cookies as defence in depth.

How it was found

  1. Open a product page and inspect the page source to find the stock-checker code.
  2. Notice a hidden storeId parameter used by the stock checker.
  3. Add a storeId parameter with a random value to the URL and confirm it appears as a new option in the list.
  4. Replace the storeId value with a payload that closes the select and injects an element with an onerror handler.
  5. Observe the injected element's onerror handler run, demonstrating the injection.

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.

A web page took a value from the address bar and pasted it straight into the page's HTML without cleaning it. Because the page trusted that value, an attacker could put special characters in the link that trick the browser into running their own code when a victim opens it. This is called DOM-based cross-site scripting, where the dangerous change happens in the browser rather than on the server.

What is XSS?

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

More by Zeyad Naguib

View all

1 more disclosed report, best first.

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.