Skip to content
XSS Write-up Intermediate

Apostrophe encoding and XSS in modern browsers

A parameter value was placed into a JavaScript string without decoding, so an attacker could break out of the string with an apostrophe and run script. Some browsers encode the apostrophe automatically, but others do not, so the issue stayed exploitable in those browsers.

en.internetwache.org

Published on en.internetwache.org

During a bugbounty hunt Sebastian discovered a script-context XSS with the injection point being a string. As you know, all modern browsers like Firefox, Chromium, IE automatically encode the apostroph.

Internetwache.org, on en.internetwache.org

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 application inserted a URL parameter into a JavaScript string literal without escaping or decoding it, and relied on browser-side apostrophe encoding as a defence.

Impact

An attacker could run script in the victim's browser on sites where the parameter is not decoded, but only in browsers that do not encode the apostrophe automatically.

What the attacker needed

Injection point inside a JS string; browser that does not encode apostrophe

The fix

The application should escape or encode the parameter before placing it into a JavaScript string, rather than relying on browser behaviour.

How it was found

  1. Start a listener on a local port.
  2. Open a local URL with a parameter containing an apostrophe.
  3. Observe that the browser changed the apostrophe into its percent-encoded form.

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 can put a value from the address bar into a piece of JavaScript code. If that value is not cleaned, a person can add characters that end the code string and start new code, which runs in the victim's browser. Some browsers hide the apostrophe by turning it into a code, but not all browsers do this, so the same page can be safe in one browser and unsafe in another.

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.