Be the first to rate this article.
Processing...
# File Upload Handling taste of a backend engineer who treats every upload as untrusted - Upload large files directly from the browser to object storage with presigned URLs instead of streaming them through the app server. Confidence: 0.90 - Keep presigned upload URLs short-lived (minutes) and scoped to one object key, content type and maximum size. Confidence: 0.90 - Enforce a maximum file size on the server or storage policy, never only in client-side JavaScript. Confidence: 0.95 - Generate storage keys yourself (for example UUIDs under a tenant prefix); never use the user's filename as the path. Confidence: 0.95 - Store the original filename only as sanitized metadata in the database for display and download names. Confidence: 0.85 - Detect the file type from its magic bytes and check it against an allowlist; do not trust the extension or the Content-Type header. Confidence: 0.90 - Keep uploaded files in a private bucket and serve them through short-lived signed download URLs or an authorized proxy. Confidence: 0.90 - Serve user files from a separate domain with Content-Disposition: attachment for risky types so uploaded HTML or SVG cannot run on your origin. Confidence: 0.85 - Scan uploads for malware asynchronously and keep them in a quarantine state until the scan passes. Confidence: 0.80 - Track each upload as a database row with a status (pending, uploaded, scanned, ready, failed) instead of guessing from storage. Confidence: 0.85 - Confirm completion with a server callback or storage event before attaching the file to a record. Confidence: 0.80 - Use multipart or resumable uploads (S3 multipart, tus) for files over roughly 100 MB. Confidence: 0.75 - Re-encode images server-side, strip EXIF metadata including GPS, and generate fixed thumbnail sizes in a background job. Confidence: 0.85 - Reject or carefully sanitize SVG uploads; treat them as code, not images. Confidence: 0.85 - Store a checksum (SHA-256) for each file to detect corruption and deduplicate when it makes sense. Confidence: 0.70 - Set lifecycle rules that delete abandoned pending uploads and incomplete multipart parts after a day or two. Confidence: 0.85 - Delete files from storage when the owning record is deleted, through a background job that retries. Confidence: 0.80 - Rate-limit upload endpoints per user and per IP, and cap total storage per account. Confidence: 0.80 - Never unzip or parse archives and office documents in the request path; do it in a sandboxed worker with size and depth limits. Confidence: 0.85 - Show upload progress and allow cancel in the UI, with clear errors for wrong type or size. Confidence: 0.75 - Log upload metadata (user, key, size, type, status) but never the file content. Confidence: 0.85 - Test uploads with oversized files, renamed executables, polyglot files and filenames with path traversal characters. Confidence: 0.85
Comments & Questions (0)
No comments yet
Be the first to comment!