fix(secret-guard): kill 8 rule false positives, drop S-62 code from banner#96
Merged
Conversation
…anner Same family of bug across multiple rules: flat regex across the whole CMD with no segment-awareness, and substring matches without terminators. Tightened all of them: - B3: capture-form-aware ($() and `` strips) + quote-aware segment split on ;/&&/||. Stops false-firing on $(printf '%s' "$T" | wc -c) and on echo-in-one-segment + safe -H "Bearer $TOKEN"-in-another. - B5: same segment split; SEPCLASS terminator (excludes `.`) so .netrc.tmpl / credentials.tmpl read straight through. Bare .pem dropped from the regex; /etc/ssl/private and /etc/pki/tls/private added explicitly so canonical private-key dirs still block. - B6: inspects ONLY the body of unquoted-marker heredocs (new extract_unquoted_heredoc_bodies awk helper). Quoted-marker bodies and out-of-heredoc text no longer trip the rule. - B8: three signals (interpreter -c, env-access, secret-name) now required IN THE SAME SEGMENT, not aggregated across &&. - B2d: terminators after `--decrypt` / `-d` so `gpg --decrypt-files` and `openssl enc -des-cbc` don't substring-match decrypt verbs. - R1: drops bare *.pem; adds */etc/ssl/private/* and */etc/pki/tls/ private/* (canonical private-key dirs). Banner: stripped `(S-62/<code>)` from the user-facing block message and replaced with a short per-rule label, e.g. `BLOCKED: echo of a secret variable`. Rule code still lands in `~/.cache/claude-secret- guard.log` for grep. Banner now also starts on its own line (prior output concatenated onto the `[~/.claude/hooks/...]:` prefix). Two new shell helpers (split_quote_aware, extract_unquoted_heredoc_ bodies) consolidate the awk used by multiple rules. Verified end-to-end: both originally-blocked Cloudflare commands (zones?name=han.ws and workers GraphQL with unquoted JSON heredoc) now run through to a real API response. Spec self-test: 115/115. 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
Sweep of rule-level false positives surfaced while running Cloudflare API work yesterday and today. Same family of bug across multiple rules: flat regex across the whole CMD with no segment-awareness, plus substring matches without terminators. All were hitting normal API/devops workflows.
$()and`strips) + quote-aware segment split on;/&&/||. Stops false-firing on$(printf '%s' "$T" | wc -c)and onecho "non-secret" && curl -H "Bearer $TOKEN" > /file.SEPCLASSterminator (excludes.) so.netrc.tmpl/credentials.tmplread straight through. Bare.pemdropped from the regex;/etc/ssl/private/and/etc/pki/tls/private/added explicitly so canonical private-key dirs still block.extract_unquoted_heredoc_bodiesawk helper inspects ONLY the body of unquoted-marker heredocs. Quoted-marker bodies and out-of-heredoc text no longer trip the rule.&&.--decrypt/-dsogpg --decrypt-filesandopenssl enc -des-cbcdon't substring-match the decrypt verbs.*.pem(couldn't tell public from private); adds*/etc/ssl/private/*and*/etc/pki/tls/private/*explicitly.Banner: stripped
(S-62/<code>)from the user-facing block message and replaced with a short per-rule label (e.g.BLOCKED: echo of a secret variable). Rule code still lands in~/.cache/claude-secret-guard.logfor grep. Banner now starts on its own line.Two new shell helpers (
split_quote_aware,extract_unquoted_heredoc_bodies) consolidate the awk used by multiple rules.Test plan
tests/secret-guard.sh— 115/115 pass (tests 120/122/123 updated to match the new banner contract: short-label in banner, rule code in audit log only)zones?name=han.wsDNS list, workers GraphQL with unquoted JSON heredoc) now run through to a real API response/etc/ssl/private/server.pem)run_onchange_after_secret-guard-test.sh.tmplwill re-run the spec test on the nextchezmoi applyand surface any regression via the apply summary🤖 Generated with Claude Code