fix: ERE brace bug made detection a no-op + bytes32 false positives#1
Merged
Merged
Conversation
Two bugs made the local pre-commit hook either useless or unusable:
1. ERE/BRE mismatch — the hook's patterns used BRE intervals/groups (\{64\},
\(live\|test\), \?) but are run with `grep -E` (ERE), where \{ etc. are
LITERALS. So ETHEREUM/AWS/OpenAI/Google/Anthropic/GitHub/Stripe detection
matched nothing — the hook printed 'No private keys detected' on a real
0x+64hex key and let it through. Fixed all braces/groups to ERE syntax.
(The CI workflow already used correct ERE.)
2. bytes32 false positives — once the Ethereum pattern actually fires,
'0x'+64hex is indistinguishable from a legitimate bytes32 (hashes, storage
slots, calldata, test fixtures), so a fixed hook floods every such file.
Now a bare 64-hex is only flagged when it looks secret: a .env file, or a
secret-ish keyword (priv/secret/mnemonic/seed/wallet/signer) on the line.
Applied to both the hook and the CI workflow.
Adds test/test-detection.sh (6 cases): real keys in .env/code, AWS, OpenAI all
blocked; a bare bytes32 and a clean file allowed. All pass.
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.
Two confirmed bugs
1. ERE/BRE mismatch — the local hook detected nothing
hooks/pre-commitdefines patterns with BRE syntax (0x[a-fA-F0-9]\{64\},sk_\(live\|test\)_,[_-]\?) but runs them withgrep -E(ERE), where\{\(\|\?are literal characters, not operators. So the Ethereum / AWS / OpenAI / Google / Anthropic / GitHub / Stripe patterns matched nothing.Proof (shipped
hooks/pre-commitvs a real 64-hex key):(The
.github/workflows/check-secrets.ymlalready used correct ERE{64}, so CI was unaffected by this one.)2. bytes32 false positives — fixing #1 alone floods
Once
0x[a-fA-F0-9]{64}actually fires, it can't tell a private key from a legitimate bytes32 (hashes, storage slots, calldata, test fixtures). On a real codebase it flags hundreds of false positives, making the hook unusable and CI permanently red.Fix: a bare 64-hex is only flagged when it looks secret — the file is a
.env, or the line carries a secret-ish keyword (priv|secret|mnemonic|seed|wallet|signer). The existingPRIVATE_KEY_WITH_VALUE_PATTERNstill covers labeled assignments. Applied to both the hook and the workflow.Tests
Adds
test/test-detection.sh(run from repo root) — 6/6 pass:.envFound while integrating LeakShield into a public repo: the hook reported a real leaked key as safe (bug 1), and the corrected pattern then flagged every bytes32 in the tree (bug 2).