mediumCWE-400A05:2021

No File Size Limit

File upload endpoints without size limits allow attackers to exhaust disk space, memory, and CPU with multi-gigabyte uploads.

How It Works

Without a file size limit, an attacker can upload a 10GB file to your storage bucket, fill up your /tmp directory, or OOM crash your server by loading the file into memory for processing. Even without malicious intent, a user uploading a raw 4K video to a profile picture endpoint causes the same problem.

Vulnerable Code
// BAD: no file size limit — attacker uploads 10GB files
export const config = { api: { bodyParser: false } };

export default async function handler(req, res) {
  const form = new IncomingForm(); // no maxFileSize set
  const [fields, files] = await form.parse(req);
  await uploadToStorage(files.upload[0]);
}
Secure Code
// GOOD: enforce file size limit before processing
export const config = { api: { bodyParser: false } };

export default async function handler(req, res) {
  const form = new IncomingForm({
    maxFileSize: 5 * 1024 * 1024, // 5MB limit
    maxFiles: 1
  });
  const [fields, files] = await form.parse(req);
  await uploadToStorage(files.upload[0]);
}

Real-World Example

Multiple production servers have been taken offline by file upload DoS attacks where the attacker uploaded multi-GB files that filled the container's writable layer or exhausted Node.js heap memory during image processing.

How to Prevent It

  • Set maxFileSize to the minimum necessary for your use case (5MB for profile photos, 50MB for documents)
  • Validate file size both on the client side (for UX) and on the server side (for security)
  • Also set a maximum number of files per upload request
  • Use cloud storage direct upload (Supabase Storage, S3 presigned URLs) where possible — the file never touches your server

Affected Technologies

Node.js

Data Hogo detects this vulnerability automatically.

Scan Your Repo Free

Related Vulnerabilities