Skip to content

fix(security): write MCP bearer tokens 0600, revoke them on shutdown, keep them out of codex argv (#125) - #195

Merged
currentbits merged 1 commit into
mainfrom
coder/security-orchestrator-memory-bearer-toke-013caa
Aug 16, 2026
Merged

currentbits merged 1 commit into
mainfrom
coder/security-orchestrator-memory-bearer-toke-013caa

Conversation

@currentbits

@currentbits currentbits commented Aug 16, 2026 •

Copy link
Copy Markdown
Owner

Closes #125.

What was wrong

The bearer tokens protecting coder-memory and coder-threads were written into user-global CLI configs at ~0644 and never removed. The coder-threads token reaches thread_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's mode only applies on create, so an existing 0644 file stayed 0644. Applied to kimi's mcp.json and our own mcp-coder-memory.json. grok writes its own config.toml, so it is chmod'd 0600 after a successful mcp add.

Codex auth off the command line. getCodexMcpArgs() no longer appends ?token= to the URL (visible to every local user via ps for the whole run). It emits mcp_servers.<name>.bearer_token_env_var="CODER_MCP_TOKEN_<NAME>" and the new getCodexMcpEnv() supplies the value on the child's env only. Verified end-to-end against a real codex-cli 0.142.4 and a probe server: POST /mcp auth=Bearer abc123.

Revocation. unregisterMcpServer() and the supervisor's stop() now drop our entries from kimi's mcp.json and run grok 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. loadOrCreateConfig keeps 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-memory token 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, the grok mcp remove argv, the codex token arriving via env and not argv, and a stale orchestrator token getting 401 after a restart. Two test suites also needed CODER_GROK_CONFIG_PATH so the new chmod cannot touch the real ~/.grok/config.toml.

  • PR created by the Claude Code agent

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]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits currentbits changed the title fix(security): stop leaking MCP bearer tokens into user configs (#125) fix(security): write MCP bearer tokens 0600, revoke them on shutdown, keep them out of codex argv (#125) Aug 16, 2026
@currentbits
currentbits merged commit 42613a0 into main Aug 16, 2026
1 check passed
@currentbits
currentbits deleted the coder/security-orchestrator-memory-bearer-toke-013caa branch October 3, 2026 16:07
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.

Security: orchestrator/memory bearer tokens persisted world-readable in kimi/grok user configs, never revoked

1 participant