Skip to content
XSS Write-up Beginner

Reflected DOM XSS

The search bar's results are fetched as JSON and then passed into eval(), so the response text is run as JavaScript rather than treated as data. A crafted search term breaks out of the JSON string and causes the browser to run attacker-supplied script.

medium.com

Published on medium.com

In this lab activity, the application has a vulnerable search bar wherein a script on the page processes that input in an unsafe way

Maning, on medium.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

Likely the client-side script concatenates the raw JSON response into an eval() call, so a crafted search term escapes the JSON string and is executed as code.

Impact

An attacker could run arbitrary JavaScript in a victim's browser through a crafted search term, though the text only demonstrates an alert rather than a real attack.

What the attacker needed

Victim clicks a crafted search link

The fix

The response should be parsed as JSON data rather than passed to eval(), so the text is never executed as code.

How it was found

  1. Search for any term and inspect the page to find the searchResults.js script handling the input.
  2. Read the script and note that the response text is passed into eval().
  3. Send the search request through a proxy repeater and observe the results and searchTerm fields in the response.
  4. Try a backslash and see it is treated as part of the text.
  5. Try a crafted term with a quote and a closing brace, and see it is still escaped inside the JSON.
  6. Submit the crafted term in the search bar and the alert fires because eval() runs the response.

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's search box sends what you type to the server and gets back a small data reply. Instead of reading that reply as plain data, the page runs it as computer code, so anything sneaky hidden in the reply gets executed by your browser. That lets an attacker make the page run their own script.

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.