security: force attachment or block active uploaded content (ai:gpt-5) #52

Closed
opened 2026-05-23 22:09:19 +02:00 by heiko · 0 comments
Owner

Finding from a whole-codebase security review.

Affected code:

  • cmd/once-server/upload.go:133 stores the client-provided multipart Content-Type for single-file uploads.
  • cmd/once-server/upload.go:154 stores a fixed application/zip type for generated archives.
  • cmd/once-server/download.go:90-95 returns the stored type and only adds Content-Disposition: attachment when the type does not start with text/.

Impact:
An authenticated uploader can upload active text content such as text/html and send the once link to another user. After the recipient confirms the POST download, the browser may render the response as same-origin HTML/JavaScript because the server deliberately omits Content-Disposition for text/*. For users who also have Basic-auth credentials cached for the same origin, that script can make same-origin authenticated requests.

Suggested fix:

  • Prefer Content-Disposition: attachment for all downloads, including text/*.
  • Add X-Content-Type-Options: nosniff.
  • Consider forcing application/octet-stream unless the type is server-detected and known safe.
  • If inline display is required, add a restrictive CSP such as sandbox/default-src none and block active content types explicitly.
  • Add tests for text/html uploads to assert they are not rendered inline as active same-origin content.
Finding from a whole-codebase security review. Affected code: - cmd/once-server/upload.go:133 stores the client-provided multipart `Content-Type` for single-file uploads. - cmd/once-server/upload.go:154 stores a fixed `application/zip` type for generated archives. - cmd/once-server/download.go:90-95 returns the stored type and only adds `Content-Disposition: attachment` when the type does not start with `text/`. Impact: An authenticated uploader can upload active text content such as `text/html` and send the once link to another user. After the recipient confirms the POST download, the browser may render the response as same-origin HTML/JavaScript because the server deliberately omits `Content-Disposition` for `text/*`. For users who also have Basic-auth credentials cached for the same origin, that script can make same-origin authenticated requests. Suggested fix: - Prefer `Content-Disposition: attachment` for all downloads, including `text/*`. - Add `X-Content-Type-Options: nosniff`. - Consider forcing `application/octet-stream` unless the type is server-detected and known safe. - If inline display is required, add a restrictive CSP such as sandbox/default-src none and block active content types explicitly. - Add tests for `text/html` uploads to assert they are not rendered inline as active same-origin content.
heiko closed this issue 2026-05-24 20:56:24 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
IUS/once#52
No description provided.