File upload features—such as profile avatars, invoice attachments, CSV imports, and support tickets—accept arbitrary byte streams from external users. When an application trusts client-supplied filenames, MIME headers, or serves uploaded files back from its own web origin, file uploads can lead directly to stored XSS, path overwrite, or server-side code execution.
Four file upload attack vectors to test
During a web application security assessment, testers evaluate how the upload handler validates, stores, processes, and serves files across four risk areas:
- Executable script and webshell uploads: uploading `.php`, `.jsp`, `.aspx`, or `.py` files into a directory inside the web root where the HTTP server executes scripts instead of serving static bytes.
- Path traversal in filenames: supplying a multipart filename such as `../../../var/www/app/config.json` when the backend concatenates `file.originalname` directly into a filesystem write path.
- Stored XSS via SVG, HTML, or XML files: an `.svg` image is an XML document that can contain executable `<script>` blocks and `onload` handlers; if served inline with `Content-Type: image/svg+xml` from the main domain, the script runs in the viewer's origin.
- Parser and image-processor vulnerabilities: malformed archives (Zip Slip path traversal, decompression bombs) or crafted image metadata processed by outdated native image libraries.
How to architect a safe file upload pipeline
Never use the user-supplied filename on disk or in object-storage keys; generate a random UUID key and store the sanitized display name separately in database metadata. Validate the file's actual magic bytes (file signature) and re-encode raster images (PNG, JPEG, WebP) rather than trusting the `Content-Type` header sent by the browser.
Store uploaded blobs in an isolated cloud object storage bucket (such as S3 or R2) outside the application server's filesystem, and serve downloads from a separate, cookieless static domain with `Content-Disposition: attachment`, `X-Content-Type-Options: nosniff`, and a restrictive `Content-Security-Policy: sandbox` header.
Generate random storage keys, verify file magic bytes, store uploads outside the web root, and serve downloads from an isolated cookieless domain.