Reflected Cross-Site Scripting (XSS)
Input from a request is returned straight away in the page without encoding for its context, so a crafted link can run an attacker's script in the victim's browser.
| Severity | Medium |
| CVSS 3.1 | 6.1 CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N Open in the calculator |
| CVSS 4.0 | 5.1 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N Open in the calculator |
| CWE | CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') |
| OWASP Top 10 | A05:2025 Injection |
| MITRE ATT&CK | T1189 Drive-by Compromise, T1539 Steal Web Session Cookie |
| Category | Input Validation |
Description
The application takes a value from the request, such as a search term, error message or URL parameter, and includes it in the HTML response without encoding it for the context in which it appears. A value containing markup or script, such as a <script> element, an event handler attribute or a javascript: URL, is therefore interpreted by the browser as part of the page. Because the script runs on the application's own origin, the browser gives it the same access as the application's legitimate code.
The attack is delivered by persuading a victim to open a crafted link, or to visit a page that submits the request, usually while logged in. The injected script then runs in the victim's session, so the attacker can do anything the victim can do in the application: read data shown to them, perform actions on their behalf, capture what they type, display a convincing fake login form, or read session tokens that are not protected by the HttpOnly attribute. Because each victim must be persuaded to follow a link, the scale is limited; the impact is greater where victims include administrators, and lower where a strict Content Security Policy blocks injected script.
The weakness typically shows itself on a test when a unique string with special characters is returned unencoded and a payload is then confirmed to execute in a browser. The context matters: element content, attribute values, JavaScript strings and URLs each need different encoding, and filters that remove particular tags or words are commonly bypassed. Burp Suite, OWASP ZAP, Acunetix and Nuclei templates all detect common forms.
Remediation
Encode output for its context, and limit what injected script could do:
- Encode all untrusted data for the context where it is placed in the page: HTML entity encoding for element content, attribute encoding for quoted attribute values, JavaScript string encoding for values in scripts, and URL encoding for URL parameters. Use a template engine that encodes automatically, and avoid helpers that bypass it, such as raw output functions.
- Do not place untrusted data directly in script blocks, event handlers or style elements. Pass it in a data attribute or a safely encoded JSON object, and read it from there.
- Where a URL from the user is placed in a link or redirect, allow only the
httpandhttpsschemes. - Validate input against the expected format as an extra layer of defence.
- Deploy a Content Security Policy that allows scripts only by nonce or hash, without
unsafe-inline, and set theHttpOnlyattribute on session cookies.
Confirm the fix by repeating the original payloads, and variants for the same context, and checking that they are displayed as text and do not execute.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.