Skip to content

Keep generic CLI provider keys out of research sandboxes - #65

Merged
LikC1606 merged 1 commit into
mainfrom
fix/cli-credential-relay
Nov 29, 2026
Merged

LikC1606 merged 1 commit into
mainfrom
fix/cli-credential-relay

Conversation

@LikC1606

Copy link
Copy Markdown
Collaborator

Problem

Follow-up to #64. The generic cli research harness (non-sealed path) passed the whole host environment into bwrap. Any key listed in inheritEnvironment was readable from the agent shell and /proc/$PPID/environ, and the sandbox has network access.

Change

  • cli.json gains an optional researchProvider: { wireApi, apiKeyEnvironment, baseUrlEnvironment }. Both names must be inherited, distinct and not set in environment (math_cli_research_provider_binding_invalid).
  • prepareCliResearchRelay starts a loopback relay that holds the key. The sandbox gets a 64-hex capability and http://127.0.0.1:<port>/v1; client paths are forwarded relative to the configured base (default OpenAI / Anthropic base per wire API).
  • Secret-named inherited variables, sealedRole keys and copies of the key are removed from the sandbox. Any other inherited credential with a value fails closed with math_cli_provider_relay_unsupported. The launch asserts no arg or env value contains the key.
  • Web cli providers must declare a researchProvider matching their key/base environment (config validation and web_cli_research_provider_unbound).
  • Qwen and Aider presets are bound to chat-completions; Aider no longer inherits ANTHROPIC_API_KEY.

Behavior changes

  • The Gemini preset fails closed for research when GEMINI_API_KEY is set (no Gemini wire API in the relay).
  • Not covered: Codex's own /proc environ, profile-stored logins, literal keys in cli.json / configurationFiles.

Verification

  • vitest: cliSession, researchCredentialRelay, cliConfiguration, webHarness, webServer, genericCliSolver, sealedHarness, claudeCodeSession, openCodeSession: 232 passed, 2 skipped (opt-in).
  • tsc --noEmit and bun run build pass.
  • Local probe checking env and /proc/$PPID/environ inside the sandbox: this branch key_in_sandbox=no, unbound config rejected; main 1742637 key_in_sandbox=yes.

🤖 Generated with Claude Code

The non-sealed cli research launch spread the whole host environment into
bwrap, so any inherited provider key was readable from the agent's shell and
/proc environ.

- Add an optional researchProvider binding to cli.json; the host relay keeps
  the real key and the sandbox gets a disposable capability plus a relay /v1
  base. Client paths are forwarded relative to the configured base.
- Strip secret-named inherited variables, sealedRole keys and copies of the
  key; fail closed (math_cli_provider_relay_unsupported) for any other
  inherited credential that has a value.
- Require web cli providers to declare a matching researchProvider.
- Bind the Qwen and Aider presets; Aider no longer inherits ANTHROPIC_API_KEY.
  Gemini fails closed when GEMINI_API_KEY is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LikC1606
LikC1606 merged commit e676474 into main Nov 29, 2026
4 checks passed
@LikC1606
LikC1606 deleted the fix/cli-credential-relay branch December 1, 2026 20:12
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