How to fix: File Upload Validated With filename.includes() Instead of Real Extension Check
An uploaded file's type is validated with filename.includes('.ext') or filename.indexOf('.ext') rather than checking the actual file extension or MIME type.
Why it matters
A filename like 'evil.jpg.exe' or 'shell.php.jpg' passes an includes()-based check while actually being executable content, letting an attacker upload a malicious file that a naive validator waves through.
This is a very common AI-generated validation shortcut: it looks correct against the obvious test case (a file literally named 'photo.jpg') but doesn't anchor the match to the actual extension position, so any filename that merely contains the substring passes.
How to fix it
- 1Extract the actual extension (the substring after the final '.') and compare it against an allowlist exactly.
- 2Validate the file's real content type via magic-byte/MIME sniffing, not just the filename.
- 3Store uploaded files outside the web root, or serve them with Content-Disposition: attachment and a randomized name.
Code examples
Validate the actual extension
const ALLOWED = new Set(['jpg', 'jpeg', 'png', 'gif']);
const ext = filename.split('.').pop()?.toLowerCase();
if (!ext || !ALLOWED.has(ext)) throw new Error('Invalid file type');References
Detected automatically by VulnRadar. The check id is vibe-weak-file-extension-check, stable across every scan so you can filter or diff on it.
More ai code checks
- LowGeneric Error Messages Leak No Context
- MediumTODO/FIXME Security Note in Response
- Higheval() Usage in Page Scripts
- HighSSL Certificate Verification Disabled
- HighMath.random() Used for Security Tokens
- CriticalHardcoded Credential in Authentication Logic
- CriticalJWT 'none' Algorithm Accepted
- CriticalSQL String Concatenation Pattern Detected
Questions
- How severe is File Upload Validated With filename.includes() Instead of Real Extension Check?
- VulnRadar rates this medium severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id vibe-weak-file-extension-check, which stays the same between runs so you can filter, diff, or gate CI on it.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.