Skip to content

fix(secret-guard): strip quoted-heredoc bodies in call-detection#92

Merged
tieubao merged 2 commits into
mainfrom
fix/secret-guard-quoted-heredoc
May 10, 2026
Merged

fix(secret-guard): strip quoted-heredoc bodies in call-detection#92
tieubao merged 2 commits into
mainfrom
fix/secret-guard-quoted-heredoc

Conversation

@tieubao
Copy link
Copy Markdown
Member

@tieubao tieubao commented May 10, 2026

Summary

  • secret-guard PreToolUse hook blocked git commit -m "$(cat <<'INNER' ... INNER)" whose message body documented changes to secret-cache-read / op read / security find-generic-password (rule B2/B1/B2b false-positive).
  • Two compounding causes in is_safe_secret_call: (1) literal call-tokens inside a quoted-marker heredoc body are documentation, not invocations, and (2) the $() strip regex \$\([^\(\)]*\) can't match when the body contains parens, so conventional-commit subjects (feat(scope): ...) defeat the substitution strip.
  • Prepends a quoted-heredoc body strip (awk, line-based) before the $() / backtick / <() strip. UNQUOTED markers stay under B6's purview unchanged.

Test plan

  • Adds tests/secret-guard.sh cases 131/132/133 (B2, B1, B2b inside <<'EOF' body)
  • Tests confirmed red before fix, green after
  • Full suite 115/115 green; shellcheck clean
  • chezmoi apply deployed; original user repro now exits 0
  • This PR's own commit message exercises the fix (parens in subject + secret-cache-read / op read / security find-generic-password mentioned in body)

🤖 Generated with Claude Code

tieubao and others added 2 commits May 11, 2026 01:02
PreToolUse hook blocked git commits whose message body mentioned
secret-cache-read / op read / security find-generic-password (rule
B2/B1/B2b false-positive). Two compounding causes in
is_safe_secret_call: (1) the literal token sat inside a quoted-marker
heredoc (<<'EOF'...EOF) which preserves the body as data, not a call,
and (2) the existing $() strip regex \$\([^\(\)]*\) couldn't match
when the body contained parens, so conventional-commit subjects
defeated the substitution strip on every applicable commit.

Prepend a quoted-heredoc body strip (awk, line-based) before the $()
/ backtick / <() strip in is_safe_secret_call. UNQUOTED markers stay
under B6's purview unchanged. Adds tests 131/132/133 covering all
three rules; tests confirmed red before fix and green after. Test
suite 115/115; shellcheck clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tieubao tieubao merged commit a4a95dc into main May 10, 2026
2 checks passed
@tieubao tieubao deleted the fix/secret-guard-quoted-heredoc branch May 10, 2026 18:06
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