Repository navigation
fix(security): stop lending the server GitHub credential to any agent token - #964
Conversation
… token Three routes let any `cm_agent_*` token — held by an agent installed by any user on the instance — reach GitHub under our shared PAT: - `POST /api/github/token` returned `process.env.GITHUB_PAT` in plaintext to the caller, or minted an App installation token for a caller-chosen repo. - `GET /api/github/pulls/:number/diff` and `POST /:number/review` took `owner`/`repo` from the caller (ours were only defaults) and executed under that PAT — so any agent could read diffs from, and post reviews including APPROVE onto, any repository the credential reached. Nothing exploited this because the PAT has been 401-dead for weeks: the broken credential was doing the access control, and rotating it would have re-armed all three at once. That is why this lands before any rotation. Removed all three, plus the `commonly_pr_diff` / `commonly_pr_review` MCP tools they backed. No runtime loses a capability — every runtime that used them has a shell and its own GitHub identity (local wrappers use the operator's `gh` keyring; cluster runtimes get `gh` plus a credential helper at image build), and `gh` additionally supports the line-level review comments these never did. The agent-facing preset and bundled skill now say so instead of recommending them. Issue routes are pinned server-side to Team-Commonly/commonly. They kept the same shape — caller-supplied `owner`/`repo` — so the target is no longer caller-chosen. This retires the `VALID_NAME` regex on those inputs: validating a caller's repo name made it well-formed, never authorised. Left deliberately unsolved: a shell-LESS runtime (native Tier-1, or a hosted Code Reviewer persona) still has no GitHub path. That case needs per-user GitHub App auth, because reviewing a user's repository under our identity is wrong even when it works. Tests: the removed routes are asserted unroutable against the mounted app, with a PAT configured — the strongest configuration for the defect — and separately asserted never to reach a GitHub service call, so a 404 arriving for some other reason cannot pass. Issue pinning is asserted against a caller-supplied attacker-controlled target. AX audit entry 25 records the rules earned. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8
…d number Fourth instance of the same defect, reached through a surface that names no GitHub route: the task board. `githubIssueNumber` is caller-supplied on task creation and validated only as a positive integer (`tasksApi.ts:155`), so it can name ANY issue in the repository. Two writes trusted it, both under the server's shared PAT and both reachable by any `cm_agent_*` token: - completing a task auto-closed that issue, with `prUrl` — also caller-supplied — interpolated into the closing comment - creating a sub-task commented on the parent's issue, with `title` as the body So an agent could create a task naming someone else's issue, complete it, and have our server close that issue as us with attacker-chosen text. Gated on a new `githubIssueOwned` flag, set only where this server itself opened the issue via `createGithubIssue`. The number stays as display metadata; it is no longer authority to write. Legacy tasks predate the flag and so no longer auto-close. That is the correct direction: a write we cannot prove we own should fail closed. Same pre-rotation gate as the rest of this PR — inert today only because the PAT is 401-dead, and re-armed the moment it is rotated. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8
|
Added a fourth instance found while sweeping for siblings — worth calling out because it isn't a GitHub route and wouldn't be found by grepping for one. The task board.
So an agent could create a task naming someone else's issue, complete it, and have the server close it as us with attacker-chosen text. Gated on a new Note the search that found it: grepping route files for |
CodeQL flagged js/missing-rate-limiting on the complete handler — a pre-existing gap, surfaced only because this PR touched that line. Create and claim were limited; complete, updates and patch were not, though all five write to Mongo behind the same auth. Fixing the flagged line alone would have left two siblings open for the next diff to rediscover, so all three get the shared limiter, keyed per token like the existing two rather than per IP. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8
…source npm @commonlyai/mcp@0.3.0 and main's commonly-mcp@0.3.0 are DIFFERENT CODE. #964 deleted `commonly_pr_diff`/`commonly_pr_review` from the tool list (their routes spent the server's shared GitHub PAT on a caller-chosen repo) but did not bump the version. So the correction reached the repo and never reached a single seat: every MCP agent installed from npm still advertises two tools that now 404, and the model plans around a capability that fails at the call. Verified by unpacking the published tarball rather than reading this tree — 0.3.0 on npm declares both names; main declares neither and carries a comment saying why. Same version string, two different tool surfaces. A version number that maps to two different artifacts is the part worth fixing beyond this release: it defeats the only check anyone can run from outside. This commit is the bump alone. The code correction is already on main. Publishing needs npm auth, which is Sam's to run.
…source (#979) npm @commonlyai/mcp@0.3.0 and main's commonly-mcp@0.3.0 are DIFFERENT CODE. #964 deleted `commonly_pr_diff`/`commonly_pr_review` from the tool list (their routes spent the server's shared GitHub PAT on a caller-chosen repo) but did not bump the version. So the correction reached the repo and never reached a single seat: every MCP agent installed from npm still advertises two tools that now 404, and the model plans around a capability that fails at the call. Verified by unpacking the published tarball rather than reading this tree — 0.3.0 on npm declares both names; main declares neither and carries a comment saying why. Same version string, two different tool surfaces. A version number that maps to two different artifacts is the part worth fixing beyond this release: it defeats the only check anyone can run from outside. This commit is the bump alone. The code correction is already on main. Publishing needs npm auth, which is Sam's to run.
Summary
Three GitHub routes were reachable by any
cm_agent_*token — which every agent, installed by any user on the instance, holds — and each of them spent our shared server-sideGITHUB_PAT:POST /api/github/tokenprocess.env.GITHUB_PATin plaintext, or mint an App installation token for a repo of their choosingGET /api/github/pulls/:number/diffPOST /api/github/pulls/:number/reviewAPPROVE— onto any such repoowner/repowere caller-supplied;Team-Commonly/commonlywere only defaults. So the caller chose the target and our credential supplied the authority. The rate limiter on the/pullsroutes bounded volume, not authority.Why nothing happened, and why that matters
The PAT has been 401-dead for weeks. Every call failed upstream, so the broken credential was doing the access control. That is also why this stayed invisible: it was filed as an ops annoyance (AX #9 flagged the credential as unverified) rather than an authorisation gap, because a failing call and a forbidden one look identical from outside.
The practical consequence: rotating the PAT would have re-armed all three at once. This lands first for that reason.
What changed
commonly_pr_diff/commonly_pr_reviewMCP tools they backed.Team-Commonly/commonlyserver-side. They had the same caller-supplied-target shape.VALID_NAMEregex on those inputs — validating a caller's repo name made it well-formed, never authorised, and there is no caller-supplied value left to interpolate.githubskill) toghinstead of recommending the removed tools.No capability is lost
Every runtime that used these has a shell and its own GitHub identity:
ghkeyring auth — PR fix: derive wake policy from pod shape #963 was opened that way, not through this proxyghplus a git credential helper at image buildghis also strictly more capable here: it supports line-level review comments, whichcommonly_pr_reviewnever did (it took only{event, body}).The tools existed for ergonomics —
docs/audits/ui-smoke-2026-05-23records agents having to "know the gh CLI is available". That is a real complaint, and it justified building a credential proxy without anyone re-asking whose authority it spent.Deliberately left open
A shell-less runtime — native Tier-1, or the hosted Code Reviewer persona in ADR-022's v1 cast — still has no GitHub path. That case needs per-user GitHub App auth, because reviewing a user's repository under our identity is wrong even when it works. A shared PAT cannot express it, so no amount of gating on these routes would have delivered it.
Verification
backend/__tests__/unit/routes/github.upstreamErrorRoutes.test.js— 10 passing:isPatConfigured: true(the strongest configuration for the defect — precisely when/tokenused to answer with the secret){owner: 'attacker', repo: 'private-repo'}commonly-mcp— 46 passing. Tool count 29 → 27, plus a by-name assertion that the two tools are absent, because a future tool would restore the count and silently re-satisfy a bare length check.npx tsc --noEmitclean.Note:
backend/__tests__/unit/routes/github.upstreamErrors.test.jsfails to run on this branch — it also fails identically onmain(verified by restoring the pristine file and re-running; the stack differs only by the line number of an import). Pre-existing, untouched here.Follow-ups not in this PR
POST /issues/:number/closeis still a write any agent can perform. Worth an explicit authorisation decision.🤖 Generated with Claude Code
https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8