Treat every uploaded file as untrusted input. Upload flow with object storage (Amazon S3, Azure Blob Storage or MinIO) 1. React asks the backend for an upload slot: POST /api/uploads with file name, size and type. 2. Spring Boot checks authorization and quotas, validates the declared size and extension against an allow-list, generates a random object key (UUID-based path with no user-supplied name), and returns a short-lived pre-signed PUT URL (S3Presigner, or an Azure SAS) restricted to that key, content type and size where the storage supports it. 3. The browser uploads directly to storage (with progress, and multipart upload for large files), so large files do not pass through the application servers. 4. The client calls POST /api/uploads/{id}/complete, or a storage event notifies the backend. Server-side validation after upload - Check the real file type with magic bytes (Apache Tika) rather than trusting the extension or Content-Type. - Enforce size limits; reject archives with excessive compression ratios (zip bombs). - For images, re-encode them (strip metadata and malformed payloads) and generate thumbnails. - Scan for malware: a quarantine bucket triggers a scanner (ClamAV container, Amazon GuardDuty Malware Protection for S3, Microsoft Defender for Storage). Only clean files move to the permanent bucket or are marked available. If uploading through Spring Boot directly - Configure spring.servlet.multipart.max-file-size and max-request-size; stream to storage instead of buffering whole files in memory; never write to paths built from the original file name (path traversal). Storage security - Private buckets only, encryption at rest, and versioning or lifecycle rules. - Downloads through authorized endpoints or short-lived pre-signed GET URLs, with Content-Disposition: attachment and X-Content-Type-Options: nosniff; serve user content from a separate domain to prevent stored XSS via HTML or SVG files. React side - accept attribute and client-side size checks for user experience only; progress and error states; accessible file input with clear messages. Data model and audit - Store metadata (owner, tenant, original name escaped, size, checksum, scan status) in the database; log uploads and downloads; apply per-user rate limits and quotas.
Ravindra Wadile · · 0 likes