Definition
Reflected Cross-Site Scripting (XSS) is a security vulnerability where an attacker injects malicious scripts into a website's HTTP response via user-supplied input. Unlike stored XSS, where the script is saved on the server, reflected XSS scripts are immediately reflected back to the user within the HTTP response.How It Works
- 1An attacker creates a malicious URL containing a script payload.
- 2A victim clicks on this malicious link.
- 3The server processes the request and reflects the input, including the script, in the HTTP response.
- 4The victim's browser executes the script, treating the response as trusted content.
Key Characteristics
- Triggered when a victim clicks a crafted link.
- Script is reflected immediately, not stored on the server.
- Often involves input fields, parameters, or headers echoed in HTTP responses.
Comparison
| Type | Stored on Server | Immediate Execution | Common Vector |
|---|---|---|---|
| Reflected XSS | No | Yes | URL query parameters |
| Stored XSS | Yes | No (until triggered) | Comments, forum posts |
| DOM-based XSS | No | Yes | JavaScript processing in DOM |
Real-World Example
CVE-2020-12345 revealed a reflected XSS vulnerability in a popular web application where user input wasn't properly sanitized in an error message. Attackers could execute arbitrary JavaScript in the user's browser session.Detection & Prevention
- Detection: Use tools like Burp Suite or OWASP ZAP to inject unique markers and analyze the reflected output.
- Prevention: Implement Content Security Policy (CSP) headers, use output encoding (e.g., HTML encoding), and validate/sanitize user inputs.
Common Misconceptions
- "Reflected XSS is not as dangerous as stored XSS." Both can be equally harmful depending on context and execution.
- "Only web forms can be exploited." Any user input, including URL parameters and headers, can be vectors for reflected XSS.
- "Firewalls and antivirus software can block XSS." These tools may not fully protect against XSS, as the vulnerability is at the application layer.