Most upload handlers ask the uploaded file three questions: what's your name, what type are you, and what do your first few bytes look like? Then they believe the answers.
All three answers come from the client. The filename is a string in the request. The Content-Type is a string in the request. The bytes are, obviously, whatever was sent. A check built on any one of them is a check the sender gets to fill in.
This post is the developer side of file upload bugs: four checks that look fine in code review, what gets past each one, a small upload function where the server decides everything that matters, and a test suite that goes red on the old code and green on the new. Everything runs locally with harmless stand-in files (one line of HTML, nothing executable). Only test systems you own or are authorized to test.
What the bug is
PortSwigger describes file upload vulnerabilities as a server accepting files without properly validating things like their name, type, contents or size.β¦