Reject bare wildcard env-forward patterns at load time#130
Merged
Conversation
A bare `*` in env_forward matches every host environment variable
because matchPattern trimmed the trailing `*` and HasPrefix against
the empty string always returns true. Combined with mergeAgentOverride
replacing the global env_forward with the workspace-local value
verbatim, a malicious `.broodbox.yaml` could ship
`agents.claude-code.env_forward: ["*"]` and scoop up host secrets
(SSH_AUTH_SOCK, GITHUB_TOKEN, AWS_*, VAULT_TOKEN, OKTA_*) into the
guest agent's environment — from where any permitted egress host
becomes an exfiltration channel.
The narrow fix preserves the feature (per-repo env_forward allowlists
like `["GOFLAGS", "CARGO_*"]` are legitimate and useful) while
rejecting the footgun:
- Reject bare "*" and whitespace-trimmed variants
- Reject empty / whitespace-only patterns
- Reject leading-star patterns ("*_KEY") which are silently useless
under matchPattern's semantics — surface as a clear error rather
than let users believe their config works
Validation runs at four load points:
- NewLoader.Load — global ~/.config/broodbox/config.yaml
- LoadFromPath — workspace-local .broodbox.yaml
- run() — `--env-forward` CLI flag
- SandboxRunner.Prepare — SDK boundary (RunOpts.EnvForwardExtra)
Defense-in-depth: matchPattern also returns false for empty / bare-"*"
patterns so a bypass of load-time validation cannot silently forward
every env var.
UX change: global config load errors are now fatal instead of warn-
and-fall-back-to-defaults. Silently discarding every override in a
user's own config because one line fails validation was worse than
a clear error naming the file and the exact problem. Workspace-local
config keeps its warn-and-skip behavior so a malicious repo cannot
DOS a user's session.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Closes a HIGH security finding. A bare
*inenv_forward(global config, workspace.broodbox.yaml, or--env-forwardCLI flag) matched every host environment variable becausematchPatterntrimmed the trailing*and thenHasPrefix(key, "")was always true. Combined withmergeAgentOverridereplacing the global value with the workspace-local value verbatim, a malicious.broodbox.yamlcould shipagents.claude-code.env_forward: ["*"]and scoop up host secrets (SSH_AUTH_SOCK,GITHUB_TOKEN,AWS_*,VAULT_TOKEN,OKTA_*) into the guest agent's environment — from where any permitted egress host becomes an exfiltration channel.The narrow fix preserves the feature (per-repo allowlists like
["GOFLAGS", "CARGO_*"]are legitimate and useful) while rejecting three classes of footgun:*and whitespace-trimmed variants*_KEY) — silently useless today; surface a clear error so users learn the correct syntaxValidation coverage
Validation runs at four load points so no user-supplied source bypasses it:
NewLoader.Load— global~/.config/broodbox/config.yamlLoadFromPath— workspace-local.broodbox.yamlrun()—--env-forwardCLI flagSandboxRunner.Prepare— SDK boundary (RunOpts.EnvForwardExtra)Defense-in-depth:
matchPatternalso returns false for empty / bare-*patterns so a bypass of load-time validation cannot silently forward every env var.UX change
Global config load errors are now fatal instead of warn-and-fall-back-to-defaults. Silently discarding every override in a user's own config because one line fails validation was worse UX than a clear error naming the file and the exact problem. Workspace-local config keeps its warn-and-skip behavior so a malicious repo cannot DOS a user's session.
Error messages
Every rejection pinpoints the location and suggests the fix:
loading global config /path/to/config.yaml: validating config file ...: agents.claude-code.env_forward[0]: bare "*" matches every host env var — specify an exact name or a prefix like "AWS_*"invalid --env-forward: env_forward[0]: leading-star patterns are not supported ("*_API_KEY") — only trailing-star globs like "AWS_*"Test plan
task fmt && task lint && task test— all green*variants, empty, whitespace, leading-star, mixed-with-valid patterns)Loader.Load, workspaceLoadFromPath, and empty-string in configmatchPatterntest: bad patterns ("*",""," "," * ") must not match any realistic env var name includingSSH_AUTH_SOCK,GITHUB_TOKEN,AWS_ACCESS_KEY_IDbbox claude-code --env-forward '*'→ exit non-zero with clear errorbbox claude-code --env-forward '*_API_KEY'→ exit non-zero with clear errorbbox claude-code --config /path/with-star.yaml→ exit non-zero with file path in errorbbox claude-code --no-mcp --env-forward HOME --exec /bin/sh -- -c 'env | grep ^HOME='→ VM boots,HOMEforwarded,AWS_*/GITHUB_TOKEN/ANTHROPIC_API_KEYNOT present🤖 Generated with Claude Code