Shannon (1948) Entropy, Aho-Corasick (1975) Multi-Pattern Automata & Zero-Upload Git Secret Scanning
Catching leaked credentials after a developer pushes to a cloud Git host means the secret has already traversed the network and entered immutable packfiles. Combining linear-time Aho-Corasick prefix automata with alphabet-calibrated Shannon entropy detects credentials locally before commit.
1. Aho & Corasick (1975) Deterministic Failure-Link Trie (O(N + M + Z))
Given dictionary P = {p_1, ..., p_K} of fixed vendor credential anchors with total pattern length M = sum |p_k|, BFS construction links each trie state s to its longest proper suffix state f(s) and precomputes dense 256-byte DFA transitions delta(s, byte) so every byte of an N-byte diff is read exactly once:
// Precomputed 256-way transition eliminates while-loop failure chasing at scan time:
delta(s, b) = goto(s, b) if goto(s, b) != FAIL
= delta(f(s), b) if s != ROOT
= ROOT if s == ROOT
// Single-pass streaming scan over N bytes with Z total anchor hits:
state = ROOT
for offset, byte in stream:
state = delta(state, byte)
if output[state] != EMPTY:
validate_bounded_nfa_and_checksum(stream, offset, output[state])2. Shannon (1948) Empirical Entropy & Relative Entropy Against Code Priors
For candidate token w of length L over alphabet Sigma (e.g., Base64url |Sigma| = 64 or hexadecimal |Sigma| = 16) with empirical symbol frequencies p(c) = count(c, w) / L and natural source-code character baseline q_code(c):
H(w) = - sum_{c in Sigma, p(c) > 0} p(c) * log_2( p(c) )
D_KL(p || q_code) = sum_{c in Sigma, p(c) > 0} p(c) * log_2( p(c) / q_code(c) )
// Suppress benign SRI sha384-/sha256- digests, lockfile hashes & UUIDv4 fixtures via AST context
is_high_entropy_secret(w, ast_parent) =
!is_integrity_or_fixture_context(ast_parent)
&& ( (is_base64(w) && L >= 24 && H(w) >= 4.5) || (is_hex(w) && L >= 32 && H(w) >= 3.3) )
&& D_KL(p || q_code) >= tau_kl3. Meli, McNiece & Reaves (2019) Packfile Persistence & CRC32 Checksum Gates
Modern structured tokens (such as GitHub ghp_ tokens with trailing Base62 CRC32 checksums) allow deterministic O(L) checksum verification locally—eliminating regex false positives before a secret ever touches a remote Git packfile where Meli et al. (2019) demonstrated historical commits remain permanently exposed until revoked.
4. Enterprise Per-Developer Secret SaaS vs Self-Serve Local Security TCO
Compare multi-year AppSec seat licensing against Destiny’s flat self-serve tiers below, or audit CycloneDX 1.6 manifests and ReDoS bounds free at /tools/sbom-cra-auditor and /tools/unicode-regex-forensics.
Document strict SHA-256 CSP, HSTS preload, and zero third-party ad-tracker compliance.
Shannon Entropy, Aho-Corasick Automata & Secret Scanning — FAQ
Direct answers on Aho-Corasick O(N + M + Z) prefix tries, Shannon & KL-divergence false-positive suppression, Git packfile persistence, and scope.
- Why do high-throughput secret scanners run Aho-Corasick (1975) prefix automata before regular expressions?
- Evaluating 500 separate regular expressions over every line of a multi-gigabyte Git repository scales as O(K * N) or worse under backtracking engines. Aho & Corasick (1975) compile all K vendor token prefixes (such as "sk_live_", "ghp_", "AKIA", and "xoxb-") into a single deterministic finite-state trie with failure links that scans N input bytes in O(N + M + Z) time independent of K, invoking bounded Thompson NFA token validators only around matched anchor offsets.
- Why does raw Shannon (1948) entropy alone produce severe false positives on source code?
- Uniform Base64 tokens reach up to log_2(64) = 6.0 bits/char and hex digests reach log_2(16) = 4.0 bits/char, but legitimate Subresource Integrity SHA-384 hashes, UUIDv4 fixtures, lockfile integrity strings, and long camelCase identifiers also exhibit elevated empirical entropy. Combining alphabet-specific Shannon thresholds with Kullback-Leibler divergence against source-identifier bigram priors and structural AST context suppresses benign hashes without missing unprefixed bearer secrets.
- Why did Meli, McNiece & Reaves (2019) find that deleting a leaked API key in a follow-up Git commit fails to remediate exposure?
- Git stores content-addressed blob objects immutably inside ".git/objects/pack". A subsequent commit that deletes an accidental ".env" file updates the HEAD tree pointer while leaving the historical blob intact and cloneable by anyone with repository read access—requiring immediate cryptographic credential rotation plus history rewriting.
- Does local secret, SBOM, and header scanning replace credential rotation or formal security audits?
- No. Automated pattern and entropy scanning reduces accidental pre-push credential leaks alongside CycloneDX SBOM and CSP3 header checks, while leaked live keys always require immediate provider revocation. Informational engineering guide only; not legal advice.