Almost every application that accepts file uploads validates them roughly like this: collect the allowed types, compare the uploaded file's type against the list, reject anything that does not match. It reads as reasonable, it passes review, and it checks nothing.
The reason is where that type comes from. The browser reports it, and the browser derives it from the file extension. Rename an executable to report.pdf and the browser announces it as application/pdf, because from the browser's point of view that is simply what the file is called. The allowlist compares a string the attacker chose against a list of strings you chose, and finds them equal.
Check the bytes, not the label
Real file formats identify themselves in their first few bytes. A PDF opens with the characters %PDF. A PNG opens with a fixed eight-byte sequence. JPEG has its own marker, and every modern Office document is a ZIP archive underneath, so it starts with PK.
Reading those leading bytes and comparing them against the declared type catches the rename immediately, and it costs nothing if you are already streaming the file to hash it. It also produces a far better error. "That file type is not accepted" tells a user nothing they can act on. "This file is not the type it claims to be, it looks like a Windows executable" tells them exactly what happened, and on the rare occasion it is a false alarm, tells them what to check.
Never trust the client's account of the upload
There is a second, subtler version of the same mistake. Modern uploads usually go directly from the browser to object storage using a pre-signed URL, which is the right architecture, the file never passes through your application and never meets a request size limit. The browser then calls back to say it finished.
The trap is believing anything in that callback. The size, the type, the hash, even the fact that an upload happened at all are claims from a client you do not control. Every one of them has to be re-read from the storage object itself before it is trusted, and the storage key has to be checked against the prefix you issued, or a caller can attach somebody else's file by guessing its key.
Hashing the stored bytes yourself is worth the read for a second reason beyond validation: it is what makes the evidence tamper-evident. An auditor handed the file a year later can hash it and compare, and that comparison is only meaningful if the hash was computed from what the storage actually holds rather than from what a browser said it uploaded.
What none of this catches
This is the part usually left out of the security page, so here it is plainly. Signature checking proves a file is the kind of thing it claims to be. It says nothing whatsoever about what is inside it.
A genuine, well-formed PDF carrying an exploit passes every check described above, because it really is a PDF. Only a scanning engine catches that, and calling signature validation "malware protection" in your documentation is the kind of claim that survives right up until the first customer security questionnaire asks a follow-up question.
A cheap intermediate step is worth knowing about. If you are already computing a cryptographic hash of the stored file, you can look that hash up against a threat-intelligence service without sending the file anywhere. Only the hash leaves your infrastructure, which means no third-party processing of customer content to disclose and no data-residency question to answer. Known-bad files get rejected; files nobody has seen before pass. That is a real improvement and it is emphatically not a scanner, and the honest thing is to describe it as exactly that.
Two rules for the screening itself
- Fail open, and record why. A threat-intelligence outage must not stop somebody recording evidence against a deadline. But log the outcome, so that years later you can tell "screened and clean" apart from "never screened because no key was configured".
- Use a threshold, not a single detection. Obscure engines produce false positives on ordinary business documents often enough that a one-detection rule will reject real policies, and a check that cries wolf gets switched off within a week.
Where this leaves you
Validate the bytes, not the label. Re-read everything from storage rather than believing the client. Hash what you stored. Screen against known-bad if you can do it without shipping customer files to a third party. And then write down, in the documentation a customer will actually read, that uploads are validated and screened but not content-scanned, because the gap between what your upload path does and what your security page implies it does is itself a finding.