fix: WPB-19708 validate binary content type instead of Content-Type#907
Open
cristianoliveira wants to merge 4 commits into
Conversation
https://wearezeta.atlassian.net/browse/WPB-19708 Fixes arbitrary file upload vulnerability (WPB-19708 / WRE-06-008) where the server trusted the client-provided Content-Type header to derive the stored file extension, allowing attackers to upload .exe/.html files. Changes: - Add detectBinaryExtension() using http.DetectContentType + magic bytes - Allowlist image-only MIME types (png, jpg, gif, webp, ico, svg) - Add size limit (5MB) for GLOBAL binary uploads - Apply EXIF stripping to GLOBAL uploads (parity with USER) - Validate extension on serve path (defense in depth) - Add 14 unit tests covering accept/reject cases
Why: - WPB-19708 showed the upload boundary still accepted risky cases after the initial content sniffing fix. - This path serves frontend binaries directly to browsers, so it must fail closed on malformed or active-content inputs. What changed: - remove SVG from the accepted upload types because SVG carries active content on an image endpoint - centralize extension -> Content-Type mapping instead of synthesizing image/<ext> - reject binaries with empty or unknown extensions on serve path - update tests to cover the stricter policy and MIME mapping Why this is a refactor: - keeps the security behavior explicit in small helper boundaries - removes implicit MIME construction - makes serving and validation share one source of truth Validation: - CGO_ENABLED=0 go test ./frontend/rest/...
dbc5cbb to
05cc800
Compare
Why: - keep frontend/rest tests closer to the common repo pattern - favor plain testing, table-driven cases, and named subtests for helper-level checks What changed: - add standard file header - replace grouped extension assertions with table-driven subtests - make binaryContentType checks use subtests too Validation: - CGO_ENABLED=0 go test ./frontend/rest/...
ghecquet
reviewed
Apr 23, 2026
| ) | ||
|
|
||
| // allowedBinaryTypes maps detected MIME types to file extensions for binary uploads. | ||
| var allowedBinaryTypes = map[string]string{ |
Member
There was a problem hiding this comment.
That might be a bit of a reductive list. Can you pls check with Tran to see if we have a list of supported content types somewhere ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
check for details: https://wearezeta.atlassian.net/browse/WPB-19708