Skip to content
XSS Write-up Beginner

DOM XSS and JavaScript Logic: Escaping HTML ≠ Escaping Danger

The article demonstrates that escaping HTML before inserting user input into the DOM via innerHTML does not prevent DOM-based XSS, and that client-side JavaScript logic for access control can be bypassed. An attacker could inject script through a URL parameter or manipulate the browser console to reveal admin links or exfiltrate data.

medium.com

Published on medium.com

We have all probably heard of Cross-Site Scripting (XSS) at this point. In 2017, it was in the 7th place on the OWASP Top 10, and in 2021 it moved up to number 3.

Marshall Humble, 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 application relied on client-side HTML escaping and JavaScript logic for security, which can be bypassed because the browser environment is fully controllable by the user.

Impact

An attacker could execute arbitrary JavaScript in the victim's browser to steal data or perform actions, and could bypass client-side access controls to reveal admin functionality; however, the article notes that server-side checks are the real fix and that client-side measures alone are insufficient.

What the attacker needed

Victim clicks a crafted link; attacker can run JavaScript in browser console

The fix

The article recommends server-side validation and output sanitisation, using .textContent or DOMPurify instead of innerHTML, and not relying on JavaScript for logic or input validation.

How it was found

  1. Open the page with a URL parameter containing an image tag with an onerror handler to trigger a pop-up.
  2. Observe that the escaping function blocks the script tag but the page still executes the onerror handler.
  3. Use the browser console to run JavaScript that changes the display of the admin link.
  4. Alternatively, set the role parameter to admin in the URL to reveal the admin link.
  5. Use JavaScript to read account information and send it to an attacker-controlled server.

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.

This article shows that cleaning up special characters in user input before putting it on a web page is not enough to stop script injection. It also shows that decisions made only in the browser, like hiding an admin link, can be changed by anyone using browser developer tools. The lesson is that security checks must happen on the server, not just in the browser.

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.