Skip to content

fix: ERE brace bug made detection a no-op + bytes32 false positives#1

Merged
jhfnetboy merged 1 commit into
mainfrom
fix/ere-brace-bug-and-bytes32-false-positives
Jun 24, 2026
Merged

fix: ERE brace bug made detection a no-op + bytes32 false positives#1
jhfnetboy merged 1 commit into
mainfrom
fix/ere-brace-bug-and-bytes32-false-positives

Conversation

@jhfnetboy

Copy link
Copy Markdown
Owner

Two confirmed bugs

1. ERE/BRE mismatch — the local hook detected nothing

hooks/pre-commit defines patterns with BRE syntax (0x[a-fA-F0-9]\{64\}, sk_\(live\|test\)_, [_-]\?) but runs them with grep -E (ERE), where \{ \( \| \? are literal characters, not operators. So the Ethereum / AWS / OpenAI / Google / Anthropic / GitHub / Stripe patterns matched nothing.

Proof (shipped hooks/pre-commit vs a real 64-hex key):

A) original hook  → '✅ No private keys detected'   ← false negative, key committed
B) braces → ERE   → '[CRITICAL] Ethereum Private Key … 🚨 COMMIT BLOCKED'

(The .github/workflows/check-secrets.yml already 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 existing PRIVATE_KEY_WITH_VALUE_PATTERN still covers labeled assignments. Applied to both the hook and the workflow.

Tests

Adds test/test-detection.sh (run from repo root) — 6/6 pass:

case expect
real key in .env block ✅
labeled key in code block ✅
AWS access key block ✅
OpenAI key block ✅
bare bytes32, no context allow ✅
clean file allow ✅

Found 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).

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.
@jhfnetboy
jhfnetboy merged commit 67ec835 into main Jun 24, 2026
1 of 2 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.

1 participant