Skip to content

Lesson 1 of 9 · 20m

The Upload Endpoint Is a Trust Boundary

Why uploads fail in production, what attackers control end-to-end, and the threat model you need before touching validation logic.

File upload bugs are rarely exotic. They are the predictable result of letting attacker-controlled bytes, attacker-controlled filenames, attacker-controlled metadata, and sometimes attacker-controlled content types cross into a system designed around trusting files. I have seen the same incident three times in different stacks: someone builds an avatar upload, validates the extension, stores it in the web root, and six months later a .jpg that is actually PHP is executing as www-data.

Everything about the upload is hostile

In a multipart request, the client controls more than most developers remember:

POST /api/profile/avatar HTTP/1.1
Content-Type: multipart/form-data; boundary=----formdata

------formdata
Content-Disposition: form-data; name="avatar"; filename="../../shell.php"
Content-Type: image/jpeg

<attacker-controlled bytes>
------formdata--

The attacker chooses the bytes, filename, declared MIME type, ordering of form fields, number of parts, compression behavior, chunking, and timing. If your pipeline trusts any of those without verification, that is the exploit primitive.

The failure modes that matter

Upload vulnerabilities usually chain one or more of these:

  • Execution: file lands somewhere the application server or another interpreter will execute it.
  • Interpretation mismatch: browser, server, proxy, image library, and antivirus disagree about what the file is.
  • Write primitive abuse: attacker controls path, overwrite target, symlink behavior, or archive extraction layout.
  • Resource exhaustion: huge files, decompression bombs, expensive parser inputs, or thousands of tiny uploads.
  • Secondary abuse: stored content is later rendered for users, moderators, or admins.

Threat model first, code second

Before implementation, answer five questions:

  1. Who may upload, and how large can a legitimate file be?
  2. What formats are business-required rather than merely nice to support?
  3. Where will files live, and can that location ever execute, render inline, or overwrite application files?
  4. Which downstream systems parse the file — browsers, workers, image processors, antivirus, indexing, backups?
  5. What is the maximum damage if validation is bypassed?

If the answer to the last one is "full RCE," your design is wrong even if validation is perfect, because validation never stays perfect.

Field notes

  • An upload feature is never "just a form field." It is a hostile file ingestion pipeline.
  • The client-supplied MIME type is a claim, not evidence.
  • Threat model the moderators and admins too; reviewer dashboards are favorite targets for stored attack payloads.

Was this lesson helpful?

Sign in to rate