Skip to content
XSS Write-up Beginner

Title: The One with the eval() — A DOM-Based XSS That Got P

A JavaScript file on a Shopify store read the cart_token URL parameter and passed it directly to eval(), allowing an attacker to execute arbitrary JavaScript in a victim's browser. The author demonstrated that a crafted URL could run code such as alert(document.domain) without authentication or filtering.

Mostafa Ghanem Follow

Published on mosstafa.medium.com

It was late. Screens dimmed.

Mostafa Ghanem, on mosstafa.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 code passed an untrusted URL parameter directly into eval() without any validation or sanitisation.

Impact

An attacker could execute arbitrary JavaScript in a victim's browser, potentially leading to session hijacking, admin account takeover, or silent customer skimming if cookies are accessible.

What the attacker needed

Victim clicks a crafted link; no authentication required

The fix

The eval() should be removed entirely, URL parameters should be sanitised and validated, and a Content Security Policy with script-src 'self' should be implemented.

How it was found

  1. Find the JavaScript file ajax-cart.js on a Shopify store.
  2. Notice that it reads the cart_token parameter from the URL and passes it to eval().
  3. Craft a URL with a JavaScript payload in the cart_token parameter.
  4. Open the URL to trigger execution of the payload in the browser.

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 took a value from the address bar and ran it as JavaScript code without checking it. Because anyone can put anything in a URL, an attacker could make the browser run their own code when a victim opened a link. This is called DOM-based cross-site scripting (XSS).

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.