November 10, 2026
Stored XSS via File Upload: Smuggling JavaScript Inside a “Harmless” PDF
Finding a bug is great. Bypassing a strict PDF whitelist without breaking a single validation rule? That’s pure hacking dopamine.

By M0stafaX404
3 min read
This is that story. A modern recruitment portal had a résumé upload field locked down to "PDF only" — no exceptions. I didn't break that rule. I just found out it wasn't the rule I needed to break.
The Whitelist That Wouldn't Budge
The target had a job-application form with a résumé upload field. Nothing unusual — except this one actually enforced its "PDF only" rule properly.
I threw everything at it: renamed extensions, double extensions, null bytes, spoofed Content-Type headers. Every non-PDF attempt bounced off the same validation error. No cracks, no leniency.
Most people shrug and move on to the next endpoint here. I did too — for about five minutes. Then it hit me: I'd been attacking the wrong layer. The filter was watching the wrapper. Nobody was watching what was inside it.
Pivoting to Format-Level Abuse
Here's the paradox the whole bug hinges on: the file wasn't malicious to the validator at all. It was a 100% structurally valid PDF. Nothing to flag, nothing to spoof, nothing to sneak past.
The PDF specification allows more than people assume. Buried in the document catalog, a PDF can carry opening-action entries pointing directly to embedded JavaScript code that runs the moment the file is opened. That's not a hack; that's a built-in feature of the format.
So the question flipped: not "how do I sneak a non-PDF past this filter," but "how do I build a perfectly legal PDF that also happens to execute code when viewed." No spoofing required. Just the format, used exactly as designed, pointed somewhere nobody expected.
Building the Proof of Concept
I kept it simple. Instead of relying on complex exploitation frameworks, I used a straightforward approach to craft a valid carrier document and embedded a minimal proof-of-concept script (app.alert("XSS")) directly into its structural catalog.
The result? A file that looked, felt, and passed validation as a completely normal document, while quietly carrying an execution trigger for the moment it was opened.
Point it at the PDF, point it at the payload, and it spits out our weaponized carrier file (e.g., js_injected_test.pdf) — same visual document, now quietly wired to execute the moment it's opened.
Upload & Server Response
The crafted PDF went through the exact same upload flow as any other applicant's résumé. No error, no rejection, no sanitization step. Just a clean 200 OK:
HTTP
HTTP/1.1 200 OK
Content-Type: application/json
{
"success":true,
"message":"CV uploaded successfully",
"cv_path":"accountID_1794221240804_cv.pdf",
"filename":"accountID_1794221240804_cv.pdf",
"uploadDate":"2026-11-09T10:47:20.820Z"
}HTTP/1.1 200 OK
Content-Type: application/json
{
"success":true,
"message":"CV uploaded successfully",
"cv_path":"accountID_1794221240804_cv.pdf",
"filename":"accountID_1794221240804_cv.pdf",
"uploadDate":"2026-11-09T10:47:20.820Z"
}
From the server's point of view, this was a perfectly valid upload — because it was. Nothing in the validation path looked past "is this a well-formed PDF."
Execution Context: Why It Actually Fired
Getting the file accepted is only half the trick. The other half is how it gets opened. Two missing pieces turned "stored file with embedded script" into "script running in the app's own origin":
- No
Content-Disposition: attachmentheader: Without it, the browser defaults to rendering the file inline instead of forcing a download — so the PDF opened right in the browser, with no save prompt in the way. - No restrictive Content-Security-Policy (CSP): Nothing stopped the browser's built-in PDF viewer from executing the document's active content inside the page's own origin.
Opening the stored file triggered the payload instantly. Confirmed, reproducible Stored XSS — and the only "user interaction" required was opening a document they had every reason to trust.
Defensive Remediation
Fixing this isn't about finding better extension checks; it's about defense-in-depth across the asset's lifecycle:
- Sanitize PDFs server-side: Strip active content actions and embedded scripts before storage. Extension checks alone won't save you.
- Force the download: Serve uploads with
Content-Disposition: attachmentso the browser never auto-renders them inline. - Isolate uploaded content: Serve user-supplied files from a separate, cookieless static domain — if something does execute, there's nothing there to steal.
- Lock it down with a strict CSP on the file-serving path as a final line of defense.
Takeaway
"PDF only" is not the same promise as "safe." A whitelist that checks the wrapper and never looks inside is reading the label, not the contents of the box.
If your upload pipeline accepts complex document formats, assume they can carry executable content until proven otherwise. Sanitize. Isolate. Force the download. Then go find the next whitelist that's a little too proud of itself.
Reported responsibly through the program's disclosure process — and marked as Resolved on the exact same day within 24 hours.