Skip to content

Lesson 3 of 9 · 18m

Validation That Fails in the Real World

Client-side checks, blacklist traps, size bypasses, race conditions, and the validation mistakes attackers rely on.

Most upload validation is performative: a little JavaScript in the browser, an extension check on the server, maybe a MIME comparison. Attackers do not need zero-days against that. They need a proxy, patience, and one inconsistency between what the developer meant and what the code actually verifies.

Client-side validation is UX, not security

<input type="file" accept="image/png,image/jpeg" max="1">

That helps honest users choose the right file. It does nothing against anyone using curl, Burp, or a handcrafted multipart body. Repeat all validation server-side, in one place, as close to ingestion as possible.

Blacklists fail in boring ways

Typical bad logic:

if filename.endswith(".php"):
    reject()

Attackers try .php5, .phtml, .phar, .pht, uppercase variants, trailing whitespace, trailing dots on Windows, null-byte tricks in legacy runtimes, alternate data streams on Windows, and framework-specific executable formats. If the file lands in a directory processed by more than one technology, the blast radius grows.

Allowlists are better, but still weak if they inspect only names. Enforce all of these together:

  • maximum size before full buffering;
  • exact detected type;
  • extension generated by the server, not copied from the client;
  • safe filename charset;
  • canonical path checks;
  • parser-level validation.

Race conditions around temporary files

A classic pattern: write to a temporary location, scan, then move if clean. If the temporary path is web-accessible, predictable, or attacker-influenced, there is a race window. Even milliseconds are enough under automation.

Safer design:

receive stream → spool outside web root → scan/validate → atomic move into immutable object storage

Use unpredictable IDs, restrictive permissions, and directories inaccessible to the web server.

Validation is not one event

Validation happens at several layers: request size limits, type checks, structural parsing, content scanning, business rules, and post-processing. The mistake is treating one successful check as final judgment. Attackers exploit the gaps between checks, especially when one component mutates the file and another component later serves the original.

Field notes

  • Validate early for resource use, deeply for structure, and again after transformation if the transformed object is what users receive.
  • Error messages should not reveal internal paths, scanner names, or framework versions.
  • Log rejection reasons with request IDs; you will need them when bypass attempts start.

Was this lesson helpful?

Sign in to rate