Repository navigation
fix(security): write MCP bearer tokens 0600, revoke them on shutdown, keep them out of codex argv (#125) - #195
Merged
currentbits merged 1 commit intoAug 16, 2026
Conversation
The memory and orchestrator tokens were written world-readable into user-global CLI configs and never revoked. The coder-threads token drives thread_fork/thread_send, so a leaked copy is arbitrary agent runs in every registered project. - kimi mcp.json and our own claude mcp config are written 0600, and chmod'd on rewrite (writeFileSync's mode only applies on create). grok's config.toml is chmod'd 0600 after a successful `mcp add`. - Codex gets the URL in argv and the token via bearer_token_env_var + CODER_MCP_TOKEN_<NAME> on the child env, instead of a ?token= query param visible to any local process through `ps`. - unregisterMcpServer and the supervisor's stop() now revoke the kimi/grok entries (delete from mcp.json, `grok mcp remove <name> -s user`) the way the claude path already did. - The orchestrator mints a fresh token every launch (port stays stable), so a copy that escaped cleanup is dead on the next start. Co-Authored-By: Claude Opus 5 <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
currentbits
deleted the
coder/security-orchestrator-memory-bearer-toke-013caa
branch
October 3, 2026 16:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #125.
What was wrong
The bearer tokens protecting
coder-memoryandcoder-threadswere written into user-global CLI configs at ~0644 and never removed. Thecoder-threadstoken reachesthread_fork/thread_send→runner.startRun, so any copy of it is arbitrary agent runs in every registered project.Changes
Permissions.
writeSecretFile()writes token-bearing files 0600 and chmods them —writeFileSync'smodeonly applies on create, so an existing 0644 file stayed 0644. Applied to kimi'smcp.jsonand our ownmcp-coder-memory.json. grok writes its ownconfig.toml, so it is chmod'd 0600 after a successfulmcp add.Codex auth off the command line.
getCodexMcpArgs()no longer appends?token=to the URL (visible to every local user viapsfor the whole run). It emitsmcp_servers.<name>.bearer_token_env_var="CODER_MCP_TOKEN_<NAME>"and the newgetCodexMcpEnv()supplies the value on the child's env only. Verified end-to-end against a realcodex-cli 0.142.4and a probe server:POST /mcp auth=Bearer abc123.Revocation.
unregisterMcpServer()and the supervisor'sstop()now drop our entries from kimi'smcp.jsonand rungrok mcp remove <name> -s user, matching what the claude path already did. Kimi cleanup runs even when the kimi binary is gone — an uninstalled CLI leaves the config and the token behind all the same. An adopted memory server is skipped: it belongs to another instance that is still serving it.Rotation.
loadOrCreateConfigkeeps the persisted port but mints a fresh orchestrator token every launch, so a copy that escaped cleanup is dead the next time Solenta starts.Not covered
The
coder-memorytoken still persists across launches — it is minted by the memory server process, which survives app restarts by design, so rotating it is a separate change. Its capability is memory read/write, not agent execution.Tests
electron/test/776 pass, renderer 703 pass. New coverage: kimi config mode 0600 over a pre-existing 0644 file, unregister deleting our entry while leaving foreign servers alone, thegrok mcp removeargv, the codex token arriving via env and not argv, and a stale orchestrator token getting 401 after a restart. Two test suites also neededCODER_GROK_CONFIG_PATHso the new chmod cannot touch the real~/.grok/config.toml.