fix(scan): close cross-scan leak for single-file targets of any format#55
Merged
jonathansantilli merged 1 commit intomainfrom Apr 22, 2026
Merged
Conversation
PR #54 disabled the user-scope walk when the CLI scanned a single local file, by gating on `explicitCandidates.length > 0`. That gate breaks for files whose extension is not in `inferTextLikeFormat` — e.g. `.idea/workspace.xml`, `.env` with unusual names, binary-ish configs — because `collectExplicitCandidates` returns `[]` for them, the guard never fires, and sibling user-scope findings (e.g. a hidden-unicode hit in `~/.agents/skills/foo/SKILL.md`) leak into the scan of the unrelated file. Reproducer (0.14.3): $ npx codegate-ai scan ~/workspace/.idea/workspace.xml --format json scan_target: .../.idea/workspace.xml findings: - HIGH rule-file-hidden-unicode file_path: ~/.agents/skills/api-design-guide/domains/rest/SKILL.md ## Fix Add a `stagedFromLocalFile: true` flag to `ResolvedScanTarget`, set from `stageLocalFile`. The CLI gate now uses this flag directly: scan_user_scope = --include-user-scope ? true : stagedFromLocalFile ? false : baseConfig.scan_user_scope It's a signal that doesn't depend on whether the file's extension was recognisable. Covers every file type, no per-format maintenance. ## Tests `tests/scan-target.test.ts`: - Staged `.xml` file gets `stagedFromLocalFile=true` AND empty `explicitCandidates` (the PR #54 gate would have failed here). - Staged `.json` file also gets `stagedFromLocalFile=true` and populated `explicitCandidates` — no regression on the happy path. All 155 files / 722 tests pass. Lint + prettier + typecheck clean.
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
Closes a leftover edge in #54: user-scope findings still leak into scans of single-file targets whose extension isn't in
inferTextLikeFormat(e.g..xml). The gate introduced in #54 relied onexplicitCandidates.length > 0, which is empty for those files.Reproducer on 0.14.3
```
$ npx codegate-ai scan ~/.idea/workspace.xml --format json
findings:
file_path: ~/.agents/skills/api-design-guide/domains/rest/SKILL.md
```
The XML file has nothing to do with the skill; the finding leaks in because the user-scope walker ran unfiltered.
Fix
stageLocalFilenow setsstagedFromLocalFile: trueonResolvedScanTarget. The CLI gate incli.tsuses that flag directly instead ofexplicitCandidates.length > 0. Reliable for any file type.Tests
New cases in
tests/scan-target.test.ts:stageLocalFileon a.xmlproducesstagedFromLocalFile=truewith an emptyexplicitCandidates(reproduces the class of bug).stageLocalFileon a.jsonproducesstagedFromLocalFile=truewith populated candidates (no regression).All 155 files / 722 tests pass. `npm run typecheck`, `npm run lint`, `npx prettier --check` clean.