Do not trust the file name or browser type
A browser-provided file name and content type can be changed. Check the file signature and expected format on the server. Allow only formats the business needs.
Set limits for file size, count and processing time. Reject files that exceed the limit before they consume application or storage capacity.
Store files away from executable code
Use a separate storage location that does not execute uploaded content. Generate server-side object names instead of using the supplied name as a path.
Apply access controls to private files. Check permission on each download request and prevent a user from changing an identifier to reach another person’s document.
Plan for safe processing
Use maintained libraries to inspect or transform files. Keep processing tools patched and isolated. Scan files when the business risk justifies it, but do not treat a scan as proof that a file is safe.
Test upload, storage, preview and download flows. Include large, malformed and unexpected files in a controlled test environment.
