DOM XSS in document.write
The page's search feature took the value of the URL's search parameter and wrote it into the page using JavaScript's document.write without sanitising it. An attacker could craft a link that breaks out of the surrounding markup and runs script in the victim's browser.
medium.com
Published on medium.com
Cross-site scripting (also known as XSS) is a web security vulnerability that allows an attacker to compromise the interactions that users have with a vulnerable application. It allows an attacker to circumvent the same origin policy, which is designed to segregate different websites from each other.
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
Likely the client-side script passed the URL's search parameter directly into document.write without encoding or validating it, so the value could close the existing markup and inject new elements.
What the attacker needed
Victim clicks a crafted link; JavaScript enabled in the browser
The fix
The script should encode or otherwise sanitise the URL parameter before writing it to the page, or avoid document.write and set text content instead.
How it was found
- Enter a plain test string in the search box and observe how it is reflected on the page.
- Craft a payload that breaks out of the surrounding context and triggers JavaScript.
- Place the payload in the search box and submit it.
- Observe the GET request in Burp Suite and forward it.
- Load the page and see the alert popup, confirming script execution.
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 website can build parts of the page with JavaScript running in your browser. Here the script copied whatever was typed after ?search= in the address bar straight into the page. Because it did not clean that text first, someone could put code in the link, and the browser would run it as if the site itself had written it.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.