Not the File, Just the Name: Exploring Stored XSS in Upload Funct
The upload feature validated file content and extension but did not sanitise the filename, which was stored and later rendered into the HTML page without output encoding. An attacker could inject JavaScript through the filename so that it executed for users who viewed the file listing.
Published on medium.com
During an authorized security assessment of a real-world web application, I identified a Stored Cross-Site Scripting (XSS) vulnerability in the file upload functionality.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the application validated file content and extension but stored the raw filename and rendered it into HTML without output encoding.
Impact
The injected script was stored server-side and executed whenever the file listing was accessed, so other users viewing that listing could be affected.
What the attacker needed
Valid account with upload access; ability to intercept requests
The fix
The filename should be sanitised and output-encoded wherever it is rendered, rather than trusted because the extension is valid.
How it was found
- Log in and open the file upload feature.
- Intercept the upload request with an interception proxy.
- Change only the filename value while keeping a valid extension and valid content.
- Forward the request to the server.
- View the file listing in the UI, where the filename is rendered and the script runs.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
When you upload a file, the site also saves its name. This site checked what was inside the file but trusted the name completely, and later put that name straight into the page. Because the name could contain code, the browser ran that code for anyone viewing the file list, which is called stored cross-site scripting.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.