Skip to content

fix(coderd): reject overflowing chat workspace TTL values - #31036

Draft
ibetitsmike wants to merge 1 commit into
mainfrom
mike/chat-workspace-ttl-overflow
Draft

ibetitsmike wants to merge 1 commit into
mainfrom
mike/chat-workspace-ttl-overflow

Conversation

@ibetitsmike

Copy link
Copy Markdown
Collaborator

PUT /api/v2/chats/config/workspace-ttl converted workspace_ttl_ms to a time.Duration before it checked the 30-day maximum. A value whose nanosecond count overflows int64 wraps into range: 18446744133710 ms becomes about one minute, passes both range checks, and is stored. This PR checks the maximum on the millisecond value, before the conversion.

Why it is safe: for every value that does not overflow, req.WorkspaceTTLMillis > ttlMaximum.Milliseconds() is the same test as d > ttlMaximum, and it writes the same 400 message. TestChatWorkspaceTTL already pins the boundary: exactly 30 days is accepted and 721 hours is rejected. A mutant that rejects exactly 30 days fails it.

Red test: TestChatWorkspaceTTL now sends 18446744133710 ms and expects a 400 and an unchanged stored value. On main the handler accepts the value:

coderd: PUT path=/api/v2/chats/config/workspace-ttl status_code=204
exp_chats_test.go:17027: Error: An error is expected but got nil.
--- FAIL: TestChatWorkspaceTTL

Review focus: the order of the checks. The maximum now runs on milliseconds before the conversion; the one-minute minimum still runs on the converted duration, which is safe once the maximum has passed.

#31018 moves this handler into a shared putChatOperationalSetting helper. This fix is based on main, and whichever of the two merges second will merge main and keep this check.

Validation: go test ./coderd -run '^TestChatWorkspaceTTL$' -count=1 fails on main as above and passes on this branch. On this branch, go test ./coderd -run '^(TestChatPersonalModelOverridesAdminSettings|TestChatComputerUseProvider|TestChatDebugLoggingSettings|TestChatWorkspaceTTL|TestChatRetentionDays.*|TestChatDebugRetentionDays|TestChatAutoArchiveDays|TestAuditedChatOperationalSettingWrite.*)$' -count=1 passes (11 tests, 27 with subtests) and go test ./enterprise/coderd -run '^TestChatOperationalSettingsAudit$' -count=1 passes (17 with subtests). go vet ./coderd/ is clean, and the pre-commit hook passed (make gen, formatting, golangci-lint, slim build).

Xum, an AI agent, opened this PR for @ibetitsmike and wrote this description.

putChatWorkspaceTTL converted workspace_ttl_ms to a time.Duration before
it checked the 30-day maximum, so a value whose nanosecond count
overflows int64 wrapped into range: 18446744133710 ms became about one
minute, passed both checks, and was stored. Check the maximum on the
millisecond value before the conversion.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-19T23:36:45.772720Z 6f112f4 Manual request
ℹ️ 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. What shall we delve into next?

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 6f112f4ca7

ℹ️ 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".

This branch has not been deployed

No deployments
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.

1 participant