Skip to content

fix(protect-secrets): close the grep and Grep-tool .env bypasses - #48

Merged
karanb192 merged 1 commit into
mainfrom
fix/protect-secrets-grep-bypasses
Aug 20, 2026
Merged

fix(protect-secrets): close the grep and Grep-tool .env bypasses#48
karanb192 merged 1 commit into
mainfrom
fix/protect-secrets-grep-bypasses

Conversation

@karanb192

Copy link
Copy Markdown
Owner

Fixes #47.

Two ways an agent read .env past protect-secrets, both surfaced while recording demos for the CodeSecCon talk. The failed takes are the proof of concept; this is the fix plus regression tests.

What was wrong

  1. Bash text-search tools. cat-env only covered cat/less/head/tail/more/bat/view. grep -E "STRIPE_API_VERSION|STRIPE_SECRET_KEY" .env read the file cleanly. A pipe inside the quoted pattern also defeats a plain [^|;&]* separator guard.
  2. The built-in Grep tool. Not registered at all, so Grep(pattern=..., path=".env") was never inspected.

The fix

  • New grep-env critical Bash pattern for grep/rg/egrep/fgrep/ag/awk/gawk targeting .env. The middle of the pattern skips over single- and double-quoted strings, so a | inside quotes no longer breaks the separator guard while a real shell separator still stops the match (a following cat .env is left to cat-env).
  • Grep added to the accepted tool list and normalized to a Read against its path/glob/include target, so it flows through the existing checkFilePath logic and denies with a search-flavored message.

Scope kept tight

  • .env.example and ordinary source-tree greps stay allowed (existing allowlist covers them; tests assert it).
  • One documented residual: a pattern-only Grep with no path searches the whole tree and can still surface a secret line. Blocking that would break normal search; the honest mitigation is output-side, not pattern matching. Called out in a test and a comment rather than papered over.

Tests

14 new regression tests (both bypass groups, the on-camera command shapes, the quoted-pipe variant, and the documented residual). Full suite 1584 pass / 0 fail. guard-pack lib/ copy kept byte-identical (drift test passes).

Two ways an agent read .env past the guard, both found while recording a
demo:

- Bash grep/rg/awk/etc. on .env slipped past the cat-only patterns. New
  grep-env critical pattern covers the text-search tools, and the pattern
  skips over quoted strings so a pipe inside grep -E "A|B" .env cannot
  break the separator guard.
- The built-in Grep tool was never inspected. It is now normalized to a
  Read against its path/glob/include target and runs through the same
  file-path check, denying with a search-flavored message.

.env.example and ordinary source-tree greps stay allowed. 14 regression
tests added, including the on-camera command shapes and a documented
residual (pattern-only Grep with no path). guard-pack lib copy kept
byte-identical. Suite 1584/0.

Fixes #47
@karanb192
karanb192 merged commit 2a907c1 into main Aug 20, 2026
3 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.

protect-secrets: .env readable via bash grep and the built-in Grep tool

1 participant