Skip to content
XSS Write-up Intermediate

An (somewhat) interesting XSS vector using JavaScript identifiers

A web endpoint builds an onclick attribute by concatenating a user-supplied suffix into a JavaScript function name, and only strips quotes. An attacker can supply a suffix that assigns a value to the static prefix and then runs arbitrary JavaScript, leading to script execution in the victim's browser.

medium.com

Published on medium.com

JavaScript is a chaotic language that thrives on flexibility, allowing variable names like \u0061, ಠಠ, and even λ. This permissive syntax encourages creativity but also makes JavaScript vulnerable to exploits, especially when developers generate dynamic code from user input.

Jonas Benjamin Friedli, 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 concatenates unsanitised user input into a JavaScript identifier inside an inline event handler, and only removes quotes, so the input can break out of the identifier and inject code.

Impact

An attacker could execute arbitrary JavaScript in a victim's browser when the button is clicked, though the technique is limited to static strings containing characters valid in JavaScript variable names.

What the attacker needed

Victim clicks the crafted button; attacker can control the URL parameter

The fix

The vulnerability should be fixed by validating the user-supplied suffix against a whitelist of allowed values before inserting it into the page.

How it was found

  1. Send a request to the endpoint with the item_function_suffix parameter set to a value that assigns to the static prefix and appends code.
  2. The server builds the button HTML with the injected value inside the onclick attribute.
  3. The browser renders the button, and clicking it executes the injected JavaScript.

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 page puts part of a web address into a button's click code without checking it properly. By choosing a special value, an attacker can make the button run their own JavaScript when clicked, which could 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.

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.