Stored Cross-Site Scripting (XSS)
Input that the application stores is later shown to other users without encoding for its context, so script saved by an attacker runs in their browsers.
| Severity | High |
| CVSS 3.1 | 8.7 CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:N Open in the calculator |
| CVSS 4.0 | 6.3 CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:P/VC:N/VI:N/VA:N/SC:H/SI:H/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 saves values supplied by users, such as profile fields, comments, messages, support tickets, file names or log entries, and later includes them in pages viewed by other users without encoding them for the context in which they appear. Script or markup saved by an attacker is therefore interpreted as part of the page by every browser that displays it, with the same access as the application's own code. Rich-text fields that accept HTML, and uploaded HTML or SVG files served from the application's own origin, are common sources.
Unlike the reflected form, no crafted link is needed: the payload runs whenever the affected page is viewed in the normal course of use, often in back-office or administrative views that the attacker cannot see, which is known as blind cross-site scripting. An attacker with an ordinary account can in this way run script in the session of every user who views the affected content, which often includes staff and administrators. The script can read anything those users can see and perform any action they can perform, such as changing account details, creating users or altering configuration, and can read session tokens not protected by the HttpOnly attribute. The effect persists until the stored value is removed, and the impact is much lower where the content is shown only to the user who supplied it, or a strict Content Security Policy blocks the script.
The weakness typically shows itself on a test when a unique string with special characters, submitted through one function, appears unencoded wherever the stored value is displayed, including views used by other roles. Burp Suite and OWASP ZAP detect common forms, and out-of-band payloads are used to find blind cases.
Remediation
Encode stored data whenever it is displayed, and limit what injected script could do:
- Encode stored data for the context where it is displayed, every time it is displayed, using a template engine that encodes automatically: HTML entity encoding for element content, attribute encoding for quoted attributes, and JavaScript or URL encoding where those contexts cannot be avoided. Avoid raw output helpers.
- Where users must be able to submit formatted text, sanitise it with a maintained HTML sanitiser that uses an allowlist of elements and attributes, or offer a restricted markup language such as Markdown rendered by a safe library.
- Serve user-uploaded files with a
Content-Disposition: attachmentheader and an explicit, safeContent-Type, preferably from a separate domain. - Deploy a Content Security Policy that allows scripts only by nonce or hash, and set
HttpOnlyon session cookies. - Validate input against the expected format when it is stored, as an extra layer.
After fixing the code, find and remove any malicious content already stored. Confirm the fix by repeating the original payloads in every affected field and checking that they display as text in every view.
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.