You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: enforce mimeTypes restriction when useTempFiles is enabled (#16255)
This replaces #16236 which was auto-closed when the fork was deleted.
# Overview
Fixes MIME type validation being skipped on upload collections when
`upload.useTempFiles: true` is set globally.
## Key Changes
- Use `fileTypeFromFile` for temp files instead of loading the full
buffer — avoids reading large files (e.g. 2GB video) into memory just
for MIME detection
- Removed the `!useTempFiles` gate that was causing the entire fallback
validation block to be skipped
- Added `tempFilePath` to the `File` type directly instead of
intersecting it at the call site
- Full file content is loaded lazily via `getFileBuffer()` and only when
needed for SVG/PDF content validation
## Design Decisions
The original code used the `useTempFiles` config flag to decide whether
to run fallback validation, but checking `tempFilePath` directly is more
accurate, files uploaded via the local API always have `file.data`
populated even when `useTempFiles` is enabled.
Simply removing the gate (as originally suggested) would've fixed the
extension check but left `validateSvg` broken, since it would still run
on an empty buffer and always return safe.
Fixes#16233.
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Patrik Kozak <35232443+PatrikKozak@users.noreply.github.com>
Co-authored-by: Paul Popus <paul@payloadcms.com>
0 commit comments