Fix masking overlap leak (#15) and large-file read-before-check (#16), expand edge-case tests - #17
Merged
Conversation
The previous approach sorted raw values longest-first and repeatedly did result.contains(raw) -> result.replace(raw, mask(raw)) against a mutating string. When two matched secrets on the same line partially overlapped without either containing the other, masking the longer one first consumed characters shared with the shorter one, so the shorter one's exact text no longer existed in `result` and its .contains() check silently skipped masking it -- leaving most of it in plaintext. Rewritten to find every occurrence of every raw value as a byte range in the original line, merge overlapping/adjacent ranges, and rebuild the line in one pass masking each merged range as a block. This can't leave a fragment of any value unmasked regardless of how matches overlap. Fixes #15 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
std::fs::read() loaded a file's full contents into memory before the 5MB cap was checked against bytes.len(), so the cap never actually bounded memory use -- a stray multi-GB file anywhere under the scan target would be read in full regardless. Check entry.metadata().len() first and skip oversized files without reading them at all. Fixes #16 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…nks, deep trees, boundary-spanning secrets Expands builtin_scan/mask coverage beyond the #15/#16 fixes: - empty target dir, empty file - non-UTF8 (corrupt) file content - a directory tree 150 levels deep - a secret split across two separate files (must not be merged) - a secret wrapped across two lines in one file (characterizes the known line-by-line detection limit -- not a leak, just non-detection) - a symlinked file is never followed/read (WalkDir's default), and a directory symlink cycle back to an ancestor does not hang the scan Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Aug 10, 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.
Summary
Adversarial re-audit of the masking logic (
mask()/mask_line_all()/fingerprint()), resource handling, and path handling, done as a follow-up to the earlier masking-leak fixes (#2, #5).mask_line_all()could leave a secret almost entirely in plaintext when it partially overlapped another matched secret on the same line without either containing the other (confirmed with a direct repro before fixing). Rewritten to a byte-range/merge approach that can't leave any covered character unmasked, regardless of overlap shape.builtin_scan()read a file's full contents into memory before checking the 5MB size cap, defeating the cap's purpose for very large files. Now checksentry.metadata().len()first and skips oversized files without reading them.Also checked and found not vulnerable (no fix needed): catastrophic regex backtracking — the
regexcrate guarantees linear-time matching, no PCRE-style backtracking engine; path traversal via scanner-reported paths — raw secret values and scanner-reported file paths never reach any filesystem write call, output paths are only ever the CLI--outarg.Test plan
cargo buildcargo test --all-targets(24/24 passing)cargo clippy --all-targets(0 new warnings vs. main)cargo fmt --all -- --check