Skip to content
XSS Write-up Intermediate

Single Unescaped Quote Broke JSON and Unleashed XSS on a Live E-C

A search endpoint embedded user input into JSON inside a JavaScript context without escaping single quotes, allowing an attacker to break out of the JSON string and inject arbitrary JavaScript. The attacker could execute script in the victim's browser, bypass WAF filtering via POST requests, and potentially poison analytics data.

Tyreek Haynes Follow

Published on medium.com

During a routine security assessment of a production e-commerce search feature, I discovered a criticalReflected Cross-Site Scripting (XSS) vulnerability triggered by a subtle yet dangerous encoding flaw within JSON strings.

Tyreek Haynes, 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

The application failed to escape single quotes when embedding user input into a JSON string that was rendered inside a JavaScript context.

Impact

An attacker could execute arbitrary JavaScript in a victim's browser to steal session cookies, CSRF tokens, and account information, perform actions as the victim, and poison analytics data; POST requests bypassed WAF filtering, and the text notes that CSP could reduce exploit reliability but was not implemented.

What the attacker needed

Victim clicks a crafted link; no authentication required

The fix

The application should escape single quotes inside JavaScript strings, use safe serialization like JSON.stringify, apply output encoding for the JavaScript context, add server-side validation, and implement a Content Security Policy.

How it was found

  1. Send a GET request to the search endpoint with a query parameter containing a single quote and JavaScript code.
  2. Observe that the single quote is not escaped, breaking the JSON structure and allowing script injection.
  3. Send the same payload via a POST request to bypass WAF filtering rules that only apply to GET requests.
  4. Confirm that the payload also appears unescaped in analytics tracking events, potentially leading to stored XSS.

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.

When a website puts user input into a JavaScript string, it must escape special characters like single quotes. Here, the site forgot to escape single quotes, so an attacker could close the string early and add their own JavaScript code. That code would then run in the browser of anyone who clicked a crafted link, letting the attacker steal data or act as the user.

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 Tyreek Haynes

View all

7 more disclosed reports, 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.