Skip to content

fix(#835): CI-safe recurrence guard for previously-leaked values (partial) - #840

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/835
Sep 28, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/835

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

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_offenders scans every git-tracked file's _LEAK_TOKEN-shaped tokens for a hash match. It depends on neither CI/GITHUB_ACTIONS nor getpass.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 raises ValueError up front if the token is not already a bare _LEAK_TOKEN unit, 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_leak selected 0 tests before implementation), green: 17 passed after. Full repo pytest not run (per developer brief, targeted-lane scope). Python 3.9 syntax checked via ast.parse(feature_version=(3,9)).

Review round: two reviewers spawned in parallel against the first commit.

  • Explore reviewer: 3 findings, all fixed -- a HIGH defect where _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.
  • oss:auditor: 1 finding, below-bar -- _known_leak_offenders's per-file read swallows IsADirectoryError, PermissionError, OSError with a bare continue, 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_HASHES ships 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]

fdaviddpt and others added 2 commits September 28, 2026 14:51
`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]>
@fdaviddpt
fdaviddpt merged commit 53e6239 into main Sep 28, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/835 branch September 28, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No CI-safe way to catch a real leaked username reaching main -- the local-only guard cannot run there

1 participant