Skip to main content
In this lesson we cover auditing file handling (primarily uploads) and recommend secure defaults for any future upload functionality. The repository analyzed here does not currently implement file uploads; this guide shows how to audit upload code, common pitfalls to look for, and practical hardening steps to apply if uploads are added. All audit prompts referenced are available at https://github.com/JeremyMorgan/ClaudeCodeReviewingPrompts.
A dark-themed desktop with a browser window open to a GitHub repository showing a list of markdown files for code-review prompts. A code editor's file explorer and project files are visible in the background.

Audit objectives (high-level)

When reviewing file upload code, target the following objectives:
  • Use a whitelist for allowed file types (explicit allow list).
  • Enforce file size and file count limits.
  • Sanitize or generate safe filenames to prevent path traversal and unsafe characters.
  • Integrate anti-virus / content inspection in upload pipelines for hostile content.
  • Store uploads outside the webroot; serve them via a safe, controlled channel.
  • Prevent uploaded content from being executed.
  • Validate MIME types and verify file signatures (“magic numbers”) where feasible.
  • Inspect image and archive libraries for known vulnerabilities and pin versions.
  • Implement protections against archive-based attacks (ZIP bombs, tar bombs).

Example audit prompt

Use a consistent, structured prompt to guide a code auditor or automated review assistant. Here is an example you can adapt:
Maintain a repeatable audit checklist and require code locations (file/function/line ranges) for each finding to make remediation actionable. Prioritize fixes that reduce the largest attack surface first (whitelisting, size limits, and storage configuration).

Key concepts explained

Whitelisting vs. blacklisting

  • Whitelist: explicitly allow only known-safe types (e.g., JPEG, PNG, PDF). This is the recommended approach.
  • Blacklist: try to block known-bad types (e.g., .exe, .sh). Blacklists are error-prone and can miss novel threats.

Filename sanitization

  • Normalize filenames and remove path separators and control characters.
  • Consider generating server-side filenames (UUIDs) and storing the original name in metadata for display only.
  • Deny user-controlled paths when writing files.

Anti-virus / content inspection

  • Enterprise systems often route uploads through AV/IDS/IPS or content inspection services before storing or processing.
  • If you cannot scan at upload time, mark files as untrusted and delay processing until they are inspected.

ZIP bombs and archive attacks

  • A ZIP bomb is a small archive that expands into an extremely large set of files or a very large file, exhausting disk/memory.
  • Mitigations: limit decompressed size, limit recursion/levels, validate file types and sizes inside archives before extraction.

Example audit findings (for this repository)

  • The Express Login Demo application only handles JSON authentication requests and does not implement file uploads (no Multer, no express-fileupload, no multipart/form-data handling found).
  • Because there is no upload functionality present, the file-upload risk score for this codebase is 0/10 for this assessment.
  • A full audit report has been saved to /audits/FILE_UPLOAD_SECURITY_AUDIT.md with checklist results set to N/A where appropriate, and recommendations for secure implementation if uploads are added.
Here is a sample audit report you can use as a template:

Secure defaults: example in Express using Multer

If you add uploads to an Express application, start with strict defaults. Example Multer configuration:
Notes:
  • Client-provided MIME types and extensions can be spoofed. Always verify file signatures (“magic numbers”) server-side, especially for high-risk types.
  • For any image processing, limit dimensions and validate images before processing.
  • Consider scanning files with an anti-virus engine or sandboxing them before further processing.
  • Whitelist MIME types + extension + magic number verification.
  • Enforce file size and file count limits.
  • Store uploads outside webroot and deny execution.
  • Sanitize or generate server-side filenames.
  • Scan uploads for malware where possible.
  • Serve uploads from a separate domain/subdomain with strict headers (CSP, X-Content-Type-Options, X-Frame-Options).
  • Limit and pin versions of image manipulation libraries.
  • Validate archives before extraction; limit decompressed size and recursion depth.

Example checklist diff for this repository

If the application will accept uploads, start with strict whitelisting (MIME + extension + magic number), enforce size limits, store uploads outside the webroot, and treat every uploaded file as untrusted. These steps reduce the attack surface and make further defenses (AV scanning, sandboxing) more effective.
Summary
  • This repository currently contains no file upload functionality; therefore, the file-upload risk in this assessment is minimal (0/10).
  • If uploads are introduced, follow the checklist and secure Multer example above, and require an audit to validate the implementation and deployment configuration.

Watch Video