security: sanitize filenames used in multi-file zip uploads (ai:gpt-5) #51

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

Finding from a whole-codebase security review.

Affected code:

  • cmd/once-server/upload.go:163-181 creates zip entries from filepath.Join(basename, f.Filename).

Impact:
Multipart filenames are client-controlled. A filename containing path traversal, an absolute path, or platform-specific separators can become a dangerous zip entry name. Recipients who extract the generated archive with vulnerable tooling may write files outside the intended extraction directory. Single-file uploads use filepath.Base; the multi-file zip path does not.

Suggested fix:

  • Sanitize each zip entry name before zipW.CreateHeader.
  • Use portable slash-separated zip names, reject absolute paths, drive letters, empty names, and any . or .. segment.
  • Consider flattening to filepath.Base unless preserving directories is an explicit feature.
  • Add tests with filenames like ../secret, /tmp/secret, a/../../secret, and Windows-style paths.
Finding from a whole-codebase security review. Affected code: - cmd/once-server/upload.go:163-181 creates zip entries from `filepath.Join(basename, f.Filename)`. Impact: Multipart filenames are client-controlled. A filename containing path traversal, an absolute path, or platform-specific separators can become a dangerous zip entry name. Recipients who extract the generated archive with vulnerable tooling may write files outside the intended extraction directory. Single-file uploads use `filepath.Base`; the multi-file zip path does not. Suggested fix: - Sanitize each zip entry name before `zipW.CreateHeader`. - Use portable slash-separated zip names, reject absolute paths, drive letters, empty names, and any `.` or `..` segment. - Consider flattening to `filepath.Base` unless preserving directories is an explicit feature. - Add tests with filenames like `../secret`, `/tmp/secret`, `a/../../secret`, and Windows-style paths.
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#51
No description provided.