Repository navigation
fix(report): keep the leading dot of dot paths in the code region hash - #234
Open
nabeelbaghoor wants to merge 1 commit into
Open
nabeelbaghoor wants to merge 1 commit into
nabeelbaghoor wants to merge 1 commit into
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.
What does this change, and why?
hash_code_regionnormalised the reported path withfile_path.strip().lstrip("./").lstripremoves any run of.and/characters, not a./prefix, so.envbecameenvand.github/workflows/ci.ymlbecamegithub/workflows/ci.yml. The lookup then missed the file and the function returnedNone, so a secret found in.env(or.env.local,.npmrc, ...) and a SAST finding under.github/never got a code region hash and fell back to the path and line key that region hashing was added to replace.This strips only leading
./and/segments, so./app/db.pyand/app/db.pystill resolve toapp/db.pyas before, and dot files and dot directories keep their name.../paths are still rejected.sast._normalize_pathand theonly_filesscope instorage/repository.pyuse the samelstrip("./"), but only as a normalised key on both sides of a comparison, and changing it there would change existing fingerprints, so I left them alone.How to reproduce
Before:
None. After: a SHA-256 hex digest.parse_locationalready returns(".env", "1")for a.env:1location, so the dot was lost only insidehash_code_region.Testing
pytest testspasses: 2426 passed, 11 failed. The same 11 tests fail on untouchedmainin my environment (Rich table wrapping in CLI output, mermaid not vendored, the Claude capture subprocess, one model column check), none of them near this code.ruff check .passes for the changed files (ruff check src/secfoo/report/code_region.py tests/test_report/test_code_region.py: all checks passed);bandit -r src/secfoo/report/code_region.py -c .bandit -ll: no findings.test_hash_code_region_keeps_leading_dot_of_dotfiles_and_dot_dirsfails onmain(assert None is not Nonefor.env) and passes with this change;test_hash_code_region_strips_leading_dot_slash_and_rejects_parentpins the./,/and../handling that must not change.