feat(redact): add a shannon entropy layer for unknown-vendor secrets - #44
Merged
Conversation
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.
What changed
src/redact/entropy.tswithshannonEntropy, measuring bits per character over a token's own distribution.shannon-entropyrule that slices any token of 24 characters or more reaching 4.5 bits per character, keeping 7 leading characters.slicedAboveEntropytoreplace.ts, so the regex selects candidates and the redactor decides, with no change toRedactionRule.entropy.test.tscovering the function and the rule throughredactSecrets.Why
README.mdalready advertised a Shannon entropy layer and none existed. Every other rule is a known-vendor pattern, so a credential in an in-house format passed through to the model untouched. Measured entropy is the only rule in the set that does not need to know the vendor in advance.How to verify
Ordering matters and is deliberate: the rule runs last. Placing it earlier lets it match a sub-token of a larger blob, redact only the tail, and block
high-entropy-stringfrom catching the rest.high-entropy-stringis kept because it covers tokens with a mid-string=at 4.8 to 5.0 bits that this pattern splits below its floor.The 24-character floor is arithmetic, not a tuned value. Entropy is bounded by
log2(distinct characters), so 4.5 bits is unreachable below 23 characters.entropy.test.tsasserts that property rather than guarding it with a fixture.Data handling
redactSecretsNo new capture source, call site, or file reader. This adds one rule inside
redactionRules, which is reached only throughredactSecretsinsideresolveRedacted. The single gate stays where it is.