Context
A security fix stopped trusting the client-declared Content-Type of image uploads. Instead it read the file signature and rejected anything that wasn’t PNG or JPEG. It looked safe. Its evidence came only from the declared type of stored blobs, which were all application/octet-stream, and that says nothing about the actual bytes.
Insight
Reading the first 16 bytes of the newest stored blobs showed what the clients actually send. The current mobile client had switched to a proprietary raw capture format, with a custom ASCII magic and a fixed size, while older uploads were PNG. The new check would have rejected every upload from the current client with a 400.
Before tightening upload validation, range-read the headers of real stored objects.
az storage blob download --account-name <account> -c <container> -n <blob> \ --auth-mode login --start-range 0 --end-range 15 -f head.binxxd head.binSample the newest objects, not random ones: formats change with client releases.
Policy that came out of it
- Raw/capture image types: accept any bytes, but store and serve them as
application/octet-streamwithContent-Disposition: attachment, so they never render. - Display image types: must be PNG or JPEG by signature.
- Ignore the declared part type. The bytes alone decide, so
image/jpg,image/pjpegor a missing type don’t reject valid files. - Type served responses from the bytes, not the stored type. Legacy blobs stored with the wrong type then come back correctly.
- Check existence (404) and duplicates (409) before format (400), so clients retrying an upload that was stored before the change still get the response they treat as done.