cve-lite-cli 1.23.1 → 1.25.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 +56 -0
- package/dist/audit-log/events.js +3 -0
- package/dist/audit-log/handle.js +20 -0
- package/dist/audit-log/index.js +16 -0
- package/dist/audit-log/ndjson-writer.js +28 -0
- package/dist/cli/args.js +71 -3
- package/dist/cli/fix-overrides-hook.js +64 -0
- package/dist/cli/help.js +22 -0
- package/dist/cli/overrides.js +67 -0
- package/dist/index.js +270 -12
- package/dist/osv/cache.js +23 -3
- package/dist/output/formatters.js +23 -4
- package/dist/output/html-reporter.js +34 -4
- package/dist/output/override-findings-html.js +57 -0
- package/dist/output/override-findings-json.js +3 -0
- package/dist/output/override-findings-sarif.js +52 -0
- package/dist/output/override-findings-terminal.js +37 -0
- package/dist/output/printers.js +25 -8
- package/dist/output/sarif.js +77 -8
- package/dist/output/write-outputs.js +7 -3
- package/dist/overrides/api.js +79 -0
- package/dist/overrides/composite.js +23 -0
- package/dist/overrides/context-builder.js +150 -0
- package/dist/overrides/context.js +3 -0
- package/dist/overrides/detectors/index.js +23 -0
- package/dist/overrides/detectors/oa001-orphaned-target.js +36 -0
- package/dist/overrides/detectors/oa002-floating-tag.js +40 -0
- package/dist/overrides/detectors/oa003-wrong-section.js +48 -0
- package/dist/overrides/detectors/oa004-surpassed-pin.js +49 -0
- package/dist/overrides/detectors/oa005-nested-ineffective.js +128 -0
- package/dist/overrides/detectors/oa006-coupled-platform-binary.js +170 -0
- package/dist/overrides/detectors/oa007-frozen-latest.js +69 -0
- package/dist/overrides/detectors/oa008-materialized.js +75 -0
- package/dist/overrides/detectors/platform-binary.js +37 -0
- package/dist/overrides/fixer.js +199 -0
- package/dist/overrides/index.js +5 -0
- package/dist/overrides/parsing/installed-tree.js +164 -0
- package/dist/overrides/parsing/json-pointer.js +8 -0
- package/dist/overrides/parsing/node-modules.js +19 -0
- package/dist/overrides/parsing/package-json.js +139 -0
- package/dist/overrides/parsing/registry.js +66 -0
- package/dist/overrides/types.js +2 -0
- package/dist/parsers/yarn-lock.js +2 -2
- package/dist/remediation/fix-commands.js +110 -29
- package/dist/remediation/npm-registry.js +30 -0
- package/dist/remediation/npm-transitive-resolution.js +2 -2
- package/dist/remediation/transitive-chain-resolver.js +100 -0
- package/dist/scan/multi-folder-scan.js +26 -0
- package/dist/scanner.js +61 -5
- package/dist/types.js +13 -1
- package/dist/utils/baseline.js +16 -0
- package/dist/utils/create-pr.js +19 -4
- package/dist/utils/string.js +34 -0
- package/dist/utils/version.js +115 -0
- package/package.json +4 -2
|
@@ -32,6 +32,10 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
32
32
|
// workspace map is best-effort
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
const devLookup = new Map();
|
|
36
|
+
for (const pkg of scanInput.packages) {
|
|
37
|
+
devLookup.set(`${pkg.name}@${pkg.version}`, pkg.dev ?? false);
|
|
38
|
+
}
|
|
35
39
|
const prioritizedFindings = [...findings]
|
|
36
40
|
.filter(f => f.severity === "critical" || f.severity === "high")
|
|
37
41
|
.sort((a, b) => {
|
|
@@ -115,6 +119,8 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
115
119
|
reason: `Direct upgrade target for ${finding.pkg.name}@${finding.pkg.version}`,
|
|
116
120
|
usage: finding.usage ?? null,
|
|
117
121
|
workspaces: pkgWorkspaces.length > 0 ? pkgWorkspaces : undefined,
|
|
122
|
+
isDev: finding.pkg.dev ?? false,
|
|
123
|
+
fixVersionPublishedAt: finding.fixVersionPublishedAt ?? null,
|
|
118
124
|
});
|
|
119
125
|
}
|
|
120
126
|
else if (finding.fixVersionValidationNote) {
|
|
@@ -161,7 +167,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
161
167
|
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
162
168
|
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
163
169
|
targetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
|
|
164
|
-
displayTargetVersion: "
|
|
170
|
+
displayTargetVersion: "npm install",
|
|
165
171
|
scannedVersions: null,
|
|
166
172
|
knownVulnerableVersions: null,
|
|
167
173
|
kind: "parent-update",
|
|
@@ -172,6 +178,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
172
178
|
reason: finding.recommendedNpmTransitiveRemediation.reason,
|
|
173
179
|
command: buildNpmUpdateCommand(finding.recommendedNpmTransitiveRemediation.package, finding.recommendedNpmTransitiveRemediation.workspaces),
|
|
174
180
|
usage: finding.usage ?? null,
|
|
181
|
+
isDev: devLookup.get(`${finding.recommendedNpmTransitiveRemediation.package}@${finding.recommendedNpmTransitiveRemediation.currentVersion}`) ?? false,
|
|
175
182
|
});
|
|
176
183
|
continue;
|
|
177
184
|
}
|
|
@@ -181,6 +188,9 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
181
188
|
finding.recommendedNpmTransitiveRemediation.targetVersion &&
|
|
182
189
|
isUpgradeTarget(finding.recommendedNpmTransitiveRemediation.currentVersion, finding.recommendedNpmTransitiveRemediation.targetVersion)) {
|
|
183
190
|
const coverage = calculatePathCoverage(finding.dependencyPaths, finding.recommendedNpmTransitiveRemediation.viaPath);
|
|
191
|
+
const chainForNpmRemediation = finding.chainResolution?.directDep === finding.recommendedNpmTransitiveRemediation.package
|
|
192
|
+
? finding.chainResolution
|
|
193
|
+
: null;
|
|
184
194
|
upsertTarget(targetsByPackage, {
|
|
185
195
|
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
186
196
|
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
@@ -197,6 +207,10 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
197
207
|
coveredPaths: coverage.coveredPaths,
|
|
198
208
|
remainingPaths: coverage.remainingPaths,
|
|
199
209
|
usage: finding.usage ?? null,
|
|
210
|
+
isDev: devLookup.get(`${finding.recommendedNpmTransitiveRemediation.package}@${finding.recommendedNpmTransitiveRemediation.currentVersion}`) ?? false,
|
|
211
|
+
chainProof: chainForNpmRemediation?.chain,
|
|
212
|
+
chainSafeVersion: chainForNpmRemediation?.safeVersion,
|
|
213
|
+
chainVulnerablePackage: chainForNpmRemediation ? finding.pkg.name : undefined,
|
|
200
214
|
});
|
|
201
215
|
continue;
|
|
202
216
|
}
|
|
@@ -204,6 +218,9 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
204
218
|
finding.recommendedParentUpgrade &&
|
|
205
219
|
isUpgradeTarget(finding.recommendedParentUpgrade.currentVersion, finding.recommendedParentUpgrade.targetVersion)) {
|
|
206
220
|
const coverage = calculatePathCoverage(finding.dependencyPaths, finding.recommendedParentUpgrade.viaPath);
|
|
221
|
+
const chainForParentUpgrade = finding.chainResolution?.directDep === finding.recommendedParentUpgrade.package
|
|
222
|
+
? finding.chainResolution
|
|
223
|
+
: null;
|
|
207
224
|
upsertTarget(targetsByPackage, {
|
|
208
225
|
package: finding.recommendedParentUpgrade.package,
|
|
209
226
|
currentVersion: finding.recommendedParentUpgrade.currentVersion,
|
|
@@ -220,6 +237,10 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
220
237
|
coveredPaths: coverage.coveredPaths,
|
|
221
238
|
remainingPaths: coverage.remainingPaths,
|
|
222
239
|
usage: finding.usage ?? null,
|
|
240
|
+
isDev: devLookup.get(`${finding.recommendedParentUpgrade.package}@${finding.recommendedParentUpgrade.currentVersion}`) ?? false,
|
|
241
|
+
chainProof: chainForParentUpgrade?.chain,
|
|
242
|
+
chainSafeVersion: chainForParentUpgrade?.safeVersion,
|
|
243
|
+
chainVulnerablePackage: chainForParentUpgrade ? finding.pkg.name : undefined,
|
|
223
244
|
});
|
|
224
245
|
continue;
|
|
225
246
|
}
|
|
@@ -244,7 +265,6 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
244
265
|
package: finding.pkg.name,
|
|
245
266
|
currentVersion: finding.pkg.version,
|
|
246
267
|
targetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
|
|
247
|
-
displayTargetVersion: "lockfile refresh",
|
|
248
268
|
scannedVersions: null,
|
|
249
269
|
knownVulnerableVersions: null,
|
|
250
270
|
kind: "parent-update",
|
|
@@ -260,9 +280,31 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
260
280
|
}
|
|
261
281
|
const primaryParent = getPrimaryParent(finding);
|
|
262
282
|
if (finding.relationship === "transitive" && primaryParent) {
|
|
283
|
+
if (finding.chainResolution) {
|
|
284
|
+
const isDev = devLookup.get(`${finding.chainResolution.directDep}@${finding.chainResolution.directDepCurrentVersion}`) ?? false;
|
|
285
|
+
const coverage = calculatePathCoverage(finding.dependencyPaths, [finding.chainResolution.directDep]);
|
|
286
|
+
upsertTarget(targetsByPackage, {
|
|
287
|
+
package: finding.chainResolution.directDep,
|
|
288
|
+
currentVersion: finding.chainResolution.directDepCurrentVersion,
|
|
289
|
+
targetVersion: finding.chainResolution.targetVersion,
|
|
290
|
+
kind: "parent-upgrade",
|
|
291
|
+
urgent,
|
|
292
|
+
severity: finding.severity,
|
|
293
|
+
adjusted: false,
|
|
294
|
+
adjustmentNote: null,
|
|
295
|
+
reason: buildParentUpgradeReason(finding, coverage),
|
|
296
|
+
command: finding.chainResolution.command,
|
|
297
|
+
chainProof: finding.chainResolution.chain,
|
|
298
|
+
chainSafeVersion: finding.chainResolution.safeVersion,
|
|
299
|
+
chainVulnerablePackage: finding.pkg.name,
|
|
300
|
+
usage: finding.usage ?? null,
|
|
301
|
+
isDev,
|
|
302
|
+
});
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
263
305
|
const fixHint = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
264
306
|
const fixClause = fixHint
|
|
265
|
-
? `
|
|
307
|
+
? ` - check for a release that resolves ${finding.pkg.name} to ${fixHint}+`
|
|
266
308
|
: "";
|
|
267
309
|
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
268
310
|
package: finding.pkg.name,
|
|
@@ -351,7 +393,7 @@ function buildPnpmLockfileRefreshCommand(pkg, workspaces) {
|
|
|
351
393
|
}
|
|
352
394
|
return `pnpm -C ${workspace} update --no-save ${pkg}`;
|
|
353
395
|
}
|
|
354
|
-
function commandPrefix(packageManager) {
|
|
396
|
+
export function commandPrefix(packageManager) {
|
|
355
397
|
if (packageManager === "npm")
|
|
356
398
|
return "npm install";
|
|
357
399
|
if (packageManager === "pnpm")
|
|
@@ -360,6 +402,9 @@ function commandPrefix(packageManager) {
|
|
|
360
402
|
return "bun add";
|
|
361
403
|
return "yarn add";
|
|
362
404
|
}
|
|
405
|
+
function devFlag(packageManager) {
|
|
406
|
+
return packageManager === "bun" ? "--dev" : "-D";
|
|
407
|
+
}
|
|
363
408
|
export function findSuggestedCommandForFinding(plan, finding) {
|
|
364
409
|
const target = plan.targets.find(item => {
|
|
365
410
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
@@ -377,6 +422,10 @@ export function findSuggestedCommandForFinding(plan, finding) {
|
|
|
377
422
|
looksLikeVersion(finding.recommendedParentUpgrade.targetVersion) &&
|
|
378
423
|
compareVersions(item.targetVersion, finding.recommendedParentUpgrade.targetVersion) >= 0);
|
|
379
424
|
}
|
|
425
|
+
if (finding.chainResolution) {
|
|
426
|
+
return (item.package === finding.chainResolution.directDep &&
|
|
427
|
+
item.targetVersion === finding.chainResolution.targetVersion);
|
|
428
|
+
}
|
|
380
429
|
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
381
430
|
return item.package === finding.pkg.name && item.targetVersion === directTarget;
|
|
382
431
|
});
|
|
@@ -389,7 +438,8 @@ export function findSuggestedCommandForFinding(plan, finding) {
|
|
|
389
438
|
if (commands.length > 0)
|
|
390
439
|
return commands.join(" && ");
|
|
391
440
|
}
|
|
392
|
-
|
|
441
|
+
const flag = target.isDev ? ` ${devFlag(plan.packageManager)}` : "";
|
|
442
|
+
return `${commandPrefix(plan.packageManager)}${flag} ${target.package}@${target.targetVersion}`;
|
|
393
443
|
}
|
|
394
444
|
function packageManagerSourceLabel(scanInput) {
|
|
395
445
|
if (scanInput.filePath) {
|
|
@@ -424,6 +474,7 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
424
474
|
: "parent-upgrade",
|
|
425
475
|
displayTargetVersion: existing.displayTargetVersion ?? next.displayTargetVersion,
|
|
426
476
|
command: existing.command ?? next.command,
|
|
477
|
+
isDev: (existing.isDev ?? false) && (next.isDev ?? false),
|
|
427
478
|
workspaces: mergeStringArrays(existing.workspaces, next.workspaces),
|
|
428
479
|
coverage: existing.coverage === "partial" || next.coverage === "partial"
|
|
429
480
|
? "partial"
|
|
@@ -431,6 +482,9 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
431
482
|
coveredPaths: mergePathArrays(existing.coveredPaths ?? [], next.coveredPaths ?? []),
|
|
432
483
|
remainingPaths: mergePathArrays(existing.remainingPaths ?? [], next.remainingPaths ?? []),
|
|
433
484
|
usage: existing.usage || next.usage,
|
|
485
|
+
chainProof: existing.chainProof ?? next.chainProof,
|
|
486
|
+
chainSafeVersion: existing.chainSafeVersion ?? next.chainSafeVersion,
|
|
487
|
+
chainVulnerablePackage: existing.chainVulnerablePackage ?? next.chainVulnerablePackage,
|
|
434
488
|
};
|
|
435
489
|
if (looksLikeVersion(existing.targetVersion) && looksLikeVersion(next.targetVersion)) {
|
|
436
490
|
if (compareVersions(next.targetVersion, existing.targetVersion) > 0) {
|
|
@@ -443,6 +497,7 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
443
497
|
}
|
|
444
498
|
merged.scannedVersions = next.scannedVersions ?? merged.scannedVersions ?? null;
|
|
445
499
|
merged.knownVulnerableVersions = next.knownVulnerableVersions ?? merged.knownVulnerableVersions ?? null;
|
|
500
|
+
merged.fixVersionPublishedAt = next.fixVersionPublishedAt ?? merged.fixVersionPublishedAt ?? null;
|
|
446
501
|
}
|
|
447
502
|
targetsByPackage.set(next.package, merged);
|
|
448
503
|
return;
|
|
@@ -454,6 +509,7 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
454
509
|
merged.adjustmentNote = next.adjustmentNote ?? merged.adjustmentNote;
|
|
455
510
|
merged.scannedVersions = next.scannedVersions ?? merged.scannedVersions ?? null;
|
|
456
511
|
merged.knownVulnerableVersions = next.knownVulnerableVersions ?? merged.knownVulnerableVersions ?? null;
|
|
512
|
+
merged.fixVersionPublishedAt = next.fixVersionPublishedAt ?? merged.fixVersionPublishedAt ?? null;
|
|
457
513
|
}
|
|
458
514
|
targetsByPackage.set(next.package, merged);
|
|
459
515
|
}
|
|
@@ -512,6 +568,11 @@ function buildSections(targets, packageManager) {
|
|
|
512
568
|
{ kind: "parent-update", severity: "medium" },
|
|
513
569
|
{ kind: "parent-update", severity: "low" },
|
|
514
570
|
{ kind: "parent-update", severity: "unknown" },
|
|
571
|
+
{ kind: "validated-chain-upgrade", severity: "critical" },
|
|
572
|
+
{ kind: "validated-chain-upgrade", severity: "high" },
|
|
573
|
+
{ kind: "validated-chain-upgrade", severity: "medium" },
|
|
574
|
+
{ kind: "validated-chain-upgrade", severity: "low" },
|
|
575
|
+
{ kind: "validated-chain-upgrade", severity: "unknown" },
|
|
515
576
|
{ kind: "parent-upgrade", severity: "medium" },
|
|
516
577
|
{ kind: "parent-upgrade", severity: "low" },
|
|
517
578
|
{ kind: "parent-upgrade", severity: "unknown" },
|
|
@@ -520,7 +581,10 @@ function buildSections(targets, packageManager) {
|
|
|
520
581
|
const sectionTargets = targets.filter(target => {
|
|
521
582
|
const targetKind = target.kind === "parent-update"
|
|
522
583
|
? "parent-update"
|
|
523
|
-
: target.urgent ? "urgent"
|
|
584
|
+
: target.urgent ? "urgent"
|
|
585
|
+
: target.adjusted ? "direct-adjusted"
|
|
586
|
+
: target.chainProof !== undefined ? "validated-chain-upgrade"
|
|
587
|
+
: target.kind;
|
|
524
588
|
return targetKind === entry.kind && target.severity === entry.severity;
|
|
525
589
|
});
|
|
526
590
|
if (sectionTargets.length === 0)
|
|
@@ -554,6 +618,9 @@ function buildSectionTitle(kind, severity) {
|
|
|
554
618
|
if (kind === "parent-update") {
|
|
555
619
|
return `${severityTitle} parent updates within range`;
|
|
556
620
|
}
|
|
621
|
+
if (kind === "validated-chain-upgrade") {
|
|
622
|
+
return `${severityTitle} validated chain upgrades`;
|
|
623
|
+
}
|
|
557
624
|
return `${severityTitle} parent upgrades`;
|
|
558
625
|
}
|
|
559
626
|
function groupByWorkspaceKey(targets) {
|
|
@@ -570,32 +637,39 @@ function buildWorkspaceInstallCommands(targets, packageManager) {
|
|
|
570
637
|
const groups = groupByWorkspaceKey(targets);
|
|
571
638
|
const commands = [];
|
|
572
639
|
for (const [wsKey, groupTargets] of groups) {
|
|
573
|
-
const pkgArgs = groupTargets.map(t => `${t.package}@${t.targetVersion}`).join(" ");
|
|
574
640
|
const workspaces = wsKey ? wsKey.split("\0") : [];
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
const
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
commands.push(`yarn add ${pkgArgs}`);
|
|
641
|
+
const devTargets = groupTargets.filter(t => t.isDev);
|
|
642
|
+
const prodTargets = groupTargets.filter(t => !t.isDev);
|
|
643
|
+
for (const [targets, isDev] of [[prodTargets, false], [devTargets, true]]) {
|
|
644
|
+
if (targets.length === 0)
|
|
645
|
+
continue;
|
|
646
|
+
const pkgArgs = targets.map(t => `${t.package}@${t.targetVersion}`).join(" ");
|
|
647
|
+
const flag = isDev ? ` ${devFlag(packageManager)}` : "";
|
|
648
|
+
if (packageManager === "npm") {
|
|
649
|
+
const wsFlags = workspaces.map(ws => `-w ${ws}`).join(" ");
|
|
650
|
+
commands.push(`npm install${flag}${wsFlags ? " " + wsFlags : ""} ${pkgArgs}`);
|
|
586
651
|
}
|
|
587
|
-
else {
|
|
588
|
-
|
|
589
|
-
|
|
652
|
+
else if (packageManager === "pnpm") {
|
|
653
|
+
const wsFlags = workspaces.map(ws => `--filter ./${ws}`).join(" ");
|
|
654
|
+
commands.push(`pnpm add${flag}${wsFlags ? " " + wsFlags : ""} ${pkgArgs}`);
|
|
655
|
+
}
|
|
656
|
+
else if (packageManager === "yarn") {
|
|
657
|
+
if (workspaces.length === 0) {
|
|
658
|
+
commands.push(`yarn add${flag} ${pkgArgs}`);
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
for (const ws of workspaces) {
|
|
662
|
+
commands.push(`yarn workspace ${ws} add${flag} ${pkgArgs}`);
|
|
663
|
+
}
|
|
590
664
|
}
|
|
591
665
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
666
|
+
else if (packageManager === "bun") {
|
|
667
|
+
const wsFlags = workspaces.map(ws => `--filter ${ws}`).join(" ");
|
|
668
|
+
commands.push(`bun add${flag}${wsFlags ? " " + wsFlags : ""} ${pkgArgs}`);
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
commands.push(`${commandPrefix(packageManager)}${flag} ${pkgArgs}`);
|
|
672
|
+
}
|
|
599
673
|
}
|
|
600
674
|
}
|
|
601
675
|
return commands;
|
|
@@ -621,7 +695,14 @@ function buildCommandForTargets(targets, packageManager) {
|
|
|
621
695
|
commandParts.push(...buildWorkspaceInstallCommands(installTargets, packageManager));
|
|
622
696
|
}
|
|
623
697
|
else {
|
|
624
|
-
|
|
698
|
+
const prodInstall = installTargets.filter(t => !t.isDev);
|
|
699
|
+
const devInstall = installTargets.filter(t => t.isDev);
|
|
700
|
+
if (prodInstall.length > 0) {
|
|
701
|
+
commandParts.push(`${commandPrefix(packageManager)} ${prodInstall.map(t => `${t.package}@${t.targetVersion}`).join(" ")}`);
|
|
702
|
+
}
|
|
703
|
+
if (devInstall.length > 0) {
|
|
704
|
+
commandParts.push(`${commandPrefix(packageManager)} ${devFlag(packageManager)} ${devInstall.map(t => `${t.package}@${t.targetVersion}`).join(" ")}`);
|
|
705
|
+
}
|
|
625
706
|
}
|
|
626
707
|
}
|
|
627
708
|
return commandParts.join(" && ");
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
|
+
function getNpmVersionCacheKey(packageName, version) {
|
|
3
|
+
return `${packageName}@${version}`;
|
|
4
|
+
}
|
|
2
5
|
const packumentCache = new Map();
|
|
3
6
|
const DEFAULT_NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
4
7
|
let registryDebugLog;
|
|
@@ -75,6 +78,33 @@ export async function packageVersionExists(packageName, version) {
|
|
|
75
78
|
return null;
|
|
76
79
|
return Boolean(packument.versions && version in packument.versions);
|
|
77
80
|
}
|
|
81
|
+
export async function resolveVersionPublishDate(packageName, version, options) {
|
|
82
|
+
const cacheKey = getNpmVersionCacheKey(packageName, version);
|
|
83
|
+
if (options?.cache && !options.noCache) {
|
|
84
|
+
const cached = options.cache.npmVersionEntries?.[cacheKey];
|
|
85
|
+
if (cached) {
|
|
86
|
+
return { publishedAt: cached.publishedAt, cacheWritten: false };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const packument = await fetchPackument(packageName);
|
|
90
|
+
if (!packument)
|
|
91
|
+
return { publishedAt: null, cacheWritten: false };
|
|
92
|
+
const publishedAt = packument.time?.[version];
|
|
93
|
+
if (!publishedAt)
|
|
94
|
+
return { publishedAt: null, cacheWritten: false };
|
|
95
|
+
let cacheWritten = false;
|
|
96
|
+
if (options?.cache) {
|
|
97
|
+
if (!options.cache.npmVersionEntries) {
|
|
98
|
+
options.cache.npmVersionEntries = {};
|
|
99
|
+
}
|
|
100
|
+
options.cache.npmVersionEntries[cacheKey] = {
|
|
101
|
+
publishedAt,
|
|
102
|
+
cachedAt: new Date().toISOString(),
|
|
103
|
+
};
|
|
104
|
+
cacheWritten = true;
|
|
105
|
+
}
|
|
106
|
+
return { publishedAt, cacheWritten };
|
|
107
|
+
}
|
|
78
108
|
export async function resolvePublishedFixVersion(packageName, fixedVersionHint) {
|
|
79
109
|
const packument = await fetchPackument(packageName);
|
|
80
110
|
if (!packument) {
|
|
@@ -228,11 +228,11 @@ function resolveParentNodeId(args) {
|
|
|
228
228
|
}
|
|
229
229
|
return candidateNodeIds[0] ?? null;
|
|
230
230
|
}
|
|
231
|
-
function highestVersionSatisfyingRange(candidates, rawRange) {
|
|
231
|
+
export function highestVersionSatisfyingRange(candidates, rawRange) {
|
|
232
232
|
const matches = candidates.filter(candidate => versionSatisfiesRange(candidate, rawRange)).sort(compareVersions);
|
|
233
233
|
return matches.at(-1) ?? null;
|
|
234
234
|
}
|
|
235
|
-
function versionSatisfiesRange(version, rawRange) {
|
|
235
|
+
export function versionSatisfiesRange(version, rawRange) {
|
|
236
236
|
const range = rawRange.trim();
|
|
237
237
|
if (!range)
|
|
238
238
|
return false;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { commandPrefix } from "./fix-commands.js";
|
|
2
|
+
import { fetchPackument } from "./npm-registry.js";
|
|
3
|
+
import { compareVersions, looksLikeVersion, isPreReleaseVersion } from "../utils/version.js";
|
|
4
|
+
import { versionSatisfiesRange, highestVersionSatisfyingRange } from "./npm-transitive-resolution.js";
|
|
5
|
+
export async function resolveChainFix(finding, installedVersions, packageManager, options) {
|
|
6
|
+
if (options.offline)
|
|
7
|
+
return null;
|
|
8
|
+
if (finding.relationship !== "transitive")
|
|
9
|
+
return null;
|
|
10
|
+
const fixedVersion = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
11
|
+
if (!fixedVersion)
|
|
12
|
+
return null;
|
|
13
|
+
const uniqueDirectDeps = [...new Set(finding.dependencyPaths
|
|
14
|
+
.filter(path => path.length >= 3)
|
|
15
|
+
.map(path => path[1]))];
|
|
16
|
+
for (const directDepName of uniqueDirectDeps) {
|
|
17
|
+
const directDepCurrentVersion = installedVersions.get(directDepName);
|
|
18
|
+
if (!directDepCurrentVersion)
|
|
19
|
+
continue;
|
|
20
|
+
const packument = await fetchPackument(directDepName);
|
|
21
|
+
if (!packument?.versions)
|
|
22
|
+
continue;
|
|
23
|
+
const candidateVersions = Object.keys(packument.versions)
|
|
24
|
+
.filter(looksLikeVersion)
|
|
25
|
+
.filter(v => !isPreReleaseVersion(v))
|
|
26
|
+
.filter(v => compareVersions(v, directDepCurrentVersion) > 0)
|
|
27
|
+
.sort(compareVersions);
|
|
28
|
+
const pathsForDep = finding.dependencyPaths.filter(p => p[1] === directDepName);
|
|
29
|
+
for (const candidateVersion of candidateVersions) {
|
|
30
|
+
const candidateDeps = packument.versions[candidateVersion]?.dependencies ?? {};
|
|
31
|
+
// hops = everything after the direct dep and before (and including) the vulnerable package
|
|
32
|
+
// For path ["root", "express", "send", "mime-types"]:
|
|
33
|
+
// directDep = path[1] = "express"
|
|
34
|
+
// hops = path.slice(2) = ["send", "mime-types"]
|
|
35
|
+
const hops = pathsForDep[0].slice(2);
|
|
36
|
+
const traced = await traceChain(candidateDeps, hops, finding.pkg.version, fixedVersion);
|
|
37
|
+
if (!traced)
|
|
38
|
+
continue;
|
|
39
|
+
return {
|
|
40
|
+
directDep: directDepName,
|
|
41
|
+
directDepCurrentVersion,
|
|
42
|
+
targetVersion: candidateVersion,
|
|
43
|
+
chain: traced.chain,
|
|
44
|
+
safeVersion: traced.safeVersion,
|
|
45
|
+
command: `${commandPrefix(packageManager)} ${directDepName}@${candidateVersion}`,
|
|
46
|
+
coveredPaths: 1,
|
|
47
|
+
totalPaths: finding.dependencyPaths.length,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
async function traceChain(deps, remainingPath, vulnerableInstalledVersion, fixedVersion) {
|
|
54
|
+
if (remainingPath.length === 0)
|
|
55
|
+
return null;
|
|
56
|
+
const nextName = remainingPath[0];
|
|
57
|
+
const range = deps[nextName];
|
|
58
|
+
if (!range)
|
|
59
|
+
return null;
|
|
60
|
+
if (remainingPath.length === 1) {
|
|
61
|
+
// Bottom of chain: nextName IS the vulnerable package.
|
|
62
|
+
// The range from the parent must exclude the vulnerable installed version.
|
|
63
|
+
if (versionSatisfiesRange(vulnerableInstalledVersion, range)) {
|
|
64
|
+
// Range still allows the vulnerable version - this candidate does not fix it.
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
// Range excludes the vulnerable version - find the highest safe published version.
|
|
68
|
+
const packument = await fetchPackument(nextName);
|
|
69
|
+
if (!packument?.versions)
|
|
70
|
+
return null;
|
|
71
|
+
const candidates = Object.keys(packument.versions)
|
|
72
|
+
.filter(looksLikeVersion)
|
|
73
|
+
.filter(v => !isPreReleaseVersion(v))
|
|
74
|
+
.filter(v => compareVersions(v, fixedVersion) >= 0)
|
|
75
|
+
.sort(compareVersions);
|
|
76
|
+
const safeVersion = highestVersionSatisfyingRange(candidates, range);
|
|
77
|
+
if (!safeVersion)
|
|
78
|
+
return null;
|
|
79
|
+
return { chain: [], safeVersion };
|
|
80
|
+
}
|
|
81
|
+
// Intermediate hop: resolve the highest version of nextName within range, then recurse.
|
|
82
|
+
const packument = await fetchPackument(nextName);
|
|
83
|
+
if (!packument?.versions)
|
|
84
|
+
return null;
|
|
85
|
+
const candidates = Object.keys(packument.versions)
|
|
86
|
+
.filter(looksLikeVersion)
|
|
87
|
+
.filter(v => !isPreReleaseVersion(v))
|
|
88
|
+
.sort(compareVersions);
|
|
89
|
+
const resolvedVersion = highestVersionSatisfyingRange(candidates, range);
|
|
90
|
+
if (!resolvedVersion)
|
|
91
|
+
return null;
|
|
92
|
+
const nextDeps = packument.versions[resolvedVersion]?.dependencies ?? {};
|
|
93
|
+
const result = await traceChain(nextDeps, remainingPath.slice(1), vulnerableInstalledVersion, fixedVersion);
|
|
94
|
+
if (!result)
|
|
95
|
+
return null;
|
|
96
|
+
return {
|
|
97
|
+
chain: [{ name: nextName, version: resolvedVersion }, ...result.chain],
|
|
98
|
+
safeVersion: result.safeVersion,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -12,6 +12,8 @@ import { printMultiFolderResults } from "../output/multi-folder-printer.js";
|
|
|
12
12
|
import { writeMultiFolderHtmlReport } from "../output/multi-folder-html-reporter.js";
|
|
13
13
|
import { chalk } from "../utils/chalk.js";
|
|
14
14
|
import { getCliVersion } from "../utils/version-info.js";
|
|
15
|
+
import { buildOverrideContext, audit } from "../overrides/index.js";
|
|
16
|
+
import { NULL_AUDIT_LOG } from "../audit-log/index.js";
|
|
15
17
|
export async function runMultiFolderScan(params) {
|
|
16
18
|
const searchDepth = Math.max(0, Number(params.options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
17
19
|
const folders = loadMultiplePackages(params.projectRoot, !!params.options.prodOnly, searchDepth);
|
|
@@ -35,6 +37,17 @@ export async function runMultiFolderScan(params) {
|
|
|
35
37
|
const minSeverity = normalizeSeverity(params.options.minSeverity || "medium");
|
|
36
38
|
const tableFindings = params.options.all ? sorted : selectFindingsForTable(sorted, minSeverity);
|
|
37
39
|
const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, scanInput, { offline, subfolder });
|
|
40
|
+
// Override hygiene per folder, mirroring the single-folder --check-overrides path.
|
|
41
|
+
let overrideFindings = [];
|
|
42
|
+
if (params.options.checkOverrides) {
|
|
43
|
+
const overrideCtx = buildOverrideContext(subfolderAbs, {
|
|
44
|
+
auditLog: NULL_AUDIT_LOG,
|
|
45
|
+
logger: { info: () => { }, warn: () => { }, error: () => { }, debug: () => { } },
|
|
46
|
+
checkNetwork: !!params.options.checkNetwork,
|
|
47
|
+
});
|
|
48
|
+
const overrideAudit = await audit(overrideCtx, { checkNetwork: !!params.options.checkNetwork });
|
|
49
|
+
overrideFindings = overrideAudit.findings;
|
|
50
|
+
}
|
|
38
51
|
results.push({
|
|
39
52
|
subfolder,
|
|
40
53
|
scanInput,
|
|
@@ -44,6 +57,7 @@ export async function runMultiFolderScan(params) {
|
|
|
44
57
|
minSeverity,
|
|
45
58
|
tableFindings,
|
|
46
59
|
allPackages: scanInput.packages,
|
|
60
|
+
overrideFindings,
|
|
47
61
|
});
|
|
48
62
|
}
|
|
49
63
|
return results;
|
|
@@ -72,11 +86,23 @@ export async function handleMultiFolderScan(params) {
|
|
|
72
86
|
multiFolder: true,
|
|
73
87
|
folders: results.map(r => r.subfolder),
|
|
74
88
|
findings: allFindings,
|
|
89
|
+
...(params.options.checkOverrides
|
|
90
|
+
? {
|
|
91
|
+
overrideFindings: results.flatMap(r => r.overrideFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
|
|
92
|
+
}
|
|
93
|
+
: {}),
|
|
75
94
|
scannedAt: new Date().toISOString(),
|
|
76
95
|
}, null, 2));
|
|
77
96
|
}
|
|
78
97
|
else {
|
|
79
98
|
printMultiFolderResults(results, params.options);
|
|
99
|
+
if (params.options.checkOverrides) {
|
|
100
|
+
const { renderOverrideFindings } = await import("../output/formatters.js");
|
|
101
|
+
for (const r of results) {
|
|
102
|
+
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${r.subfolder}/`)} ${chalk.gray("override hygiene")}\n`);
|
|
103
|
+
console.log(renderOverrideFindings(r.overrideFindings));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
80
106
|
}
|
|
81
107
|
if (params.options.report) {
|
|
82
108
|
const outputDir = path.resolve(typeof params.options.report === "string" ? params.options.report : "./cve-report");
|