Skip to content
XSS Write-up Intermediate

How I found Reflected XSS which leads to Account Takeover on an E-commerce website

The search functionality reflected user input inside a script tag and attempted to strip closing script tags, but a nested-tag trick bypassed the filter. An attacker could craft a link that executes script in a victim's browser and steals their cookies, leading to account takeover.

npthin1804 Follow

Published on medium.com

Hi everyone, I hope you are doing well. This is my first time writing a bug write-up.

p00dl3, 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 server attempted to remove closing script tags with a non-recursive replacement, allowing a nested tag to bypass the filter and break out of the script context.

What the attacker needed

Victim clicks a crafted link; search functionality reflects input

The fix

The server should properly encode or sanitise user input before embedding it in a script context, rather than relying on naive string replacement.

How it was found

  1. Perform a search with a benign HTML tag to see how input is reflected.
  2. Observe that the search result is placed inside a script tag in JSON format.
  3. Try to break out by searching for a closing script tag and note that it is removed.
  4. Insert the closing script tag between each character to bypass the removal.
  5. Confirm the breakout and craft a payload that executes script to steal cookies.

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's search box put whatever you typed directly into the page's code without proper cleaning. The author found a way to sneak in a command that runs in the visitor's browser and sends their login cookie to the attacker. With that cookie, the attacker can pretend to be the victim and access their account.

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.