Repository navigation
fix(secrets): judge a string built from constant pieces as one value (#228) - #231
Merged
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.
Summary
A string expression whose parts are all constant (
+of strings,sep.joinof a list or tuple of strings with a constant separator, an f-string whose parts are all constant) is folded once, at the outermost expression.literal_groupsyields it with its constant pieces;SecretDetector.analyzejudges the whole and each piece and reports one finding, the strongest (severity, then confidence), at the span of the whole expression, so a baseline digests every line of it. When the whole value is no finding, its pieces are reported on their own, as before: nothing main reported is lost.literals()still yields every literal (the whole, then its pieces).Before:
PASSWORD = "Zx81kQpL" + "w0RtY7vB" + "n3MsD9cF"andTOKEN = "ghp_" + "…"were not reported, and a private key built with+was reported from its header piece only, so a baseline absorbed a changed body.Verification
New tests in
tests/test_folded_secret_literals.py(red before the fix), including pieces that touch ("AKIA…" + "wJal…"stayshardcoded-secret), a prefix of a chain not judged on its own, and a piece judged when the whole is no secret. Two independent reviews against main on Python 3.11–3.14: no lost or duplicated findings, no new false positives. Full suite green apart from the localtest_packagingenvironment issue; ruff, mypy clean; regression snapshots and the mitmproxy scan (75 findings) unchanged; no slowdown except a chain of several hundred terms that starts with a non-constant term (bounded by the frontend's recursion limit).Closes #228