Skip to content

fix: WPB-19708 validate binary content type instead of Content-Type#907

Open
cristianoliveira wants to merge 4 commits into
v5-devfrom
WPB-19708-pydio-cells-lack-of-validation-on-upload-file-type-wre-06-008-wp-1-low-info
Open

fix: WPB-19708 validate binary content type instead of Content-Type#907
cristianoliveira wants to merge 4 commits into
v5-devfrom
WPB-19708-pydio-cells-lack-of-validation-on-upload-file-type-wre-06-008-wp-1-low-info

Conversation

@cristianoliveira
Copy link
Copy Markdown
Contributor

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/...
@cristianoliveira cristianoliveira force-pushed the WPB-19708-pydio-cells-lack-of-validation-on-upload-file-type-wre-06-008-wp-1-low-info branch from dbc5cbb to 05cc800 Compare April 21, 2026 09:19
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/...
@cristianoliveira cristianoliveira marked this pull request as ready for review April 21, 2026 10:45
)

// allowedBinaryTypes maps detected MIME types to file extensions for binary uploads.
var allowedBinaryTypes = map[string]string{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants