Step 6
Step 6 — Validate uploads and publish them atomically
0 views
Step 6 — Validate uploads and publish them atomically
Filename and Content-Type are claims from the client. A public file needs byte, size, extension, and integrity checks before it enters the public directory.
- Check an allowlisted MIME and maximum size.
- Verify the actual PNG/JPEG/WebP/GIF/AVIF signature.
- Write an exclusive random temporary file in the same directory, then atomically
renameit. - Record SHA-256 and a bounded audit detail, not the file or sensitive values.
- Keep private user files separate from public mounts; quarantine invalid files for later cleanup.
Codingstairs Admin cover assets preserve their original public format but use MIME/signature checks and atomic rename. Pryzeet user images have a separate sharp/private-storage pipeline. Sharing one helper would blur visibility and deletion ownership.
The error should state supported formats, size limits, and how to select another file. Rejecting before the public write prevents partial files and stale cache surprises.