GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(sandbox): scrub dynamic credential env vars by PierrunoYT · Pull Request #682 · Twigpine/zero Conversation
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe change passes provider-configured API key environment names into sandbox engines, propagates them through command plans, and scrubs them alongside dynamically named ChangesSensitive environment scrubbing
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CLI as CLI sandbox setup
participant Engine as Sandbox Engine
participant Plan as Command Plan
participant Scrubber as Environment Scrubber
CLI->>Engine: Pass provider-sensitive environment keys
Engine->>Plan: Propagate normalized keys
Plan->>Scrubber: Build and scrub command environment
Scrubber-->>Plan: Return filtered environment
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This PR closes a security gap in the sandbox runner by expanding secret environment-variable scrubbing to include configuration-derived provider credential env var names (apiKeyEnv) and dynamically named OAuth client-secret variables (ZERO_OAUTH_<NAME>_CLIENT_SECRET) across Linux/macOS/Windows sandbox command plans.
Changes:
sandbox.Engine, then into per-command planning.scrubSensitiveEnv to accept additional sensitive keys and to drop dynamically patterned OAuth client-secret variables case-insensitively.Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/sandbox/windows_runner.go | Uses sensitive-env-aware sandbox environment construction for Windows restricted token plans. |
| internal/sandbox/runner.go | Plumbs sensitive keys through command planning and expands scrubbing to include additional keys + dynamic OAuth patterns. |
| internal/sandbox/runner_test.go | Extends scrub tests and adds an engine-level test ensuring configured sensitive keys are removed from plans. |
| internal/sandbox/engine.go | Adds SensitiveEnvKeys support to engine options and normalizes keys on engine creation. |
| internal/cli/exec.go | Passes config-derived provider apiKeyEnv names into sandbox engine construction. |
| internal/cli/app.go | Passes config-derived provider apiKeyEnv names into the interactive app’s sandbox engine creation path. |
| internal/cli/sandbox_sensitive_env_test.go | Adds a unit test for collecting provider-sensitive env keys from resolved config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| for _, key := range keys { | ||
| key = strings.TrimSpace(key) | ||
| folded := strings.ToUpper(key) | ||
| if key == "" { | ||
| continue | ||
| } | ||
| if _, ok := seen[folded]; ok { | ||
| continue | ||
| } | ||
| seen[folded] = struct{}{} | ||
| out = append(out, key) | ||
| } |
A config value mistakenly given as a full assignment (e.g. "COMPANY_LLM_SECRET=...") would never match the real env key during scrubbing, silently re-exposing the credential to sandboxed commands. normalizeSensitiveEnvKeys now keeps only the name part before '=' and re-trims it, per PR review. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I found issues that need to be addressed before this is ready.
internal/sandbox/runner.go:169BuildCommandPlan attaches the configured keys to spec, but the supported unavailable-backend fallback returns directCommandPlan, which simply leaves Env nil. The normal bash tool creates a spec with nil Env, so exec.Cmd inherits COMPANY_LLM_SECRET and ZERO_OAUTH_<NAME>_CLIENT_SECRET unchanged whenever the native backend is unavailable (the intended EnforcementDegraded path covered by TestBuildCommandPlanDegradesUnavailableFallback and TestUnavailableBackendsDegradeForTargetPlatforms). That leaves the reported credential-exfiltration scenario open on fallback hosts; construct a scrubbed environment for direct/degraded plans as well and add an inherited-environment regression test.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
directCommandPlan (used when the native sandbox backend is unavailable, disabled, or not required, including the EnforcementDegraded fallback) left Env nil whenever spec.Env was nil, so exec.Cmd inherited the full caller environment unscrubbed. Configured apiKeyEnv credentials and dynamically named ZERO_OAUTH_<NAME>_CLIENT_SECRET variables leaked through that path even though the wrapped sandbox plans already scrubbed them. Route direct plans through scrubSensitiveEnv the same way wrapped plans do, snapshotting os.Environ() when spec.Env is nil so scrubbing still applies. Adds a regression test covering the degraded-fallback path with both a configured and a dynamically named secret. Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Re-reviewing against commit 7b59fc83 (head). The nil spec.Envsnapshot fix (patch 3/3) closes a real leak: direct/unwrapped command plans were inheriting the parent env unscrubbed, defeating the whole point of the scrubber — a sandboxed command could seeOPENAI_API_KEYetc. by going through the direct plan path. That was the P1 and the fix is correct (snapshotos.Environ()then runscrubSensitiveEnvbefore forking). The configurableSensitiveEnvKeysplumbing from CLI → engine is clean, and the case-insensitiveZERO_OAUTH_*_CLIENT_SECRETpattern viastrings.ToUpper` is the right shape for env vars.
LGTM. Minor follow-up (not blocking): the isDynamicSensitiveEnvKey length check rejects the empty-provider case ZERO_OAUTH__CLIENT_SECRET (double underscore) — a one-line test for that edge case would be cheap. Also worth documenting the dynamic-pattern list near the function so a future maintainer knows where to add a second pattern.
Cross-PR note: #682 sits between #681 and #685. Recommend rebasing #682 onto #681, then #685 onto #682, to resolve the credentialDenyReadPaths / scrubSensitiveEnv signature overlap cleanly.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Local review: built and ran go test ./internal/cli ./internal/sandbox on darwin/arm64 (cli 94s); all pass. The direct/degraded-plan env scrubbing (including the spec.Env == nil -> os.Environ() snapshot) is a genuine security fix. One integration note.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| func scrubSensitiveEnv(env []string) []string { | ||
| func scrubSensitiveEnv(env []string, additionalKeys ...string) []string { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
[P2] Sibling-PR merge conflict on scrubSensitiveEnv in runner.go
This PR changes the signature to scrubSensitiveEnv(env, additionalKeys ...string) and adds normalizeSensitiveEnvKeys. #685 adds a hardcoded ZERO_DAEMON_REMOTE_TOKEN_FILE to the same function's literal list, and both touch runner_test.go's TestScrubSensitiveEnv. Each merges into main cleanly on its own, but they conflict with each other; #681 also rewrites credentialDenyReadPathsIn in profile.go. Sequence the three sandbox credential PRs and rebase as needed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. This closes a real leak: config-derived apiKeyEnv names and dynamic ZERO_OAUTH_*CLIENT_SECRET vars are now scrubbed on every plan path (linux/seatbelt/windows wrapped plus the degraded direct fallback that previously inherited the caller env unscrubbed). I checked out the branch and confirmed go build, go vet, and gofmt are clean on the touched files, and the new tests (TestScrubSensitiveEnv, TestEngineScrubsConfiguredSensitiveEnvKeys, TestBuildCommandPlanDegradedFallbackScrubsInheritedEnv, TestProviderSensitiveEnvKeys) pass. The bare ZERO_OAUTH_CLIENT_SECRET (no provider segment) the reviewer noted is preserved by the prefix/suffix length guard, but that's fine in practice: Zero's envKey always emits ZERO_OAUTH_CLIENT_SECRET with a name segment, so that exact bare name is never a credential Zero sets.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Reconciles this branch with main after Twigpine#681 (credential deny-read refactor), Twigpine#682 (dynamic env scrub), and Twigpine#774 (daemon child cleanup) landed on the same files. One content conflict, in internal/cli/daemon_test.go: both sides appended new test functions to the end of the file and both sides added imports. Resolved as a union — this branch's TestDaemonServeRemoteCanonicalizesTokenFileBeforeStartingWorkers and writeDaemonTestCertificate alongside main's daemon lifecycle/terminate-and-reap coverage. No test was dropped or rewritten, and the two sets share no helper names. internal/cli/daemon.go merged cleanly, keeping both this branch's CanonicalizeTokenFileEnv() bridge pinning and main's terminateAndReapDaemonProcess / background.TerminateCommand. The sandbox files (profile.go, runner.go, linux_helper.go, manager_test.go, runner_test.go) merged without conflict: this branch was already written against the credentialPathOptions shape, so no flat credentialDenyReadPathsIn signature is reintroduced.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Sandbox env scrub misses custom apiKeyEnv and dynamic OAuth client secrets
There was an error while loading. Please reload this page.