cve-lite-cli 1.29.0 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/advisory/osv-advisory-source.js +3 -0
- package/dist/cli/help.js +3 -2
- package/dist/cli/validate.js +12 -12
- package/dist/constants.js +1 -0
- package/dist/index.js +29 -2
- package/dist/output/formatters.js +19 -7
- package/dist/output/html-reporter.js +22 -14
- package/dist/output/multi-folder-html-reporter.js +3 -2
- package/dist/output/override-findings-html.js +6 -5
- package/dist/output/override-findings-terminal.js +2 -1
- package/dist/output/printers.js +16 -14
- package/dist/overrides/detectors/oa001-orphaned-target.js +2 -1
- package/dist/overrides/detectors/oa002-floating-tag.js +2 -1
- package/dist/overrides/detectors/oa003-wrong-section.js +2 -1
- package/dist/overrides/detectors/oa004-surpassed-pin.js +2 -1
- package/dist/overrides/detectors/oa005-nested-ineffective.js +2 -1
- package/dist/overrides/detectors/oa006-coupled-platform-binary.js +2 -1
- package/dist/overrides/detectors/oa007-frozen-latest.js +2 -1
- package/dist/overrides/detectors/oa009-stale-floor.js +2 -1
- package/dist/parsers/pnpm-lock.js +22 -7
- package/dist/remediation/fix-commands.js +43 -12
- package/dist/remediation/npm-transitive-resolution.js +5 -6
- package/dist/remediation/package-path-lookup.js +29 -0
- package/dist/remediation/parent-upgrade.js +2 -22
- package/dist/scan/multi-folder-scan.js +18 -3
- package/dist/scanner.js +26 -2
- package/dist/utils/finding.js +28 -0
- package/dist/utils/fix-runner.js +87 -50
- package/dist/utils/severity.js +2 -0
- package/dist/utils/version.js +13 -4
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsonPointer } from '../parsing/json-pointer.js';
|
|
2
2
|
import { compareVersions, looksLikeVersion, satisfiesRange, isValidRange } from '../../utils/version.js';
|
|
3
3
|
import { looksLikePlatformBinary } from './platform-binary.js';
|
|
4
|
+
import { OVERRIDES_COMMAND } from "../../constants.js";
|
|
4
5
|
const RULE_ID = 'OA006';
|
|
5
6
|
/**
|
|
6
7
|
* OA006 - the override target is a package that one or more INSTALLED parents
|
|
@@ -98,7 +99,7 @@ export function detect(ctx) {
|
|
|
98
99
|
fix: {
|
|
99
100
|
type: 'rfc6902',
|
|
100
101
|
patch: patches,
|
|
101
|
-
runnableCommand:
|
|
102
|
+
runnableCommand: `${OVERRIDES_COMMAND} --fix --rule OA006`,
|
|
102
103
|
tier: 'proposed',
|
|
103
104
|
},
|
|
104
105
|
references: ['https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA006.md'],
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { looksLikeVersion, compareVersions } from "../../utils/version.js";
|
|
2
2
|
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
3
|
+
import { OVERRIDES_COMMAND } from "../../constants.js";
|
|
3
4
|
const RULE_ID = "OA007";
|
|
4
5
|
const FLOATING_TAGS = new Set(["latest", "next"]);
|
|
5
6
|
/**
|
|
@@ -60,7 +61,7 @@ export function detect(ctx) {
|
|
|
60
61
|
fix: {
|
|
61
62
|
type: "rfc6902",
|
|
62
63
|
patch: [{ op: "replace", path: jsonPointer(entry.path), value: `>=${registryVersion}` }],
|
|
63
|
-
runnableCommand:
|
|
64
|
+
runnableCommand: `${OVERRIDES_COMMAND} --fix --rule OA007`,
|
|
64
65
|
},
|
|
65
66
|
references: ["https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA007.md"],
|
|
66
67
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
2
2
|
import { looksLikeVersion, coerceVersion, compareVersions } from "../../utils/version.js";
|
|
3
|
+
import { OVERRIDES_COMMAND } from "../../constants.js";
|
|
3
4
|
const RULE_ID = "OA009";
|
|
4
5
|
function majorOf(version) {
|
|
5
6
|
return parseInt(version.split(".")[0] ?? "0", 10);
|
|
@@ -69,7 +70,7 @@ export function detect(ctx) {
|
|
|
69
70
|
fix: {
|
|
70
71
|
type: "rfc6902",
|
|
71
72
|
patch: [{ op: "remove", path: jsonPointer(entry.path) }],
|
|
72
|
-
runnableCommand:
|
|
73
|
+
runnableCommand: `${OVERRIDES_COMMAND} --fix --rule OA009`,
|
|
73
74
|
},
|
|
74
75
|
references: [
|
|
75
76
|
"https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA009.md",
|
|
@@ -48,9 +48,24 @@ function hasProjectImporterSections(document) {
|
|
|
48
48
|
}
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
|
+
// pnpm-lock.yaml is by far the most expensive lockfile to parse (a full YAML document
|
|
52
|
+
// model, ~380ms on a large monorepo), yet a single scan reads it up to four times: the
|
|
53
|
+
// package load, the scanner's workspace map, the suggested-fix workspace map, and override
|
|
54
|
+
// context. Cache the parsed document per (path, mtime, size) so each unchanged lockfile is
|
|
55
|
+
// parsed exactly once. The mtime/size key invalidates automatically after `--fix` rewrites
|
|
56
|
+
// the lockfile, so a re-scan in the same process always sees the fresh contents.
|
|
57
|
+
const parsedLockCache = new Map();
|
|
58
|
+
function readAndParsePnpmLock(filePath) {
|
|
59
|
+
const stat = fs.statSync(filePath);
|
|
60
|
+
const cacheKey = `${filePath}::${stat.mtimeMs}::${stat.size}`;
|
|
61
|
+
if (parsedLockCache.has(cacheKey))
|
|
62
|
+
return parsedLockCache.get(cacheKey);
|
|
63
|
+
const parsed = parsePnpmLockContent(fs.readFileSync(filePath, "utf8"));
|
|
64
|
+
parsedLockCache.set(cacheKey, parsed);
|
|
65
|
+
return parsed;
|
|
66
|
+
}
|
|
51
67
|
export function buildPnpmWorkspaceMap(filePath) {
|
|
52
|
-
const
|
|
53
|
-
const parsed = parsePnpmLockContent(content);
|
|
68
|
+
const parsed = readAndParsePnpmLock(filePath);
|
|
54
69
|
const importers = parsed?.importers ?? {};
|
|
55
70
|
const map = new Map();
|
|
56
71
|
for (const [importerPath, importer] of Object.entries(importers)) {
|
|
@@ -69,8 +84,7 @@ export function buildPnpmWorkspaceMap(filePath) {
|
|
|
69
84
|
return map;
|
|
70
85
|
}
|
|
71
86
|
export function loadFromPnpmLock(filePath, prodOnly) {
|
|
72
|
-
const
|
|
73
|
-
const parsed = parsePnpmLockContent(content);
|
|
87
|
+
const parsed = readAndParsePnpmLock(filePath);
|
|
74
88
|
const majorVersion = parseInt(String(parsed?.lockfileVersion ?? "0"), 10);
|
|
75
89
|
return majorVersion >= 9 ? loadV9(parsed, prodOnly) : loadLegacy(parsed, prodOnly);
|
|
76
90
|
}
|
|
@@ -280,10 +294,11 @@ function parsePnpmPackageKey(key) {
|
|
|
280
294
|
return { key, name, version };
|
|
281
295
|
}
|
|
282
296
|
function parsePnpmPackageKeyV9(key) {
|
|
283
|
-
|
|
297
|
+
// strip leading slash (pnpm v9 can emit /@babel/core@7.20.0) then peer-dep suffix (pkg@1.0.0(peer@2.0.0))
|
|
298
|
+
const cleaned = key.replace(/^\//, "").split("(")[0];
|
|
284
299
|
const idx = cleaned.lastIndexOf("@");
|
|
285
300
|
if (idx <= 0)
|
|
286
|
-
return null; // no @ or @ is the first char
|
|
301
|
+
return null; // no @ or @ is the first char (scoped package name only)
|
|
287
302
|
const name = cleaned.slice(0, idx);
|
|
288
303
|
const version = cleaned.slice(idx + 1);
|
|
289
304
|
if (!name || !version)
|
|
@@ -310,7 +325,7 @@ function normalizePnpmDepRef(depName, depRef) {
|
|
|
310
325
|
}
|
|
311
326
|
function normalizePnpmDepRefV9(depName, depRef) {
|
|
312
327
|
if (typeof depRef === "string") {
|
|
313
|
-
const cleaned = depRef.replace(/^link:/, "").replace(/^workspace:/, "").split("(")[0];
|
|
328
|
+
const cleaned = depRef.replace(/^link:/, "").replace(/^workspace:/, "").replace(/^\//, "").split("(")[0];
|
|
314
329
|
if (!cleaned || cleaned.startsWith(".") || cleaned.startsWith(".."))
|
|
315
330
|
return null;
|
|
316
331
|
if (looksLikeVersion(cleaned))
|
|
@@ -174,7 +174,6 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
174
174
|
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
175
175
|
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
176
176
|
targetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
|
|
177
|
-
displayTargetVersion: "npm install",
|
|
178
177
|
scannedVersions: null,
|
|
179
178
|
knownVulnerableVersions: null,
|
|
180
179
|
kind: "parent-update",
|
|
@@ -198,6 +197,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
198
197
|
const chainForNpmRemediation = finding.chainResolution?.directDep === finding.recommendedNpmTransitiveRemediation.package
|
|
199
198
|
? finding.chainResolution
|
|
200
199
|
: null;
|
|
200
|
+
const npmParentUpgradeWorkspaces = workspaceMap.get(finding.recommendedNpmTransitiveRemediation.package)?.filter(w => w !== ".") ?? [];
|
|
201
201
|
upsertTarget(targetsByPackage, {
|
|
202
202
|
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
203
203
|
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
@@ -215,6 +215,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
215
215
|
remainingPaths: coverage.remainingPaths,
|
|
216
216
|
usage: finding.usage ?? null,
|
|
217
217
|
isDev: devLookup.get(`${finding.recommendedNpmTransitiveRemediation.package}@${finding.recommendedNpmTransitiveRemediation.currentVersion}`) ?? false,
|
|
218
|
+
workspaces: npmParentUpgradeWorkspaces.length > 0 ? npmParentUpgradeWorkspaces : undefined,
|
|
218
219
|
chainProof: chainForNpmRemediation?.chain,
|
|
219
220
|
chainSafeVersion: chainForNpmRemediation?.safeVersion,
|
|
220
221
|
chainVulnerablePackage: chainForNpmRemediation ? finding.pkg.name : undefined,
|
|
@@ -228,6 +229,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
228
229
|
const chainForParentUpgrade = finding.chainResolution?.directDep === finding.recommendedParentUpgrade.package
|
|
229
230
|
? finding.chainResolution
|
|
230
231
|
: null;
|
|
232
|
+
const parentUpgradeWorkspaces = workspaceMap.get(finding.recommendedParentUpgrade.package)?.filter(w => w !== ".") ?? [];
|
|
231
233
|
upsertTarget(targetsByPackage, {
|
|
232
234
|
package: finding.recommendedParentUpgrade.package,
|
|
233
235
|
currentVersion: finding.recommendedParentUpgrade.currentVersion,
|
|
@@ -245,6 +247,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
245
247
|
remainingPaths: coverage.remainingPaths,
|
|
246
248
|
usage: finding.usage ?? null,
|
|
247
249
|
isDev: devLookup.get(`${finding.recommendedParentUpgrade.package}@${finding.recommendedParentUpgrade.currentVersion}`) ?? false,
|
|
250
|
+
workspaces: parentUpgradeWorkspaces.length > 0 ? parentUpgradeWorkspaces : undefined,
|
|
248
251
|
chainProof: chainForParentUpgrade?.chain,
|
|
249
252
|
chainSafeVersion: chainForParentUpgrade?.safeVersion,
|
|
250
253
|
chainVulnerablePackage: chainForParentUpgrade ? finding.pkg.name : undefined,
|
|
@@ -291,6 +294,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
291
294
|
if (finding.chainResolution) {
|
|
292
295
|
const isDev = devLookup.get(`${finding.chainResolution.directDep}@${finding.chainResolution.directDepCurrentVersion}`) ?? false;
|
|
293
296
|
const coverage = calculatePathCoverage(finding.dependencyPaths, [finding.chainResolution.directDep]);
|
|
297
|
+
const chainWorkspaces = workspaceMap.get(finding.chainResolution.directDep)?.filter(w => w !== ".") ?? [];
|
|
294
298
|
upsertTarget(targetsByPackage, {
|
|
295
299
|
package: finding.chainResolution.directDep,
|
|
296
300
|
currentVersion: finding.chainResolution.directDepCurrentVersion,
|
|
@@ -307,6 +311,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
307
311
|
chainVulnerablePackage: finding.pkg.name,
|
|
308
312
|
usage: finding.usage ?? null,
|
|
309
313
|
isDev,
|
|
314
|
+
workspaces: chainWorkspaces.length > 0 ? chainWorkspaces : undefined,
|
|
310
315
|
});
|
|
311
316
|
continue;
|
|
312
317
|
}
|
|
@@ -344,6 +349,17 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
344
349
|
return kindDelta;
|
|
345
350
|
return a.package.localeCompare(b.package);
|
|
346
351
|
});
|
|
352
|
+
// Some install targets carry an explicit `command` built without workspace
|
|
353
|
+
// context (e.g. a chain-resolution command). This raw field is exposed in JSON
|
|
354
|
+
// and embedded in the HTML report, so scope it to the declaring member too -
|
|
355
|
+
// parent-update commands are already workspace-aware and left untouched.
|
|
356
|
+
for (const target of targets) {
|
|
357
|
+
if (target.kind !== "parent-update" && target.command && target.workspaces?.length) {
|
|
358
|
+
const scoped = buildWorkspaceInstallCommands([target], packageManager);
|
|
359
|
+
if (scoped.length > 0)
|
|
360
|
+
target.command = scoped.join(" && ");
|
|
361
|
+
}
|
|
362
|
+
}
|
|
347
363
|
const nowMs = options?.nowMs ?? Date.now();
|
|
348
364
|
if (scanInput.filePath && (packageManager === "npm" || packageManager === "pnpm" || packageManager === "yarn")) {
|
|
349
365
|
const cooldown = readConfiguredCooldown(path.dirname(scanInput.filePath), packageManager);
|
|
@@ -422,7 +438,7 @@ function buildPnpmLockfileRefreshCommand(pkg, workspaces) {
|
|
|
422
438
|
if (workspace === ".") {
|
|
423
439
|
return `pnpm update --no-save ${pkg}`;
|
|
424
440
|
}
|
|
425
|
-
return `pnpm
|
|
441
|
+
return `pnpm --filter ./${workspace} update --no-save ${pkg}`;
|
|
426
442
|
}
|
|
427
443
|
export function commandPrefix(packageManager) {
|
|
428
444
|
if (packageManager === "npm")
|
|
@@ -462,19 +478,32 @@ export function findFixTargetForFinding(plan, finding) {
|
|
|
462
478
|
});
|
|
463
479
|
return target ?? null;
|
|
464
480
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
481
|
+
// The single command that applies (or refreshes) one fix target, workspace-scoped
|
|
482
|
+
// where the target declares a member. Shared by the displayed per-finding command
|
|
483
|
+
// and the --fix executor so both stay consistent.
|
|
484
|
+
export function buildTargetCommand(target, packageManager) {
|
|
485
|
+
// parent-update targets carry an explicit command that is already
|
|
486
|
+
// workspace-scoped (npm update --workspace / pnpm --filter ... update).
|
|
487
|
+
if (target.kind === "parent-update" && target.command)
|
|
470
488
|
return target.command;
|
|
489
|
+
// For install targets (direct / parent-upgrade), a workspace membership must
|
|
490
|
+
// win over any flat explicit command (e.g. a chain-resolution command built
|
|
491
|
+
// without workspace context), mirroring the plan-level command builder.
|
|
471
492
|
if (target.workspaces?.length) {
|
|
472
|
-
const commands = buildWorkspaceInstallCommands([target],
|
|
493
|
+
const commands = buildWorkspaceInstallCommands([target], packageManager);
|
|
473
494
|
if (commands.length > 0)
|
|
474
495
|
return commands.join(" && ");
|
|
475
496
|
}
|
|
476
|
-
|
|
477
|
-
|
|
497
|
+
if (target.command)
|
|
498
|
+
return target.command;
|
|
499
|
+
const flag = target.isDev ? ` ${devFlag(packageManager)}` : "";
|
|
500
|
+
return `${commandPrefix(packageManager)}${flag} ${target.package}@${target.targetVersion}`;
|
|
501
|
+
}
|
|
502
|
+
export function findSuggestedCommandForFinding(plan, finding) {
|
|
503
|
+
const target = findFixTargetForFinding(plan, finding);
|
|
504
|
+
if (!target)
|
|
505
|
+
return null;
|
|
506
|
+
return buildTargetCommand(target, plan.packageManager);
|
|
478
507
|
}
|
|
479
508
|
function packageManagerSourceLabel(scanInput) {
|
|
480
509
|
if (scanInput.filePath) {
|
|
@@ -507,7 +536,6 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
507
536
|
: existing.kind === "parent-update" || next.kind === "parent-update"
|
|
508
537
|
? "parent-update"
|
|
509
538
|
: "parent-upgrade",
|
|
510
|
-
displayTargetVersion: existing.displayTargetVersion ?? next.displayTargetVersion,
|
|
511
539
|
command: existing.command ?? next.command,
|
|
512
540
|
isDev: (existing.isDev ?? false) && (next.isDev ?? false),
|
|
513
541
|
workspaces: mergeStringArrays(existing.workspaces, next.workspaces),
|
|
@@ -690,8 +718,11 @@ function buildWorkspaceInstallCommands(targets, packageManager) {
|
|
|
690
718
|
commands.push(`npm install${flag}${wsFlags ? " " + wsFlags : ""} ${pkgArgs}`);
|
|
691
719
|
}
|
|
692
720
|
else if (packageManager === "pnpm") {
|
|
721
|
+
// pnpm's --filter selector is a CLI-level flag that precedes the command
|
|
722
|
+
// (`pnpm --filter ./client add pkg`), not a trailing argument.
|
|
693
723
|
const wsFlags = workspaces.map(ws => `--filter ./${ws}`).join(" ");
|
|
694
|
-
|
|
724
|
+
const prefix = wsFlags ? `pnpm ${wsFlags} add` : "pnpm add";
|
|
725
|
+
commands.push(`${prefix}${flag} ${pkgArgs}`);
|
|
695
726
|
}
|
|
696
727
|
else if (packageManager === "yarn") {
|
|
697
728
|
if (workspaces.length === 0) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
2
|
import { fetchPackument } from "./npm-registry.js";
|
|
3
3
|
import { findSafeVersionWithinParentRange } from "./npm-transitive-graph.js";
|
|
4
|
+
import { findPackageAlongPath } from "./package-path-lookup.js";
|
|
4
5
|
export async function resolveTransitiveRemediationViaRegistry(args) {
|
|
5
6
|
if (args.finding.relationship !== "transitive")
|
|
6
7
|
return null;
|
|
@@ -14,7 +15,6 @@ export async function resolveTransitiveRemediationViaRegistry(args) {
|
|
|
14
15
|
const vulnerableName = args.finding.pkg.name;
|
|
15
16
|
const fixHint = args.finding.validatedFirstFixedVersion ?? args.finding.firstFixedVersion;
|
|
16
17
|
if (directParentName !== immediateParentName) {
|
|
17
|
-
const packagesByName = new Map(args.packages.map(p => [p.name, p]));
|
|
18
18
|
return resolveWithinRangeForDeepChainViaRegistry({
|
|
19
19
|
immediateParentName,
|
|
20
20
|
vulnerableName,
|
|
@@ -22,7 +22,6 @@ export async function resolveTransitiveRemediationViaRegistry(args) {
|
|
|
22
22
|
fixHint,
|
|
23
23
|
viaPath,
|
|
24
24
|
packages: args.packages,
|
|
25
|
-
packagesByName,
|
|
26
25
|
workspaceMap: args.workspaceMap,
|
|
27
26
|
});
|
|
28
27
|
}
|
|
@@ -70,7 +69,6 @@ export async function resolveNpmTransitiveRemediation(args) {
|
|
|
70
69
|
// immediate parent's declared range for the vulnerable package already covers a safe version.
|
|
71
70
|
// If so, a lockfile refresh of the vulnerable package itself is sufficient.
|
|
72
71
|
if (directParentName !== immediateParentName) {
|
|
73
|
-
const packagesByName = new Map(args.packages.map(p => [p.name, p]));
|
|
74
72
|
return resolveWithinRangeForDeepChain({
|
|
75
73
|
graph: args.graph,
|
|
76
74
|
immediateParentName,
|
|
@@ -79,7 +77,6 @@ export async function resolveNpmTransitiveRemediation(args) {
|
|
|
79
77
|
fixHint,
|
|
80
78
|
viaPath,
|
|
81
79
|
packages: args.packages,
|
|
82
|
-
packagesByName,
|
|
83
80
|
offline: args.offline,
|
|
84
81
|
});
|
|
85
82
|
}
|
|
@@ -305,7 +302,8 @@ function parseCoreVersion(version) {
|
|
|
305
302
|
return [Number(major), Number(minor), Number(patch)];
|
|
306
303
|
}
|
|
307
304
|
async function resolveWithinRangeForDeepChainViaRegistry(args) {
|
|
308
|
-
const
|
|
305
|
+
const immediateParentPathPrefix = args.viaPath.slice(0, -1);
|
|
306
|
+
const immediateParent = findPackageAlongPath(args.packages, args.immediateParentName, immediateParentPathPrefix);
|
|
309
307
|
if (!immediateParent || !looksLikeVersion(immediateParent.version))
|
|
310
308
|
return null;
|
|
311
309
|
const safeCandidates = await findSafeChildCandidates(args.vulnerableName, args.installedVersion, args.fixHint);
|
|
@@ -335,7 +333,8 @@ async function resolveWithinRangeForDeepChainViaRegistry(args) {
|
|
|
335
333
|
};
|
|
336
334
|
}
|
|
337
335
|
async function resolveWithinRangeForDeepChain(args) {
|
|
338
|
-
const
|
|
336
|
+
const immediateParentPathPrefix = args.viaPath.slice(0, -1);
|
|
337
|
+
const immediateParent = findPackageAlongPath(args.packages, args.immediateParentName, immediateParentPathPrefix);
|
|
339
338
|
if (!immediateParent || !looksLikeVersion(immediateParent.version))
|
|
340
339
|
return null;
|
|
341
340
|
const nodeIds = args.graph.nodeIdsFor(args.immediateParentName, immediateParent.version);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function startsWithPath(path, prefix) {
|
|
2
|
+
if (prefix.length > path.length)
|
|
3
|
+
return false;
|
|
4
|
+
for (let i = 0; i < prefix.length; i++) {
|
|
5
|
+
if (path[i] !== prefix[i])
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Finds the specific installed instance of `name` reachable via `pathPrefix`.
|
|
12
|
+
* Cannot use a name-keyed Map here: the same package name is commonly
|
|
13
|
+
* installed at multiple different versions in an npm tree (e.g. minimatch
|
|
14
|
+
* nested under eslint at one version and used top-level at another), and a
|
|
15
|
+
* Map would collapse them to a single arbitrary entry. Path-aware iteration
|
|
16
|
+
* across all installed versions is required to find the one actually on
|
|
17
|
+
* this dependency chain.
|
|
18
|
+
*/
|
|
19
|
+
export function findPackageAlongPath(packages, name, pathPrefix) {
|
|
20
|
+
for (const pkg of packages) {
|
|
21
|
+
if (pkg.name !== name)
|
|
22
|
+
continue;
|
|
23
|
+
const paths = pkg.paths ?? [];
|
|
24
|
+
if (paths.some(path => startsWithPath(path, pathPrefix))) {
|
|
25
|
+
return pkg;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
2
|
import { fetchPackument } from "./npm-registry.js";
|
|
3
|
+
import { findPackageAlongPath } from "./package-path-lookup.js";
|
|
3
4
|
export function isVerifiedUpgrade(confidence) {
|
|
4
5
|
return confidence === "verified";
|
|
5
6
|
}
|
|
@@ -84,28 +85,7 @@ function resolveDirectParentContext(viaPath, packages, directDependencyNames, pa
|
|
|
84
85
|
return { directParentName, immediateParentName, directParent };
|
|
85
86
|
}
|
|
86
87
|
function findPackageVersion(packages, name, pathPrefix) {
|
|
87
|
-
|
|
88
|
-
// multiple versions (e.g. lodash@3 and lodash@4 on different paths), a Map
|
|
89
|
-
// would only hold one entry. We need path-aware iteration across all installed
|
|
90
|
-
// versions to find the right one for this specific dependency chain.
|
|
91
|
-
for (const pkg of packages) {
|
|
92
|
-
if (pkg.name !== name)
|
|
93
|
-
continue;
|
|
94
|
-
const paths = pkg.paths ?? [];
|
|
95
|
-
if (paths.some(path => startsWithPath(path, pathPrefix))) {
|
|
96
|
-
return pkg.version;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
function startsWithPath(path, prefix) {
|
|
102
|
-
if (prefix.length > path.length)
|
|
103
|
-
return false;
|
|
104
|
-
for (let i = 0; i < prefix.length; i++) {
|
|
105
|
-
if (path[i] !== prefix[i])
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
return true;
|
|
88
|
+
return findPackageAlongPath(packages, name, pathPrefix)?.version ?? null;
|
|
109
89
|
}
|
|
110
90
|
/**
|
|
111
91
|
* Highest published, non-prerelease version of `name` that satisfies `range`,
|
|
@@ -9,7 +9,7 @@ import { normalizeSeverity } from "../osv/severity.js";
|
|
|
9
9
|
import { selectFindingsForTable } from "../output/finding-display.js";
|
|
10
10
|
import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
|
|
11
11
|
import { readDirectDependencyNames, hasOverrideEntries } from "../utils/package-json.js";
|
|
12
|
-
import { DEFAULT_SEARCH_DEPTH, severityOrder } from "../constants.js";
|
|
12
|
+
import { DEFAULT_SEARCH_DEPTH, severityOrder, OVERRIDES_COMMAND } from "../constants.js";
|
|
13
13
|
import { printMultiFolderResults } from "../output/multi-folder-printer.js";
|
|
14
14
|
import { printOverrideHint } from "../output/printers.js";
|
|
15
15
|
import { writeMultiFolderHtmlReport } from "../output/multi-folder-html-reporter.js";
|
|
@@ -21,7 +21,7 @@ import { detectDM001 } from "../maintenance/dm001-maintenance-risk.js";
|
|
|
21
21
|
import { reachesFailOn } from "../utils/severity.js";
|
|
22
22
|
import { readBaseline, writeBaseline, filterNewFindings, ratchetOutcome } from "../utils/baseline.js";
|
|
23
23
|
import { pluralize } from "../utils/string.js";
|
|
24
|
-
import { aggregateMultiFolderCompleteness } from "./completeness.js";
|
|
24
|
+
import { aggregateMultiFolderCompleteness, formatDiagnosticMessage, getCompletenessImpact, } from "./completeness.js";
|
|
25
25
|
import { scanProjectForPackageUsage } from "../usage/scanner.js";
|
|
26
26
|
export async function runMultiFolderScan(params) {
|
|
27
27
|
const searchDepth = Math.max(0, Number(params.options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
@@ -120,7 +120,19 @@ export async function runMultiFolderScan(params) {
|
|
|
120
120
|
*/
|
|
121
121
|
function handleMultiFolderRatchet(results, projectRoot, options) {
|
|
122
122
|
let anyNewFindings = false;
|
|
123
|
+
let hasDetectionGaps = false;
|
|
123
124
|
for (const r of results) {
|
|
125
|
+
const { hasDetectionGap } = getCompletenessImpact(r.completeness);
|
|
126
|
+
if (hasDetectionGap) {
|
|
127
|
+
hasDetectionGaps = true;
|
|
128
|
+
console.log(chalk.red(`${r.subfolder}/: Scan data is incomplete. Refusing to create or evaluate a baseline from partial detection data.`));
|
|
129
|
+
for (const diagnostic of r.completeness.diagnostics) {
|
|
130
|
+
if (diagnostic.impact !== "detection")
|
|
131
|
+
continue;
|
|
132
|
+
console.log(chalk.red(` ${formatDiagnosticMessage(diagnostic.code, diagnostic.count, diagnostic.affectedPackageCount)}`));
|
|
133
|
+
}
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
124
136
|
const subfolderAbs = path.join(projectRoot, r.subfolder);
|
|
125
137
|
const baseline = readBaseline(subfolderAbs);
|
|
126
138
|
const outcome = ratchetOutcome(baseline, r.sorted);
|
|
@@ -143,8 +155,11 @@ function handleMultiFolderRatchet(results, projectRoot, options) {
|
|
|
143
155
|
console.log(` ${chalk.yellow(f.severity)} ${f.pkg.name}@${f.pkg.version}${ids ? ` (${ids})` : ""}`);
|
|
144
156
|
}
|
|
145
157
|
}
|
|
158
|
+
if (hasDetectionGaps) {
|
|
159
|
+
return EXIT_ERROR;
|
|
160
|
+
}
|
|
146
161
|
if (options.checkOverrides) {
|
|
147
|
-
console.log(chalk.gray(
|
|
162
|
+
console.log(chalk.gray(`Note: override hygiene (--check-overrides) is not part of the ratchet baseline; run \`${OVERRIDES_COMMAND}\` to audit overrides.`));
|
|
148
163
|
}
|
|
149
164
|
if (anyNewFindings) {
|
|
150
165
|
console.log(chalk.gray("To accept these, re-baseline intentionally by deleting the folder's .cve-lite/baseline.json and re-running --ratchet."));
|
package/dist/scanner.js
CHANGED
|
@@ -267,7 +267,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
267
267
|
const cveAliases = extractCveAliases(vulnerabilities);
|
|
268
268
|
const dependencyPaths = result.pkg.paths ?? [];
|
|
269
269
|
const relationship = classifyRelationship(dependencyPaths, result.pkg.name, context?.directDependencyNames);
|
|
270
|
-
const firstFixedVersion = findFirstFixedVersion(vulnerabilities);
|
|
270
|
+
const firstFixedVersion = findFirstFixedVersion(vulnerabilities, result.pkg.name, result.pkg.ecosystem);
|
|
271
271
|
return {
|
|
272
272
|
pkg: result.pkg,
|
|
273
273
|
vulnerabilities,
|
|
@@ -727,10 +727,34 @@ function classifyRelationship(paths, packageName, directDependencyNames) {
|
|
|
727
727
|
return "direct";
|
|
728
728
|
return "transitive";
|
|
729
729
|
}
|
|
730
|
-
|
|
730
|
+
/**
|
|
731
|
+
* Does this `affected[]` entry describe the package being scanned?
|
|
732
|
+
*
|
|
733
|
+
* Permissive by design, matching `resolveLowestKnownNonVulnerableVersion` in
|
|
734
|
+
* remediation/npm-registry.ts: an entry is excluded only when it positively
|
|
735
|
+
* identifies a *different* package. An entry that omits the name (or the
|
|
736
|
+
* ecosystem) is kept, so an advisory with sparse metadata still contributes
|
|
737
|
+
* its fix rather than silently dropping to "no fix known".
|
|
738
|
+
*/
|
|
739
|
+
function affectedEntryMatchesPackage(affected, packageName, ecosystem) {
|
|
740
|
+
const affectedName = affected.package?.name;
|
|
741
|
+
if (affectedName && affectedName !== packageName)
|
|
742
|
+
return false;
|
|
743
|
+
const affectedEcosystem = affected.package?.ecosystem?.toLowerCase();
|
|
744
|
+
if (affectedEcosystem && affectedEcosystem !== ecosystem.toLowerCase())
|
|
745
|
+
return false;
|
|
746
|
+
return true;
|
|
747
|
+
}
|
|
748
|
+
export function findFirstFixedVersion(vulns, packageName, ecosystem) {
|
|
731
749
|
const fixedVersions = [];
|
|
732
750
|
for (const vuln of vulns) {
|
|
733
751
|
for (const affected of vuln.affected ?? []) {
|
|
752
|
+
// An advisory may list several packages with different fix versions.
|
|
753
|
+
// Without this filter the global minimum across all of them was
|
|
754
|
+
// returned, so a package inherited another package's (lower) fix and
|
|
755
|
+
// the scan reported a version that does not fix it.
|
|
756
|
+
if (!affectedEntryMatchesPackage(affected, packageName, ecosystem))
|
|
757
|
+
continue;
|
|
734
758
|
for (const range of affected.ranges ?? []) {
|
|
735
759
|
for (const event of range.events ?? []) {
|
|
736
760
|
const fixed = event.fixed;
|
package/dist/utils/finding.js
CHANGED
|
@@ -4,3 +4,31 @@ export function getPrimaryParent(finding) {
|
|
|
4
4
|
return null;
|
|
5
5
|
return firstPath[1] ?? null;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Unique root (top-level) dependencies that pull in this package, derived from
|
|
9
|
+
* every known dependencyPaths chain. Paths of length < 3 (direct dependencies,
|
|
10
|
+
* where the package itself is path[1]) are excluded — there is no meaningful
|
|
11
|
+
* root distinct from the package.
|
|
12
|
+
*
|
|
13
|
+
* Gated on relationship === "transitive": a package can be a direct dependency
|
|
14
|
+
* while also being reachable via another root's transitive chain (same
|
|
15
|
+
* resolved version, deduped into one PackageRef). classifyRelationship marks
|
|
16
|
+
* that case "direct", so treat it the same way here rather than surfacing a
|
|
17
|
+
* root that contradicts the Type column.
|
|
18
|
+
*/
|
|
19
|
+
export function getRootDependencies(finding) {
|
|
20
|
+
if (finding.relationship !== "transitive")
|
|
21
|
+
return [];
|
|
22
|
+
const roots = [];
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
for (const path of finding.dependencyPaths ?? []) {
|
|
25
|
+
if (path.length < 3)
|
|
26
|
+
continue;
|
|
27
|
+
const root = path[1];
|
|
28
|
+
if (root && !seen.has(root)) {
|
|
29
|
+
seen.add(root);
|
|
30
|
+
roots.push(root);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return roots;
|
|
34
|
+
}
|