Case F43527 · Web AppSec · L3 Applied
Securing File Uploads
Interview questionYou are reviewing a feature that lets users upload profile pictures and documents. What could go wrong, and how would you secure it?
- 01 Answer
- 02 Example
- 03 Trade-offs
What a strong answer covers
Try it out loud first. Then check yourself:
- Risks: web shell execution, stored XSS via SVG or HTML, path traversal in filenames, parser exploits, zip bombs, malware hosting
- Allowlist extensions and verify content (magic bytes, then re-encode images); do not trust Content-Type from the client
- Rename to random IDs, store outside the web root or in object storage, and serve from a separate cookieless domain
- Serve with Content-Disposition: attachment where possible and X-Content-Type-Options: nosniff; enforce size limits
- Trade-off: AV scanning and sandboxed conversion add latency and cost but matter for files other users or staff open
If the interviewer pushes back
- Why is checking the extension against .php not enough on an Apache or IIS server?