In the vast ocean of web security, Cross-Site Scripting (XSS) is a prevalent menace. One of its treacherous waves is Reflected XSS (or Non-Persistent XSS). Unlike stored XSS attacks, where the malicious script is permanently stored on the target server, Reflected XSS attacks are immediate, launching back at the user almost instantly. Let’s unmask this threat and explore ways to safeguard against it.
How Does Reflected XSS Work?
Reflected XSS attacks are typically delivered via URL parameters. Here’s the basic flow:
- An attacker crafts a URL containing a malicious script.
- The unsuspecting victim clicks on the link.
- The website takes this input and immediately reflects it back, causing the script to run in the victim’s browser.
The attack is termed “reflected” because the web server reflects the injected script back to the user’s browser, where it’s executed immediately.
Why is Reflected XSS Dangerous?
The immediate danger with Reflected XSS is its potential for phishing attacks. Since the malicious script executes instantly, attackers can craft deceptive pages or steal sensitive information, all while appearing to be within the context of the trusted website.
A Detailed Illustration
Imagine a search function on the website html.news
. You type in a keyword, and if there are no results, the site might display a message like, “No results found for your keyword.”
Here are six potential Reflected XSS attacks, from the simplest to the most complex:
- Basic Payload:
https://html.news/search?q=<script>alert('html.news XSS');</script>
A direct script injection. If the website doesn’t sanitize this input, an alert box would pop up.
- Using Event Handlers:
https://html.news/search?q=<img src='invalid' onerror='alert("html.news XSS");'>
This uses an image’s error event to trigger the script since the image source is invalid.
- URL Encoding:
https://html.news/search?q=%3Cscript%3Ealert('html.news XSS')%3C/script%3E
The script tags and the payload are URL encoded, which some naive filters might not catch.
- HTML Entity Encoding:
https://html.news/search?q=<script>alert('html.news XSS');</script>
Uses HTML entity encoding to represent the
<script>
tags, potentially bypassing simple filters. - Mixed Encoding:
https://html.news/search?q=%26%23x3C;script%26%23x3E;alert('html.news XSS');%26%23x3C;/script%26%23x3E;
A combination of URL and HTML entity encoding to further obfuscate the payload.
Support authors and subscribe to content
This is premium stuff. Subscribe to read the entire article.