Repository navigation
Commit c087de7
authored
fix(scanner): classify Windows npx.cmd/uvx.exe as package runners (#1779)
## Problem
The security scanner's source resolver gets the runner name from
`filepath.Base(info.Command)` and compares it exactly against `npx`,
`uvx`, `pnpm` and so on. On Windows the command is commonly `npx.cmd`,
`uvx.exe` or `pnpm.cmd`, so:
- `isPackageRunnerCommand` returns false and the package-cache-first
lookup is skipped. Arg scanning can then pick a data-dir argument (for
example the filesystem server's allowed root) as the server source,
which is the case that ordering exists to prevent.
- The published-package fetch (`resolveFromPackageFetch`) is gated on
the same check, so a quarantined server falls back to a
tool-definitions-only scan.
- `npxTargetPackage` and `uvxTargetPackage` return "".
## Fix
Add `runnerBase(command)`, which returns the lowercased base name with a
`.exe`, `.cmd` or `.bat` suffix removed. Use it everywhere the runner
name is derived: `isPackageRunnerCommand`, `npxTargetPackage`,
`uvxTargetPackage`, `resolveFromPackageCache`, the two
`runnerPackageSpec` calls, and the package-fetch dispatch. Unsuffixed
names are unchanged.
## Test
`TestPackageRunner_WindowsExecutableSuffix` covers `npx.cmd`, `NPX.CMD`,
`uvx.exe` and `pnpm.cmd dlx`, a non-runner `node.exe`, and the npx/uvx
target-package helpers. On main the four runner checks and both target
lookups fail; with this change they pass. `go test -count=1
./internal/security/scanner/` passes.
Made with [Cursor](https://cursor.com)1 parent 6ec9414 commit c087de7
3 files changed
Lines changed: 44 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
575 | 575 | | |
576 | 576 | | |
577 | 577 | | |
578 | | - | |
| 578 | + | |
579 | 579 | | |
580 | 580 | | |
581 | 581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
345 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
346 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
347 | 358 | | |
348 | 359 | | |
349 | 360 | | |
| |||
853 | 864 | | |
854 | 865 | | |
855 | 866 | | |
856 | | - | |
| 867 | + | |
857 | 868 | | |
858 | 869 | | |
859 | 870 | | |
| |||
865 | 876 | | |
866 | 877 | | |
867 | 878 | | |
868 | | - | |
| 879 | + | |
869 | 880 | | |
870 | 881 | | |
871 | 882 | | |
| |||
1364 | 1375 | | |
1365 | 1376 | | |
1366 | 1377 | | |
1367 | | - | |
| 1378 | + | |
1368 | 1379 | | |
1369 | 1380 | | |
1370 | 1381 | | |
| |||
1380 | 1391 | | |
1381 | 1392 | | |
1382 | 1393 | | |
1383 | | - | |
| 1394 | + | |
1384 | 1395 | | |
1385 | 1396 | | |
1386 | 1397 | | |
| |||
1563 | 1574 | | |
1564 | 1575 | | |
1565 | 1576 | | |
1566 | | - | |
| 1577 | + | |
1567 | 1578 | | |
1568 | 1579 | | |
1569 | 1580 | | |
| |||
0 commit comments