InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties…

Follow publication

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

[Write-up] Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped.

Introduction

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 an onclick HTML event attribute.

Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped - Bashoverflow - Medium
Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped

In this lab:

  • Angle brackets (<, >) and double quotes (") are HTML-encoded, preventing direct injection of new HTML tags or attributes.
  • Single quotes (') and backslashes (\) are escaped, limiting the use of certain characters in payloads.
  • The challenge requires bypassing these sanitization measures to inject a JavaScript payload (e.g., alert()) that triggers when a user clicks the comment author’s name.

Disclaimer:
The techniques described in this document are intended solely for ethical use within the controlled environment of PortSwigger Labs for educational and training purposes. Unauthorized use of these methods outside approved environments is strictly prohibited, as it is illegal, unethical, and may lead to severe consequences.

It is crucial to act responsibly, comply with all applicable laws, and adhere to established ethical guidelines. Any activity that exploits security vulnerabilities or compromises the safety, privacy, or integrity of others is strictly forbidden.

Summary of the Vulnerability

This lab contains a stored cross-site scripting (XSS) vulnerability in the comment functionality. Attackers can inject malicious JavaScript into the comment author field.

When the victim clicks the author name, the payload (e.g., alert()) executes. The challenge involves crafting a payload that bypasses input sanitization (e.g., HTML encoding of angle brackets/double quotes and escaping of single quotes/backslashes).

Steps to Reproduce & Proof of Concept (POC)

1. Open the XSS lab and select one of the example articles.

Image 1 - Lab: Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped

2. Fill out the comment section, including a payload in the input field.

Image 2 - Lab: Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped
Image 3 - Lab: Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped

3. Go back to Burp Suite’s HTTP History and examine the server’s response, which shows the sanitization applied to your payload.

Image 4 - Lab: Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped

4. Notice that the onclick event reflects the URL input from the comment section.

5. Attempt to inject the second payload in the URL form:

/?&apos;&quot;&gt;&lt;img src=x onerror=alert(1)&gt;//

/?&apos;&quot;&gt;&lt;img src=x onerror=alert(1)&gt;//
Image 5 - Lab: Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped

6. Check the browser’s response using Developer Tools (press F12).

Image 6 - Lab: Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped

7. Observe that certain HTML characters &apos; is converted back to (single quote)

8. Inject the next payload:

/?&apos;-top[`alert`](1)-&apos; 
Image 7 - Lab: Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped

9. Return to the comment section and click on the username.

Image 8 - Lab: Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped

10. The payload executes successfully, triggering a pop-up with alert(1).

11. The lab is now solved

Image 9 - Lab: Stored XSS into Onclick Event with Angle Brackets and Double Quotes HTML-encoded and Single Quotes and Backslash Escaped

Impact

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

Mitigation

  • Leverage libraries like DOMPurify to sanitize HTML
  • Replace onclick event handlers with safer alternatives (e.g., event listeners with strict validation)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties and CTFs to vulnhub machines, hardware challenges and real life encounters. Subscribe to our weekly newsletter for the coolest infosec updates: https://weekly.infosecwriteups.com/

Written by Bash Overflow

Cybersecurity Enthusiast | Sharing insights through some writeups | Passionate about advancing knowledge in the field of cybersecurity

No responses yet

Write a response