Skip to content

fix: allowlist the pi subprocess environment (GHSA-38vh parity) - #135

Merged
saucam merged 1 commit into
mainfrom
feat/pi-env-hardening
Jul 9, 2026
Merged

fix: allowlist the pi subprocess environment (GHSA-38vh parity)#135
saucam merged 1 commit into
mainfrom
feat/pi-env-hardening

Conversation

@saucam

@saucam saucam commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

What

The pi subprocess (#132) inherited the daemon's full environment — including codeoid's own secrets (ZeroID root key, OAuth HMAC, Telegram bot token). That's the same local-privilege-escalation vector (GHSA-38vh v3) the Claude subprocess already guards with buildAgentEnv. This PR brings pi to parity and extracts the mechanism so future backends get it for free.

  • buildSubprocessEnv (new shared providers/env.ts): safe basics (PATH/HOME/locale/proxy/TLS trust) + a per-provider policy (exact names, prefixes, suffixes) + the existing CODEOID_AGENT_ENV_ALLOW operator escape hatch. Claude's buildAgentEnv now delegates with its historical allowlist (behavior unchanged, covered by a delegation test).
  • buildPiEnv: major provider namespaces (ANTHROPIC_, OPENAI_, GOOGLE_, GEMINI_), pi's own PI_ namespace, POSIX locale, and the conventional credential shapes *_API_KEY / *_API_TOKEN — pi spans ~60 providers, so shape-matching beats an unmaintainable enumeration. Uncommon vars (AWS_* for Bedrock, AZURE_*) are escape-hatch-only, documented in docs/providers-pi.md.
  • The finding that shaped the design: while writing the tests I hit CODEOID_API_KEY — the ZeroID root key — which ends in _API_KEY and would have ridden pi's credential-suffix rule straight into the subprocess. The fix is a deny-list for daemon-owned namespaces (CODEOID_, ZEROID_, TELEGRAM_) that beats every pattern match; only the explicit, exact-name operator escape hatch can override it. Leaking the root key now requires a deliberate operator action, never a pattern accident.

Tests

provider-env.test.ts: shared basics pass / unlisted drop, escape-hatch precedence, pi credential prefixes + suffix shapes, AWS excluded by default, deny-beats-suffix for CODEOID_API_KEY, hatch-overrides-deny, and Claude delegation keeping its historical behavior. The pi integration suite (fake-pi) still passes under the allowlisted env, which also proves the allowlist keeps a working pi spawn. 1192 tests green; tsc + biome clean.

🤖 Generated with Claude Code

The pi subprocess inherited the full daemon env — including codeoid's
own secrets (ZeroID root key, OAuth HMAC, Telegram token), the exact
GHSA-38vh vector the Claude subprocess already guards against.

- New shared buildSubprocessEnv (providers/env.ts): safe basics + proxy/
  TLS trust + per-provider policy (exact/prefix/suffix) + the
  CODEOID_AGENT_ENV_ALLOW escape hatch. buildAgentEnv (claude) now
  delegates to it with its historical allowlist
- buildPiEnv: major provider namespaces + PI_/LC_ prefixes + the
  *_API_KEY/*_API_TOKEN credential shapes (pi spans ~60 providers —
  enumerating each var is unmaintainable); AWS_/other uncommon vars are
  escape-hatch-only
- Daemon-owned namespaces (CODEOID_/ZEROID_/TELEGRAM_) are DENIED even
  when a pattern matches — found during test-writing that
  CODEOID_API_KEY (the ZeroID root key) ends in _API_KEY and would have
  ridden pi's credential-suffix rule. Only the explicit operator escape
  hatch overrides the deny-list
- Unit coverage for basics, deny-beats-pattern, escape-hatch precedence,
  and claude-delegation behavior; docs updated
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@saucam, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 03ce6e71-c935-47d3-aadc-11d0fc15dd85

📥 Commits

Reviewing files that changed from the base of the PR and between 55a0e9d and d8b66a9.

📒 Files selected for processing (6)
  • docs/providers-pi.md
  • src/daemon/providers/claude/index.ts
  • src/daemon/providers/env.ts
  • src/daemon/providers/pi/index.ts
  • src/daemon/providers/pi/rpc.ts
  • src/tests/provider-env.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/pi-env-hardening

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.57%. Comparing base (55a0e9d) to head (d8b66a9).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #135      +/-   ##
==========================================
+ Coverage   81.54%   81.57%   +0.03%     
==========================================
  Files          94       95       +1     
  Lines       16376    16406      +30     
==========================================
+ Hits        13354    13384      +30     
  Misses       3022     3022              
Flag Coverage Δ
daemon 81.57% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/daemon/providers/claude/index.ts 97.01% <100.00%> (-0.12%) ⬇️
src/daemon/providers/env.ts 100.00% <100.00%> (ø)
src/daemon/providers/pi/index.ts 90.28% <100.00%> (+0.04%) ⬆️
src/daemon/providers/pi/rpc.ts 96.90% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@saucam
saucam merged commit 9716eba into main Jul 9, 2026
5 checks passed
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