Bypassing File Upload Restrictions To Exploit Client-Side Path Traversal
The write-up shows how file upload checks that only look for a PDF signature or a valid PDF structure can be fooled by embedding PDF markers inside a JSON object. An attacker could then upload a JSON file that passes as a PDF but is still parsed as JSON in the browser, enabling client-side path traversal and CSRF.
blog.doyensec.com
Published on blog.doyensec.com
In my previous blog post, I demonstrated how a JSON file could be used as a gadget for Client-Side Path Traversal (CSPT) to perform Cross-Site Request Forgery (CSRF). That example was straightforward because no file upload restriction was enforced.
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 upload validation only checks for a PDF signature or a loose PDF structure rather than the actual file type, so a JSON document containing PDF markers is accepted.
Impact
An attacker could upload a file that passes PDF validation but is still valid JSON, enabling client-side path traversal and CSRF; the text notes the crafted PDF will not render in recent viewers.
What the attacker needed
File upload feature; front-end parses uploaded file as JSON; victim visits attacker page
How it was found
- Craft a JSON object that contains a PDF header within its first 1024 bytes.
- Upload the file so the mmmagic check sees it as a PDF.
- For stricter PDF parsers, replace line feeds between PDF objects with spaces so the file is still valid JSON.
- Have the front-end parse the uploaded file with JSON.parse so the traversal payload is used.
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.
Some websites let you upload files but check the file type first, for example by looking for a PDF marker. This post shows that you can hide that marker inside a JSON file, so the check passes while the browser still reads the file as JSON. That lets an attacker use the uploaded file to make the victim's browser send requests the victim did not intend.
What is CSRF?
Another site makes a signed-in user's browser perform an action they did not intend.