- by x32x01 ||
File upload features are one of the most dangerous parts of any web application.
A small validation mistake can turn into a full server compromise 💀
In this guide, you’ll learn how attackers bypass upload restrictions using the Content-Type header, why it works, and how to properly secure your app.
For example:
A website only allows image uploads (JPG, PNG)…
But the attacker uploads a PHP file instead 👇
👉 If successful, this can lead to Remote Code Execution (RCE).
The server rejects it - clearly not an image.
💥 The file gets uploaded successfully!
Even though it’s not a real image.
👉 This means the server is trusting the MIME type instead of validating the actual file content.
💡 Result:
The system generates a strange extension like:
This shows the backend is parsing MIME types incorrectly, which opens the door for bypasses.
💥 The attacker bypasses the extension filter and uploads a PHP file successfully.
Example (PHP):
This prevents filename-based attacks.
You’re already vulnerable.
Attackers don’t need complex exploits…
Just one weak validation point.
If you rely on Content-Type or file extension alone, you’re leaving the door wide open.
🔐 Always:
A small validation mistake can turn into a full server compromise 💀
In this guide, you’ll learn how attackers bypass upload restrictions using the Content-Type header, why it works, and how to properly secure your app.
What is File Upload Bypass? 🧠
File Upload Bypass is when an attacker tricks a system into accepting a malicious file - even when restrictions are in place.For example:
A website only allows image uploads (JPG, PNG)…
But the attacker uploads a PHP file instead 👇
👉 If successful, this can lead to Remote Code Execution (RCE).
Real Attack Scenario ⚙️
Let’s break down a real-world example:🎯 Target:
The server only allows image uploads.❌ Blocked Attempt:
Code:
Content-Type: application/html ✅ Successful Attempt:
Code:
Content-Type: application/jpeg Even though it’s not a real image.
👉 This means the server is trusting the MIME type instead of validating the actual file content.
The Core Vulnerability 🔍
The main issue is simple:👉 The server trusts Content-Type header
👉 It does NOT verify real file content (magic bytes)
This is a very common and dangerous mistake.👉 It does NOT verify real file content (magic bytes)
Advanced MIME Parsing Trick ⚠️
Sometimes, things get even worse due to poor parsing logic: Code:
Content-Type: application/text php/jpeg The system generates a strange extension like:
.txtphpThis shows the backend is parsing MIME types incorrectly, which opens the door for bypasses.
Final Bypass Technique 🔥
By using a crafted header like: Code:
Content-Type: application/ php/jpeg Why This is Dangerous 💣
If the environment is not properly secured, this can lead to:- Remote Code Execution (RCE) ⚠️
- Web shell uploads
- Full server takeover
- Sensitive data exposure
Why Developers Miss This 🧨
These vulnerabilities often exist because of:- Trusting Content-Type headers
- No validation of file content
- Weak extension filtering
- Poor MIME parsing logic
How to Prevent File Upload Bypass 🛡️
1. Validate File Content (Magic Bytes)
Never rely on extensions or headers alone.Example (PHP):
PHP:
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['file']['tmp_name']); 2. Use a Strict Allowlist
Only allow specific types:image/jpegimage/png
3. Never Trust Content-Type
👉 This header can be easily manipulated by attackers.4. Store Files Safely
- Use separate storage (not executable)
- Avoid storing uploads inside web root
5. Rename Uploaded Files
PHP:
$newName = uniqid() . '.jpg'; 6. Disable Script Execution
Example (Apache): Code:
php_flag engine off Pro Tip for Developers 💡
👉 If your upload system only checks file extension or Content-Type…You’re already vulnerable.
Final Thoughts 🎯
File Upload Bypass isn’t a minor issue - it’s a critical security risk.Attackers don’t need complex exploits…
Just one weak validation point.
If you rely on Content-Type or file extension alone, you’re leaving the door wide open.
🔐 Always:
- Validate content
- Restrict file types
- Isolate uploads