Skip to content
XSS Write-up Intermediate

Stored XSS into Onclick Event: Bypassing Angle Brackets, Double Quotes, and Escaped Characters — XSS Labs

A stored cross-site scripting vulnerability existed in the comment author field, where user input was reflected into an onclick event handler. Despite HTML-encoding of angle brackets and double quotes, and escaping of single quotes and backslashes, an attacker could inject JavaScript that executed when a victim clicked the author name.

Bash Overflow Follow

Published on infosecwriteups.com

The lab titled Stored XSS into onclick event with angle brackets and double quotes HTML-encoded and single quotes and backslash escaped explores a stored cross-site scripting (XSS) vulnerability in a web application’s comment functionality. The vulnerability arises due to insufficient sanitization of user input within…

Bash Overflow, on infosecwriteups.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 inserted user input into an onclick attribute without properly escaping or validating it for that context, allowing JavaScript execution despite some character encoding.

Impact

An attacker could steal session cookies to impersonate users, and the stored XSS affects all users viewing the compromised comment, amplifying the attack’s reach.

What the attacker needed

Ability to post comments; victim clicks the author name

The fix

The application should use a library like DOMPurify to sanitize HTML and replace onclick event handlers with safer alternatives such as event listeners with strict validation.

How it was found

  1. Open the XSS lab and select an example article.
  2. Fill out the comment section, including a payload in the input field.
  3. Go back to Burp Suite’s HTTP History and examine the server’s response to see sanitization.
  4. Notice that the onclick event reflects the URL input from the comment section.
  5. Inject a payload in the URL form and check the browser’s response using Developer Tools.
  6. Observe that certain HTML characters are converted back, then inject another payload and click the username to trigger the alert.

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 is a stored cross-site scripting (XSS) bug. When a user submits a comment, their name is saved and later shown to other visitors. The site tried to block harmful code by encoding certain characters, but the attacker found a way to sneak in JavaScript that runs when someone clicks the name. This could let an attacker steal cookies or perform actions as the victim.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by Bash Overflow

View all

35 more disclosed reports, best first.

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.