Validate an upload on the server as well as the screen
Client checks help the user, but a caller can bypass the interface. A renamed extension does not prove the actual file content.
Start here
This example uses the sample details below. Replace them with your own facts before applying the instructions.
- Image input offers allowed formats and a file-size limit.
Start with the facts
Image input offers allowed formats and a file-size limit. Keep a small reproducible example and the expected behavior. Remove secrets from the code or error message before requesting help.
Spot the problem
The wording or action to avoid is: “Trust the browser filename and skip server checks.” Client checks help the user, but a caller can bypass the interface. A renamed extension does not prove the actual file content.
Make the correction
Validate size, supported type and actual content at the backend before processing the upload.
Check before using the result
Test an oversized file, unsupported content and a valid sample; verify rejected inputs do not proceed to processing.
Worked example and reusable input
Use the stated inputs to reproduce checked local outputs. Replace sample facts when applying a brief to your own work.
TASK Validate an upload on the server as well as the screen SAMPLE INPUT — replace with your actual facts Image input offers allowed formats and a file-size limit. AVOID Trust the browser filename and skip server checks. CORRECTED APPROACH Validate size, supported type and actual content at the backend before processing the upload. ACCEPTANCE CHECK Test an oversized file, unsupported content and a valid sample; verify rejected inputs do not proceed to processing.
Key takeaways
- Client checks help the user, but a caller can bypass the interface. A renamed extension does not prove the actual file content.
- Test an oversized file, unsupported content and a valid sample; verify rejected inputs do not proceed to processing.