Repository navigation
fix(coderd/x/gitsync): verify chat workspace before storing agent git refs - #31494
Conversation
… refs MarkStale trusted the chat ID sent by the workspace agent with external auth requests. Any agent could attach a git branch and origin to another user's chat, and the refresh worker would then query PR status with the chat owner's git token. Ignore the request unless the requested chat is bound to the calling agent's workspace. The check runs on the requested chat before resolving its root, so subagent chats (which inherit the parent's workspace) keep updating the root chat.
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c7ddb1ae5e
ℹ️ 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".
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Rebinding a chat's workspace does not rebind its existing subagent chats, so a child can stay bound to the old workspace. Checking only the requested chat let that old workspace write git refs to a root now bound elsewhere. Verify the resolved root chat as well.
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
When a workspace agent requests external auth, it can send a
chat_id(fromCODER_CHAT_ID) so the current git branch is linked to that chat.gitsync.Worker.MarkStaletrusted that ID and never checked that the chat belongs to the agent's workspace. As a result, any workspace agent could set the git branch, origin, and PR shown on another user's chat, and the refresh worker would then fetch PR status with that chat owner's git token.MarkStalenow ignores the request and logs a warning unless both the requested chat and the root chat that receives the ref are bound to the calling agent's workspace. Subagent chats are created with their parent'sworkspace_id(coderd/x/chatd/subagent.go), so their legitimate updates still reach the root chat. The root is checked too because rebinding a chat's workspace does not rebind its existing subagent chats. Both external-auth handlers incoderd/workspaceagents.gopass the chat ID throughMarkStale, so this single check covers both.Tests:
TestWorker_MarkStale_WithChatIDis now table-driven. A chat on the same workspace is updated. A chat on another workspace, a chat with no workspace, and a missing chat get no update and no event.TestWorker_MarkStale_SubagentChatID_UsesRootChatbinds the chats to real workspaces and adds two calls that must not reach the root: one from another workspace using the child's ID, and one from the old workspace through a child after the root is rebound to a new workspace.TestWorker_MarkStale_StripsOriginCredentialsbinds its chat to the caller's workspace, since that test relied on the missing check.Refs CODAGT-1420, SEC-856. Affects v2.32.0 onward; backports are needed for every supported release line from 2.32.
Investigation notes
agent/agentproc/process.gosetsCODER_CHAT_IDin the process environment, andcli/gitaskpass.gosends it aschat_id. Anyone with access to the workspace can set this value.GetChatsByWorkspaceIDs); only the chat-ID path skipped the check.workspace_id?): yes,CreateChatWithIDinsubagent.gosetsWorkspaceID: parent.WorkspaceID.UpdateChatWorkspaceBindingrebinds only the chat it targets, so a child can stay bound to the old workspace after its root is rebound. Checking only the requested chat let the old workspace write to the rebound root, so the root's workspace is checked too.MarkStaleis the only consumer of the chat ID, and rejecting there would change the external-auth response for git operations.