Repository navigation
Conversation
`tests/test_no_real_home_paths_467.py`'s username detector (detector 2) is deliberately skipped on CI (#472) because there is no general, CI-safe way to tell a contributor's real leaked username apart from a CI provider's own runner account name. #835 reports the side effect: this class of regression can merge to main with a fully green CI run, and #822's own fix (PR #824) demonstrated it -- it scrubbed the file the issue named but reintroduced the same real value into two other files the same commit added, with CI green throughout; #825 repeated the identical shape. Add detector 3: an unconditional, CI-safe hash-based regression guard. `_KNOWN_LEAK_HASHES` holds the SHA-256 hex digest of any value already confirmed to have leaked (never the plaintext); `_known_leak_offenders` scans every git-tracked file for a token matching one of those hashes. It carries none of detector 2's false-positive risk because it depends on neither `CI`/`GITHUB_ACTIONS` nor `getpass.getuser()`, so it runs everywhere, including CI, and would have caught #822's reintroduction into a different file. This does not solve #835's general question -- a genuinely new leak, never seen before, has no hash on the list yet and stays invisible to this detector by construction, so the general problem detector 2 exists for remains open. The module docstring's new "Detector 3" section documents the rationale and how to add an entry after a future incident. Ships with `_KNOWN_LEAK_HASHES` empty; two new tests (`test_known_leak_hash_detector_fires_on_a_planted_leak` and its must-not-fire pair) exercise the real matching function directly so the empty-list state cannot be mistaken for an untested one. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Self-review (Explore + oss:auditor, both against 248e9d9) found a consequential gap: _KNOWN_LEAK_HASHES entries were documented as "hashlib.sha256(leaked_value.encode()).hexdigest()" with no constraint on what "the leaked value" means, but _known_leak_offenders only ever hashes the tokens _LEAK_TOKEN extracts (runs of [A-Za-z0-9_.-]). A maintainer following the old wording literally for a path-shaped leak (exactly what #822 leaked, e.g. "/Users/realname/project") would build an entry that can never match anything -- the tokenizer only ever sees "Users", "realname", "project" as separate tokens, never the whole string -- with no error to say so. That silently defeats the detector's whole purpose for the input shape its own commit message cites as motivation. Add `_leak_hash(token)`, the only supported way to build an entry now: it hashes the token like before but raises ValueError up front when the token is not already a single bare _LEAK_TOKEN unit, turning the mistake into a loud failure at add-time instead of a permanent silent no-op. Two new tests pin both directions (test_leak_hash_rejects_a_value_that_is_not_a_bare_token, test_leak_hash_accepts_a_bare_token); the existing positive/negative controls are rewired through _leak_hash so normal use exercises it too. Also: softened the "forever, on every platform" wording in the unconditional guard test's docstring and the module docstring's Detector 3 section to state the real, narrower scope precisely (exact, case-sensitive, separator-delimited recurrence only -- not a substring or case-variant match), and updated the file's stale opening summary line to mention the new detector's scope alongside the pre-existing path/username ones. Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.
Adds detector 3 -- an unconditional, CI-safe regression guard -- as a complement to
tests/test_no_real_home_paths_467.py's existing username detector (detector 2), which deliberately skips on CI (#472) and has no general CI-safe replacement (the file's own docstring argues at length why not)._KNOWN_LEAK_HASHES(ships empty) holds SHA-256 hex digests of previously-confirmed-leaked values;_known_leak_offendersscans every git-tracked file's_LEAK_TOKEN-shaped tokens for a hash match. It depends on neitherCI/GITHUB_ACTIONSnorgetpass.getuser(), so it runs everywhere including CI. This would have caught #822's exact failure mode: PR #824 scrubbed the file the issue named but reintroduced the same real value into two other files the same commit added, and CI stayed green throughout; #825 repeated the identical shape._leak_hash(token)is the only supported way to build an entry -- it raisesValueErrorup front if the token is not already a bare_LEAK_TOKENunit, so hashing a full leaked path (e.g./Users/realname/project, exactly #822's shape) fails loudly at add-time instead of silently building an entry that can never match anything.What this does not do: it does not solve #835's general question -- detecting a genuinely new, never-before-seen leaked username still has no CI-safe mechanism. This is a narrower, tested complement, not a full resolution, matching the issue's own framing ("a design decision... worth considering, not required"). Whether to close #835 on this narrower fix, or track the general problem separately, is left to the maintainer.
Tests:
tests/test_no_real_home_paths_467.py-- red confirmed via absence (-k known_leakselected 0 tests before implementation), green: 17 passed after. Full repopytestnot run (per developer brief, targeted-lane scope). Python 3.9 syntax checked viaast.parse(feature_version=(3,9)).Review round: two reviewers spawned in parallel against the first commit.
_known_leak_offenders's tokenizer could never match a hashed full-path value (silently defeating the detector for exactly trap.d/804.edit-op-defaulted-to-main-clone-not-worktree.md leaks this maintainer's local checkout paths #822's input shape, now guarded by_leak_hash's ValueError), a MEDIUM scope-overclaim in the docstring (now precise: exact, case-sensitive, separator-delimited recurrence only), and a LOW stale docstring line._known_leak_offenders's per-file read swallowsIsADirectoryError, PermissionError, OSErrorwith a barecontinue, indistinguishable from a clean read. Not fixed here: it mirrors an identical pre-existing swallow in detector 2 (unchanged, not introduced by this diff), is currently unreachable since_KNOWN_LEAK_HASHESships empty, and fixing detector 3 alone would create asymmetry with detector 2's own accepted convention rather than closing a gap unique to this diff. The swallow ships live the day the first hash is added, mirroring detector 2's own pre-existing convention rather than introducing a new one -- at which point it's a one-line fix (log or re-raise) alongside whatever incident triggers that first entry.Addresses #835 (partial -- narrows to already-known-leak recurrence; the general new-leak-detection question stays open, see discussion above)
🤖 Generated with Claude Code
[AI-generated]