detect secrets embedded inside larger tokens#2582
Merged
dgageot merged 1 commit intodocker:mainfrom Apr 28, 2026
Merged
Conversation
aheritier
approved these changes
Apr 28, 2026
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.
secretsscan.Redact/ContainsSecretsused to require a word boundaryaround every secret: detection only fired when the recognisable token
sat next to whitespace, punctuation, or the start/end of the input.
That meant values pasted into a larger token leaked through, even when
the prefix and length were a perfect match:
KEY= ghp_…(with space)KEY=ghp_…(no space)or ghp_…BEFOREghp_…AFTER…AKIA…EXAMPLEAFTERThe fix drops the leading
[^0-9a-zA-Z]|^anchor (withoutWordPrefix/
startWord) and the trailing[.,]?(\s+|$)anchor (endSecret)from the rule expressions, plus the equivalent inline anchors on the
alibaba-access-key-id rule. Each rule's payload is already tightly
constrained (fixed-length character classes, explicit token shapes),
so removing the boundary check doesn't broaden the regex enough to
trigger false positives in practice.
Performance is unchanged in shape: the keyword pre-filter still skips
the regex hot path for typical inputs, and Go's RE2-based engine
keeps detection at
O(len(text) · len(rules)). The clean-input andwith-secret benchmarks show the same allocation profile (1 / 4
allocs per op) as before.
Two new tests pin the behaviour:
TestRedactDetectsSecretsAcrossWordBoundariescovers GitHub PAT,AWS access key, and Docker PAT in 12 boundary shapes (alone,
leading alphanumerics, trailing alphanumerics, fully embedded,
mid-
KEY=…, …).TestRedactScalesLinearlyis a guard-rail that fails if a futurechange reintroduces super-linear behaviour: doubling the input ~16×
must not balloon wall time by more than 128×, well below the ~256×
a true
O(n²)regression would produce.