tokenoverflow
All notes

Catching Raw 32-Byte Hex Keys and BIP-39 Phrases with Gitleaks

Extending default Gitleaks rules for EVM hex private keys and 12-to-24 word English recovery phrases without drowning in transaction hash noise.

  • security
  • gitleaks
  • web3

Default Gitleaks rules catch cloud tokens and PEM blocks, yet miss raw 64-character hexadecimal private keys in .env files and plain-text BIP-39 seed phrases in local notes.

Scanning every bare 64-character hex literal in a blockchain repository fails immediately. Transaction hashes, block hashes, and EVM storage slots all share the exact 32-byte hex format and generate unusable noise.

Rule design

Setting [extend] useDefault = true keeps built-in detectors active while adding two targeted rules in gitleaks-crypto.toml:

Rule ID Target Matching constraint
crypto-private-key-hex 32-byte secp256k1 / EVM private keys Requires an assignment context (privkey, private_key, signer_key, wallet_key, seed, mnemonic) with :, =, =>, or := and extracts the value via secretGroup = 1.
bip39-mnemonic 12 to 24 word English recovery phrases Matches 12 to 24 consecutive lowercase words separated by spaces or tabs drawn strictly from the official 2048-word BIP-39 English list (SHA-256 2f5eed53...).

Staged pre-commit check

Run against staged changes before committing (verified on Gitleaks v8.30.1):

gitleaks git --staged --config gitleaks-crypto.toml --verbose --redact=100

For known public test accounts such as default Hardhat or Anvil keys, suppress verified non-secrets inline with # gitleaks:allow or pin exact finding fingerprints in .gitleaksignore rather than weakening the rule.

Full configuration and allowlist examples live in gitleaks-crypto.