security: enforce upload size limits (ai:gpt-5) #48

Closed
opened 2026-05-23 21:23:01 +02:00 by heiko · 0 comments
Owner

Finding from a whole-codebase security review.

Affected code:

  • cmd/once-server/upload.go:113-144 parses the multipart form and copies a single uploaded file without a byte limit.
  • cmd/once-server/upload.go:163-183 copies each selected file into a generated zip without per-file or aggregate limits.

Impact:
r.ParseMultipartForm(2 << 20) only controls how much multipart data stays in memory. The request body and copied file content are otherwise unbounded, so an authenticated user, compromised credentials, or an automated client can fill disk and consume CPU by streaming large uploads or large multi-file zip uploads. Partial failures also leave cleanup-dependent store entries.

Suggested fix:

  • Add explicit config for maximum upload bytes, maximum file count, and optionally maximum zip aggregate size.
  • Wrap r.Body with http.MaxBytesReader in Upload before parsing.
  • Use limited copy helpers for both direct file writes and zip entries, return HTTP 413 when exceeded, and purge the partially-created store entry on failure.
  • Add tests covering oversized single-file and multi-file uploads.
Finding from a whole-codebase security review. Affected code: - cmd/once-server/upload.go:113-144 parses the multipart form and copies a single uploaded file without a byte limit. - cmd/once-server/upload.go:163-183 copies each selected file into a generated zip without per-file or aggregate limits. Impact: `r.ParseMultipartForm(2 << 20)` only controls how much multipart data stays in memory. The request body and copied file content are otherwise unbounded, so an authenticated user, compromised credentials, or an automated client can fill disk and consume CPU by streaming large uploads or large multi-file zip uploads. Partial failures also leave cleanup-dependent store entries. Suggested fix: - Add explicit config for maximum upload bytes, maximum file count, and optionally maximum zip aggregate size. - Wrap `r.Body` with `http.MaxBytesReader` in `Upload` before parsing. - Use limited copy helpers for both direct file writes and zip entries, return HTTP 413 when exceeded, and purge the partially-created store entry on failure. - Add tests covering oversized single-file and multi-file uploads.
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#48
No description provided.