Skip to content

fix: harden chat workspace file upload input validation - #30184

Merged
ibetitsmike merged 3 commits into
mainfrom
mike/chat-upload-input-validation
Oct 27, 2026
Merged

ibetitsmike merged 3 commits into
mainfrom
mike/chat-upload-input-validation

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Hardens the chat workspace-file upload surface (POST /api/v2/chats/{chat}/workspace-files and the workspace-file-reference message parts that point at its uploads) against direct API and SDK callers. These are follow-ups from a security review of the upload stack.

  • Filenames: chatfiles.SanitizeWorkspaceUploadName now also replaces ( ) [ ] { } ' ` ; , & # $. Together with its existing basename step, it covers the frontend sanitizeChatFileName set, so a$(b);c'd.txt is stored as a_b_c_d.txt. A provided name that has nothing usable left ($(), CON.txt) now gets "Filename is unusable." instead of the missing-header error.
  • Media types: a non-empty workspace_file_media_type must be a parseable type/subtype of at most 255 bytes with no control characters (new chatfiles.ParseBaseMediaType), and the parsed base type is what gets persisted. The upload endpoint falls back to application/octet-stream for an empty or invalid Content-Type, so the media_type it returns always passes message validation.
  • Rate limit: the upload route now uses the new httpmw.RateLimitPerCaller, which ignores the request path. The files budget (12 per minute by default) is therefore per user across all chats, instead of per chat ID or UUID spelling. Owner bypass and IP fallback match httpmw.RateLimit.

Parts saved earlier through direct API calls with names or media types that are now rejected fail validation if resent through the edit path. The UI never produced such values, so there is no migration. The only frontend change is a JSDoc correction.

Validation

  • Targeted Go tests for coderd/x/chatfiles, coderd/httpmw, agent/agentfiles, and the coderd workspace-file tests. Each new assertion fails with its production change reverted.
  • Remote dogfood UAT through Coder Agents passed on ca88295f44b and again on 7a8c8bb795a: unsafe names over the API, media-type rejects and accepts, the Content-Type fallback, 429 after 12 uploads across two chats, and a UI .zip upload that renders its workspace file chip. The head adds only the JSDoc edit (6335f5d491f), which UAT did not exercise.

Review record

  • coder-frontend-review (8 roles) on the site diff: CD4 and CD5 flagged the JSDoc for listing server rules. Fixed, and the CD re-run passes.
  • test-audit on the branch tests: no changes needed.
  • Codex review: one round on 6335f5d491f, no major issues and no review threads.
  • Review budget: 9 frontend role passes, 1 test audit, and 1 Codex round. That is past the six-pass cap, which Mike's explicit codex-review-loop request authorizes.

🤖 Xum prepared this PR on behalf of @ibetitsmike.

- Align the server workspace upload name sanitizer with the frontend
  sanitizeChatFileName character set so direct API callers cannot land
  shell, quote, or bracket characters in workspace file names.
- Strictly validate workspace_file_media_type on workspace-file-reference
  parts (parseable type/subtype, no control characters, at most 255
  bytes) and persist the parsed base type. The upload endpoint returns
  application/octet-stream for an unparseable Content-Type so its
  response always passes message validation.
- Rate limit POST /chats/{chat}/workspace-files per caller across all
  chats with a new httpmw.RateLimitPerCaller instead of per path.
The frontend review flagged the JSDoc for pinning coderd's filename rules, which change without touching this file.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T00:51:03.383286Z 6335f5d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 6335f5d491

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@linear-code

linear-code Bot commented Sep 30, 2026

Copy link
Copy Markdown

CODAGT-1262

@ibetitsmike
ibetitsmike marked this pull request as ready for review October 27, 2026 00:48
@ibetitsmike
ibetitsmike requested a review from a team as a code owner October 27, 2026 00:48
@ibetitsmike
ibetitsmike merged commit 34ef30e into main Oct 27, 2026
59 of 61 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chat-upload-input-validation branch October 27, 2026 00:50
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants