How a Loose Regex in a File Upload Component Led to a $12,000 Rem
The file upload component validated filenames with an unanchored regular expression that only checked whether '.pdf' appeared anywhere in the name, so a file named with a double extension was accepted. Because the server kept the original filename and stored it in a web-accessible directory where PHP was executed, the attacker could run system commands on the server.
If you ask any bug hunter what their holy grail vulnerability is, the answer is almost always the same: Remote Code Execution (RCE). It is the ultimate exploit — gaining the ability to run arbitrary system commands directly on a target’s backend server.
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
The file-extension check used an unanchored regular expression, so any filename containing '.pdf' passed, and the server then executed the file based on its final extension.
Impact
An attacker could execute arbitrary system commands on the document-handling server, and the report shows this was demonstrated with basic commands.
What the attacker needed
Ability to upload a file; server executes uploaded files
The fix
The regex was fixed to require the filename to end with '.pdf', and script execution was disabled in the static storage bucket.
How it was found
- Intercept the document upload request and observe that only PDF files are accepted.
- Try common bypasses such as changing the content type, adding PDF magic bytes, and null byte injection, all of which are blocked.
- Guess that the server uses an unanchored regex and rename the malicious script to include '.pdf' in the middle of the filename.
- Upload the renamed file and see it accepted with a URL in a web-accessible directory.
- Request the uploaded file with a command parameter and observe command output.
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 regular expression is a pattern used to check text. The developer wrote a pattern that only asked 'does the name contain .pdf somewhere?' instead of 'does the name end with .pdf?'. That let the attacker upload a file that was really a program, and the server ran it.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.