Persistent XSS via Document Upload
The application only checked file type on the client side, so an attacker could upload an HTML file containing JavaScript instead of a PDF. When the uploaded file was later viewed, the script ran in the victim's browser, allowing persistent cross-site scripting.
medium.com
Published on medium.com
During a security assessment of an authentication web application, I identified a Persistent Cross-Site Scripting (XSS) vulnerability in the document upload functionality. The application was designed to accept only .pdf files; however, this restriction was enforced solely on the client side.
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 server trusted the client-supplied file extension and Content-Type without validating the actual file content or enforcing server-side restrictions.
Impact
An attacker could store malicious JavaScript that executes in a victim's browser when the uploaded document is accessed, potentially leading to session hijacking or other client-side attacks.
What the attacker needed
Ability to intercept and modify upload requests; victim accesses the uploaded document
The fix
The application should enforce strict server-side validation of file type and content, such as checking the actual file signature and serving uploaded files with a safe Content-Type or from a separate domain.
How it was found
- Intercept the upload request using a proxy tool.
- Change the filename from .pdf to .html.
- Change the Content-Type header from application/pdf to text/html.
- Replace the file body with a JavaScript payload.
- Forward the request; the server accepts and stores the file.
- Access the uploaded document to trigger script execution.
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.
A website let people upload documents but only checked the file type in the browser, not on the server. An attacker could change the file to an HTML page with a script and upload it. When someone later opened that file, the script ran in their browser, which is called cross-site scripting (XSS).
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.