Commit d5b8aea
committed
fix(scan): close cross-scan leak for single-file targets of any format
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.1 parent 7359778 commit d5b8aea
4 files changed
Lines changed: 64 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
503 | 509 | | |
504 | 510 | | |
505 | 511 | | |
506 | | - | |
| 512 | + | |
507 | 513 | | |
508 | 514 | | |
509 | 515 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
| |||
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
| 138 | + | |
137 | 139 | | |
138 | 140 | | |
139 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
15 | 23 | | |
16 | 24 | | |
17 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | | - | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
282 | 283 | | |
283 | 284 | | |
284 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
0 commit comments