cve-lite-cli 1.28.0 → 1.30.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 +30 -4
- package/dist/advisory/osv-advisory-source.js +3 -0
- package/dist/cli/help.js +3 -2
- package/dist/cli/validate.js +6 -0
- package/dist/constants.js +1 -0
- package/dist/index.js +50 -7
- package/dist/maintenance/dm001-maintenance-risk.js +74 -15
- package/dist/maintenance/score.js +51 -0
- package/dist/output/formatters.js +21 -8
- package/dist/output/html-reporter.js +133 -12
- package/dist/output/maintenance-findings-html.js +4 -0
- package/dist/output/maintenance-findings-sarif.js +58 -0
- package/dist/output/maintenance-terminal.js +63 -5
- package/dist/output/multi-folder-html-reporter.js +64 -7
- package/dist/output/multi-folder-printer.js +11 -2
- package/dist/output/override-findings-html.js +6 -5
- package/dist/output/override-findings-terminal.js +2 -1
- package/dist/output/printers.js +92 -30
- package/dist/output/sarif.js +23 -7
- package/dist/output/write-outputs.js +4 -1
- 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/bun-lock.js +47 -7
- package/dist/parsers/npm-lock-graph.js +90 -12
- package/dist/parsers/pnpm-lock.js +60 -10
- package/dist/parsers/utils.js +0 -15
- package/dist/parsers/yarn-lock.js +140 -58
- package/dist/remediation/fix-commands.js +43 -12
- package/dist/remediation/npm-registry.js +69 -52
- 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/completeness.js +49 -0
- package/dist/scan/multi-folder-scan.js +183 -15
- package/dist/scanner.js +210 -155
- package/dist/usage/scanner.js +12 -2
- package/dist/utils/finding.js +28 -0
- package/dist/utils/fix-runner.js +87 -50
- package/dist/utils/version.js +13 -4
- package/dist/utils/vuln.js +16 -0
- package/package.json +3 -3
|
@@ -2,6 +2,7 @@ import { relative } from "node:path";
|
|
|
2
2
|
import { chalk, stripAnsi } from "../utils/chalk.js";
|
|
3
3
|
import { formatSeverityLabel, SEVERITY_ORDER } from "../utils/severity.js";
|
|
4
4
|
import { pluralize } from "../utils/string.js";
|
|
5
|
+
import { OVERRIDES_COMMAND } from "../constants.js";
|
|
5
6
|
const COL_RULE_MAX = 8;
|
|
6
7
|
const COL_PKG_MAX = 30;
|
|
7
8
|
const COL_MSG_MAX = 50;
|
|
@@ -62,7 +63,7 @@ export function renderOverrideFindings(findings, options) {
|
|
|
62
63
|
if (f.fix?.runnableCommand && !seenRules.has(f.ruleId)) {
|
|
63
64
|
seenRules.add(f.ruleId);
|
|
64
65
|
const cmd = projectInfix
|
|
65
|
-
? f.fix.runnableCommand.replace(
|
|
66
|
+
? f.fix.runnableCommand.replace(OVERRIDES_COMMAND, `cve-lite${projectInfix} overrides`)
|
|
66
67
|
: f.fix.runnableCommand;
|
|
67
68
|
lines.push(chalk.bold.cyan(`> ${cmd}`));
|
|
68
69
|
}
|
package/dist/output/printers.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { chalk, stripAnsi } from "../utils/chalk.js";
|
|
2
2
|
import { buildSuggestedFixCommandPlan, UNVERIFIED_PARENT_UPGRADE_NOTE } from "../remediation/fix-commands.js";
|
|
3
|
-
import {
|
|
3
|
+
import { isBreakingUpgrade } from "../utils/version.js";
|
|
4
4
|
import { getPrimaryParent } from "../utils/finding.js";
|
|
5
|
-
import { countUniqueAdvisories, formatRelationshipLabel, formatRelLabel, formatFixCommandWithPublishDates, formatCooldownWarning, } from "./formatters.js";
|
|
5
|
+
import { countUniqueAdvisories, formatRelationshipLabel, formatRelLabel, formatRootDependencySummary, formatFixCommandWithPublishDates, formatCooldownWarning, } from "./formatters.js";
|
|
6
6
|
import { formatSeverityLabel } from "../utils/severity.js";
|
|
7
7
|
import { pluralize } from "../utils/string.js";
|
|
8
|
+
import { hasMaliciousAdvisory } from "../utils/vuln.js";
|
|
8
9
|
import { selectFindingsForCompact } from "./finding-display.js";
|
|
9
|
-
import {
|
|
10
|
+
import { getCompletenessImpact } from "../scan/completeness.js";
|
|
11
|
+
import { MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE, MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE, MAL_GIT_SOURCE_PINNED_MESSAGE, MAL_GIT_SOURCE_FLOATING_MESSAGE, MAL_GIT_SOURCE_COMPACT_MESSAGE, MAL_GIT_SOURCE_LEGEND_MESSAGE, MAL_GIT_SOURCE_PINNED_DISPLAY, MAL_GIT_SOURCE_FLOATING_DISPLAY, OVERRIDES_COMMAND, } from "../constants.js";
|
|
10
12
|
export function printSummary(findings, packageCount, scanInput) {
|
|
11
13
|
if (findings.length === 0) {
|
|
12
14
|
if (scanInput.mode === "manifest-fallback") {
|
|
@@ -44,8 +46,8 @@ export function printActionSummary(findings, overrideCount = 0, packageManager)
|
|
|
44
46
|
console.log(`- ${chalk.gray("Package manager:")} ${packageManager}`);
|
|
45
47
|
}
|
|
46
48
|
if (findings.length > 0) {
|
|
47
|
-
console.log(`- ${chalk.green(String(direct))} vulnerable ${pluralize(direct, "package")} look directly fixable in this project.`);
|
|
48
|
-
console.log(`- ${chalk.yellow(String(transitive))} ${pluralize(transitive, "issue")} come through other dependencies.`);
|
|
49
|
+
console.log(`- ${chalk.green(String(direct))} vulnerable ${pluralize(direct, "package")} ${direct === 1 ? "looks" : "look"} directly fixable in this project.`);
|
|
50
|
+
console.log(`- ${chalk.yellow(String(transitive))} ${pluralize(transitive, "issue")} ${transitive === 1 ? "comes" : "come"} through other dependencies.`);
|
|
49
51
|
if (unknown > 0) {
|
|
50
52
|
console.log(`- ${chalk.magenta(String(unknown))} ${pluralize(unknown, "package")} could not be clearly classified as direct or transitive.`);
|
|
51
53
|
}
|
|
@@ -53,7 +55,7 @@ export function printActionSummary(findings, overrideCount = 0, packageManager)
|
|
|
53
55
|
console.log(`- ${chalk.blue(String(fixable))} ${pluralize(fixable, "package")} include a fixed-version hint from OSV.`);
|
|
54
56
|
}
|
|
55
57
|
if (overrideCount > 0) {
|
|
56
|
-
console.log(`- ${chalk.yellow(String(overrideCount))} override hygiene ${pluralize(overrideCount, "issue")} found. Run ${chalk.white(
|
|
58
|
+
console.log(`- ${chalk.yellow(String(overrideCount))} override hygiene ${pluralize(overrideCount, "issue")} found. Run ${chalk.white(`${OVERRIDES_COMMAND} --fix`)} to address ${pluralize(overrideCount, "it", "them")}.`);
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
function printCooldownWarning(target) {
|
|
@@ -191,7 +193,7 @@ export function printSkippedDependencies(skipped) {
|
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
export function printTable(findings, threshold, skippedKeys) {
|
|
194
|
-
const headers = ["Package", "Version", "Severity", "Type", "Usage", "Fixed", "IDs"];
|
|
196
|
+
const headers = ["Package", "Version", "Severity", "Type", "Root", "Usage", "Fixed", "IDs"];
|
|
195
197
|
const rawRows = findings.map(f => {
|
|
196
198
|
let usageText = "n/a";
|
|
197
199
|
if (f.usage) {
|
|
@@ -212,7 +214,7 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
212
214
|
else if (f.maliciousGitSource) {
|
|
213
215
|
fixedDisplay = chalk.yellow(f.maliciousGitSourcePinned ? MAL_GIT_SOURCE_PINNED_DISPLAY : MAL_GIT_SOURCE_FLOATING_DISPLAY);
|
|
214
216
|
}
|
|
215
|
-
else if (f.vulnerabilities
|
|
217
|
+
else if (hasMaliciousAdvisory(f.vulnerabilities)) {
|
|
216
218
|
fixedDisplay = chalk.yellow("⚠ Malicious");
|
|
217
219
|
}
|
|
218
220
|
else {
|
|
@@ -223,6 +225,7 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
223
225
|
f.pkg.version,
|
|
224
226
|
f.severity,
|
|
225
227
|
formatRelLabel(f),
|
|
228
|
+
formatRootDependencySummary(f),
|
|
226
229
|
usageText,
|
|
227
230
|
fixedDisplay,
|
|
228
231
|
f.vulnerabilities.map(v => v.id).join(", ")
|
|
@@ -238,7 +241,7 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
238
241
|
console.log(renderRow(headers, widths));
|
|
239
242
|
console.log(line("├", "┼", "┤"));
|
|
240
243
|
for (const row of rawRows) {
|
|
241
|
-
let usageDecorated = String(row[
|
|
244
|
+
let usageDecorated = String(row[5]);
|
|
242
245
|
if (usageDecorated.includes("file(s)"))
|
|
243
246
|
usageDecorated = chalk.red(usageDecorated);
|
|
244
247
|
else if (usageDecorated.includes("unused"))
|
|
@@ -250,14 +253,15 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
250
253
|
row[1],
|
|
251
254
|
formatSeverityLabel(String(row[2])),
|
|
252
255
|
formatRelationshipLabel(String(row[3])),
|
|
256
|
+
row[4],
|
|
253
257
|
usageDecorated,
|
|
254
|
-
row[
|
|
255
|
-
row[
|
|
258
|
+
row[6],
|
|
259
|
+
row[7]
|
|
256
260
|
];
|
|
257
261
|
console.log(renderRow(decorated, widths));
|
|
258
262
|
}
|
|
259
263
|
console.log(line("└", "┴", "┘"));
|
|
260
|
-
const maliciousFindings = findings.filter(f => f.vulnerabilities
|
|
264
|
+
const maliciousFindings = findings.filter(f => hasMaliciousAdvisory(f.vulnerabilities));
|
|
261
265
|
if (maliciousFindings.length > 0) {
|
|
262
266
|
console.log("");
|
|
263
267
|
console.log(chalk.bold.red("⚠ Malicious package advisory:"));
|
|
@@ -285,28 +289,49 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
285
289
|
console.log(chalk.gray("Tip: use --all to include low findings, or --min-severity high to focus only on urgent issues."));
|
|
286
290
|
}
|
|
287
291
|
}
|
|
288
|
-
export function printFinalStatus(findings, overrideCount = 0) {
|
|
292
|
+
export function printFinalStatus(findings, overrideCount = 0, completeness) {
|
|
289
293
|
console.log("");
|
|
290
294
|
console.log(chalk.gray("────────────────────────────────"));
|
|
295
|
+
const { hasDetectionGap, hasRemediationGap } = getCompletenessImpact(completeness);
|
|
291
296
|
const overrideSuffix = overrideCount > 0
|
|
292
297
|
? `, ${overrideCount} override hygiene ${pluralize(overrideCount, "issue")}`
|
|
293
298
|
: "";
|
|
294
299
|
if (findings.length === 0) {
|
|
295
|
-
if (
|
|
300
|
+
if (hasDetectionGap) {
|
|
301
|
+
const overrideNote = overrideCount > 0
|
|
302
|
+
? ` ${overrideCount} override hygiene ${pluralize(overrideCount, "issue")} detected.`
|
|
303
|
+
: "";
|
|
304
|
+
console.log(chalk.yellow(`⚠ Partial scan: vulnerability findings may be incomplete.${overrideNote}`));
|
|
305
|
+
}
|
|
306
|
+
else if (overrideCount > 0) {
|
|
296
307
|
console.log(chalk.yellow(`▲ Scan complete. No known vulnerabilities found, but ${overrideCount} override hygiene ${pluralize(overrideCount, "issue")} detected.`));
|
|
297
308
|
}
|
|
298
309
|
else {
|
|
299
310
|
console.log(chalk.greenBright("✔ Scan complete. No known vulnerabilities found."));
|
|
300
311
|
}
|
|
301
|
-
return;
|
|
302
312
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
313
|
+
else {
|
|
314
|
+
const criticalCount = findings.filter(f => f.severity === "critical").length;
|
|
315
|
+
const highCount = findings.filter(f => f.severity === "high").length;
|
|
316
|
+
const urgent = criticalCount > 0 || highCount > 0;
|
|
317
|
+
const label = `${findings.length} ${pluralize(findings.length, "vulnerability", "vulnerabilities")}`;
|
|
318
|
+
if (hasDetectionGap) {
|
|
319
|
+
const severityNote = urgent ? ` (${criticalCount} critical, ${highCount} high)` : "";
|
|
320
|
+
const action = urgent ? "Start with the priority fixes above." : "Review the suggested fix plan above.";
|
|
321
|
+
const renderStatus = urgent ? chalk.redBright : chalk.yellow;
|
|
322
|
+
console.log(renderStatus(`⚠ Partial scan: ${label} found${overrideSuffix}${severityNote}. Vulnerability findings may be incomplete. ${action}`));
|
|
323
|
+
}
|
|
324
|
+
else if (urgent) {
|
|
325
|
+
console.log(chalk.redBright(`✖ Scan complete. ${label}${overrideSuffix} found (${criticalCount} critical, ${highCount} high). Start with the priority fixes above.`));
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
console.log(chalk.yellow(`▲ Scan complete. ${label}${overrideSuffix} found. Review the suggested fix plan above.`));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (hasRemediationGap) {
|
|
332
|
+
console.log(chalk.yellow("⚠ Remediation guidance is incomplete."));
|
|
308
333
|
}
|
|
309
|
-
|
|
334
|
+
printIncompleteDiagnostics(completeness);
|
|
310
335
|
}
|
|
311
336
|
export function printOverrideHint() {
|
|
312
337
|
console.log("💡 " + chalk.gray("Tip:") + " override entries detected - run with --check-overrides to audit them for stale or broken overrides.");
|
|
@@ -361,12 +386,26 @@ function wrapCell(value, width) {
|
|
|
361
386
|
}
|
|
362
387
|
export function printCompactOutput(findings, scanInput, options) {
|
|
363
388
|
console.log("");
|
|
389
|
+
const { hasDetectionGap, hasRemediationGap } = getCompletenessImpact(options?.completeness);
|
|
364
390
|
if (options?.packageManager) {
|
|
365
391
|
console.log(chalk.gray("Package manager: ") + options.packageManager);
|
|
366
392
|
}
|
|
367
393
|
if (findings.length === 0) {
|
|
368
|
-
|
|
369
|
-
|
|
394
|
+
if (hasDetectionGap) {
|
|
395
|
+
console.log(chalk.yellow("⚠ Partial scan: vulnerability findings may be incomplete."));
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
console.log(chalk.greenBright("✔ Scan complete. No known vulnerabilities found."));
|
|
399
|
+
}
|
|
400
|
+
if (hasRemediationGap) {
|
|
401
|
+
console.log(chalk.yellow("⚠ Remediation guidance is incomplete."));
|
|
402
|
+
}
|
|
403
|
+
if (options?.completeness?.complete === false) {
|
|
404
|
+
printIncompleteDiagnostics(options.completeness);
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
console.log("");
|
|
408
|
+
}
|
|
370
409
|
return;
|
|
371
410
|
}
|
|
372
411
|
// Vulnerabilities found section
|
|
@@ -394,7 +433,7 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
394
433
|
}
|
|
395
434
|
console.log(`${formatSeverityLabel(sevLabel)} ${chalk.whiteBright(finding.pkg.name)}@${finding.pkg.version}`);
|
|
396
435
|
console.log(` ${typeLabel}${usageContext}`);
|
|
397
|
-
const isMalicious = finding.vulnerabilities
|
|
436
|
+
const isMalicious = hasMaliciousAdvisory(finding.vulnerabilities);
|
|
398
437
|
if (isMalicious) {
|
|
399
438
|
if (finding.maliciousUnverifiable) {
|
|
400
439
|
console.log(` ${chalk.yellow(`⚠ Unverifiable (private source) - ${MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE}`)}`);
|
|
@@ -506,7 +545,7 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
506
545
|
console.log(`${chalk.cyan(String(direct))} ${chalk.white("direct")}` +
|
|
507
546
|
`${chalk.gray(" · ")}` +
|
|
508
547
|
`${chalk.cyan(String(transitive))} ${chalk.white("transitive")}`);
|
|
509
|
-
const maliciousCompact = findings.filter(f => f.vulnerabilities
|
|
548
|
+
const maliciousCompact = findings.filter(f => hasMaliciousAdvisory(f.vulnerabilities));
|
|
510
549
|
if (maliciousCompact.length > 0 && !options?.all) {
|
|
511
550
|
console.log("");
|
|
512
551
|
console.log(chalk.bold.red("⚠ Malicious package advisory:"));
|
|
@@ -533,7 +572,14 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
533
572
|
}
|
|
534
573
|
// Footer
|
|
535
574
|
const urgentCount = counts.critical + counts.high;
|
|
536
|
-
if (
|
|
575
|
+
if (hasDetectionGap) {
|
|
576
|
+
const label = urgentCount > 0
|
|
577
|
+
? `${urgentCount} urgent ${pluralize(urgentCount, "issue")} found`
|
|
578
|
+
: `${findings.length} ${pluralize(findings.length, "issue")} found`;
|
|
579
|
+
const renderStatus = urgentCount > 0 ? chalk.redBright : chalk.yellow;
|
|
580
|
+
console.log(renderStatus(`⚠ Partial scan: ${label}. Vulnerability findings may be incomplete.`));
|
|
581
|
+
}
|
|
582
|
+
else if (urgentCount > 0) {
|
|
537
583
|
console.log(chalk.redBright(`✖ Scan complete. ${urgentCount} urgent ${pluralize(urgentCount, "issue")} found.`));
|
|
538
584
|
}
|
|
539
585
|
else {
|
|
@@ -542,7 +588,23 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
542
588
|
if (!options?.all) {
|
|
543
589
|
console.log(chalk.gray(`Run with ${chalk.whiteBright("--verbose")} for fix plan, paths, and full table.`));
|
|
544
590
|
}
|
|
591
|
+
if (hasRemediationGap) {
|
|
592
|
+
console.log(chalk.yellow("⚠ Remediation guidance is incomplete."));
|
|
593
|
+
}
|
|
594
|
+
printIncompleteDiagnostics(options?.completeness);
|
|
595
|
+
if (options?.completeness?.complete !== false) {
|
|
596
|
+
console.log("");
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
export function printIncompleteDiagnostics(completeness) {
|
|
600
|
+
if (!completeness || completeness.complete)
|
|
601
|
+
return;
|
|
545
602
|
console.log("");
|
|
603
|
+
for (const diag of completeness.diagnostics) {
|
|
604
|
+
const prefix = diag.impact === "detection" ? chalk.yellow(" ·") : chalk.gray(" ·");
|
|
605
|
+
console.log(prefix + " " + chalk.gray(diag.message));
|
|
606
|
+
}
|
|
607
|
+
console.log(chalk.gray(" Resolve the issues above and re-run the scan."));
|
|
546
608
|
}
|
|
547
609
|
function renderSeverityTable(counts) {
|
|
548
610
|
const labels = ["Critical", "High", "Medium", "Low", "Unknown"];
|
|
@@ -626,7 +688,7 @@ function printDirectTargetsTable(targets, remainingNotes, validationSummary, wid
|
|
|
626
688
|
remainingNotes.push(target.adjustmentNote);
|
|
627
689
|
}
|
|
628
690
|
}
|
|
629
|
-
const isBreaking = !!target.currentVersion &&
|
|
691
|
+
const isBreaking = !!target.currentVersion && isBreakingUpgrade(target.currentVersion, target.targetVersion);
|
|
630
692
|
let usageText = chalk.gray("n/a");
|
|
631
693
|
if (target.usage) {
|
|
632
694
|
usageText = target.usage.imported ? chalk.red(`${target.usage.files.length} file(s)`) : chalk.green("unused");
|
|
@@ -683,7 +745,7 @@ function printParentUpgradeTargetsTable(targets, widthsOverride) {
|
|
|
683
745
|
return [
|
|
684
746
|
target.package,
|
|
685
747
|
target.currentVersion ?? "-",
|
|
686
|
-
chalk.cyan(target.
|
|
748
|
+
chalk.cyan(target.targetVersion),
|
|
687
749
|
usageText,
|
|
688
750
|
chalk.gray(target.reason),
|
|
689
751
|
];
|
|
@@ -717,7 +779,7 @@ function computeSharedDirectTableWidths(sections) {
|
|
|
717
779
|
const rows = [];
|
|
718
780
|
for (const section of directSections) {
|
|
719
781
|
for (const target of section.targets) {
|
|
720
|
-
const isBreaking = !!target.currentVersion &&
|
|
782
|
+
const isBreaking = !!target.currentVersion && isBreakingUpgrade(target.currentVersion, target.targetVersion);
|
|
721
783
|
let usageText = "n/a";
|
|
722
784
|
if (target.usage) {
|
|
723
785
|
usageText = target.usage.imported ? `${target.usage.files.length} file(s)` : "unused";
|
|
@@ -755,7 +817,7 @@ function computeSharedParentUpgradeTableWidths(sections) {
|
|
|
755
817
|
rows.push([
|
|
756
818
|
target.package,
|
|
757
819
|
target.currentVersion ?? "-",
|
|
758
|
-
target.
|
|
820
|
+
target.targetVersion,
|
|
759
821
|
usageText,
|
|
760
822
|
target.reason,
|
|
761
823
|
]);
|
package/dist/output/sarif.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { findFixTargetForFinding } from "../remediation/fix-commands.js";
|
|
4
|
+
import { getRecommendedAction, formatCooldownWarning } from "./formatters.js";
|
|
4
5
|
import { getCliVersion } from "../utils/version-info.js";
|
|
5
6
|
import { severityToSarifLevel } from "../utils/severity.js";
|
|
6
7
|
import { sarifFingerprintHash } from "../utils/sarif.js";
|
|
7
8
|
import { buildOverrideSarifComponent, buildOverrideSarifResults } from "./override-findings-sarif.js";
|
|
9
|
+
import { buildMaintenanceSarifComponent, buildMaintenanceSarifResults } from "./maintenance-findings-sarif.js";
|
|
8
10
|
const SARIF_SCHEMA = "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json";
|
|
9
11
|
const LOCKFILE_NAMES = {
|
|
10
12
|
"package-lock": "package-lock.json",
|
|
@@ -75,13 +77,17 @@ export function deriveLockfileUri(scanInput) {
|
|
|
75
77
|
return path.basename(scanInput.filePath);
|
|
76
78
|
return LOCKFILE_NAMES[scanInput.source] ?? "lockfile";
|
|
77
79
|
}
|
|
78
|
-
export function buildSarifOutput(findings, lockfileUri, version,
|
|
80
|
+
export function buildSarifOutput(findings, lockfileUri, version, plan, overrideFindings, maintenanceFindings) {
|
|
79
81
|
const ruleMap = new Map();
|
|
80
82
|
const ruleIndexMap = new Map();
|
|
81
83
|
const results = [];
|
|
82
84
|
for (const finding of findings) {
|
|
83
85
|
const level = severityToSarifLevel(finding.severity);
|
|
84
86
|
const action = getRecommendedAction(finding);
|
|
87
|
+
// If the recommended fix for this finding lands on a version inside the
|
|
88
|
+
// project's configured release cooldown, surface that on the result so it
|
|
89
|
+
// reaches Code Scanning (message text for humans, property for tooling).
|
|
90
|
+
const cooldown = plan ? findFixTargetForFinding(plan, finding)?.cooldownWarning ?? null : null;
|
|
85
91
|
const location = {
|
|
86
92
|
physicalLocation: {
|
|
87
93
|
artifactLocation: { uri: lockfileUri, uriBaseId: "%SRCROOT%" },
|
|
@@ -116,20 +122,30 @@ export function buildSarifOutput(findings, lockfileUri, version, _plan, override
|
|
|
116
122
|
kind: "open",
|
|
117
123
|
level,
|
|
118
124
|
message: {
|
|
119
|
-
text: `${finding.pkg.name}@${finding.pkg.version} is vulnerable (${finding.severity}). ${action}
|
|
125
|
+
text: `${finding.pkg.name}@${finding.pkg.version} is vulnerable (${finding.severity}). ${action}`
|
|
126
|
+
+ (cooldown ? ` Release cooldown: ${formatCooldownWarning(cooldown)}` : ""),
|
|
120
127
|
},
|
|
121
128
|
locations: [location],
|
|
122
129
|
partialFingerprints: {
|
|
123
130
|
primaryLocationLineHash: sarifFingerprintHash(`${ruleId}:${finding.pkg.name}@${finding.pkg.version}`),
|
|
124
131
|
},
|
|
132
|
+
...(cooldown ? { properties: { cooldownWarning: cooldown } } : {}),
|
|
125
133
|
});
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
const hasOverrides = overrideFindings != null && overrideFindings.length > 0;
|
|
129
|
-
const
|
|
137
|
+
const hasMaintenance = maintenanceFindings != null && maintenanceFindings.length > 0;
|
|
138
|
+
const extensions = [
|
|
139
|
+
...(hasOverrides ? [buildOverrideSarifComponent()] : []),
|
|
140
|
+
...(hasMaintenance ? [buildMaintenanceSarifComponent()] : []),
|
|
141
|
+
];
|
|
142
|
+
const maintenanceExtensionIndex = hasOverrides ? 1 : 0;
|
|
130
143
|
const allResults = [
|
|
131
144
|
...results,
|
|
132
145
|
...(hasOverrides ? buildOverrideSarifResults(overrideFindings) : []),
|
|
146
|
+
...(hasMaintenance
|
|
147
|
+
? buildMaintenanceSarifResults(maintenanceFindings, lockfileUri, maintenanceExtensionIndex)
|
|
148
|
+
: []),
|
|
133
149
|
];
|
|
134
150
|
return {
|
|
135
151
|
$schema: SARIF_SCHEMA,
|
|
@@ -143,7 +159,7 @@ export function buildSarifOutput(findings, lockfileUri, version, _plan, override
|
|
|
143
159
|
informationUri: "https://owasp.org/cve-lite-cli/",
|
|
144
160
|
rules: Array.from(ruleMap.values()),
|
|
145
161
|
},
|
|
146
|
-
...(extensions ? { extensions } : {}),
|
|
162
|
+
...(extensions.length > 0 ? { extensions } : {}),
|
|
147
163
|
},
|
|
148
164
|
results: allResults,
|
|
149
165
|
artifacts: [
|
|
@@ -153,11 +169,11 @@ export function buildSarifOutput(findings, lockfileUri, version, _plan, override
|
|
|
153
169
|
],
|
|
154
170
|
};
|
|
155
171
|
}
|
|
156
|
-
export function writeSarifReport(findings, lockfileUri, plan, overrideFindings) {
|
|
172
|
+
export function writeSarifReport(findings, lockfileUri, plan, overrideFindings, maintenanceFindings) {
|
|
157
173
|
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
158
174
|
const filename = `cve-lite-scan-${ts}.sarif`;
|
|
159
175
|
const outputPath = path.join(process.cwd(), filename);
|
|
160
|
-
const sarif = buildSarifOutput(findings, lockfileUri, getCliVersion(), plan, overrideFindings);
|
|
176
|
+
const sarif = buildSarifOutput(findings, lockfileUri, getCliVersion(), plan, overrideFindings, maintenanceFindings);
|
|
161
177
|
try {
|
|
162
178
|
fs.writeFileSync(outputPath, JSON.stringify(sarif, null, 2));
|
|
163
179
|
}
|
|
@@ -35,6 +35,9 @@ export async function writeOutputs(options, scanState, scanInput, projectPath) {
|
|
|
35
35
|
source: scanInput.source,
|
|
36
36
|
packageCount: scanInput.packages.length,
|
|
37
37
|
findingCount: scanState.sorted.length,
|
|
38
|
+
status: scanState.completeness.complete ? "ok" : "partial",
|
|
39
|
+
complete: scanState.completeness.complete,
|
|
40
|
+
diagnostics: scanState.completeness.diagnostics,
|
|
38
41
|
suggestedFixCommands: scanState.suggestedFixCommands,
|
|
39
42
|
notes: [...scanInput.notes, ...scanState.coverage],
|
|
40
43
|
warnings: scanInput.warnings,
|
|
@@ -49,7 +52,7 @@ export async function writeOutputs(options, scanState, scanInput, projectPath) {
|
|
|
49
52
|
}
|
|
50
53
|
if (options.sarif) {
|
|
51
54
|
const lockfileUri = deriveLockfileUri(scanInput);
|
|
52
|
-
const sarifFilename = writeSarifReport(scanState.sorted, lockfileUri, scanState.suggestedFixCommands, scanState.overrideFindings);
|
|
55
|
+
const sarifFilename = writeSarifReport(scanState.sorted, lockfileUri, scanState.suggestedFixCommands, scanState.overrideFindings, scanState.maintenanceFindings);
|
|
53
56
|
console.log(`${chalk.gray("SARIF report written to")} ${chalk.cyan(sarifFilename)}`);
|
|
54
57
|
}
|
|
55
58
|
if (options.cdx) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
2
|
+
import { OVERRIDES_COMMAND } from "../../constants.js";
|
|
2
3
|
const RULE_ID = "OA001";
|
|
3
4
|
export function detect(ctx) {
|
|
4
5
|
if (ctx.skippedDetectors.some((s) => s.ruleId === RULE_ID))
|
|
@@ -25,7 +26,7 @@ export function detect(ctx) {
|
|
|
25
26
|
fix: {
|
|
26
27
|
type: "rfc6902",
|
|
27
28
|
patch: [{ op: "remove", path: jsonPointer(entry.path) }],
|
|
28
|
-
runnableCommand:
|
|
29
|
+
runnableCommand: `${OVERRIDES_COMMAND} --fix --rule OA001`,
|
|
29
30
|
},
|
|
30
31
|
references: [
|
|
31
32
|
"https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA001.md",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
2
2
|
import { isValidRange } from "../../utils/version.js";
|
|
3
|
+
import { OVERRIDES_COMMAND } from "../../constants.js";
|
|
3
4
|
const RULE_ID = "OA002";
|
|
4
5
|
const FLOATING = new Set(['latest', 'next', '*', 'x', '']);
|
|
5
6
|
export function detect(ctx) {
|
|
@@ -31,7 +32,7 @@ export function detect(ctx) {
|
|
|
31
32
|
finding.fix = {
|
|
32
33
|
type: 'rfc6902',
|
|
33
34
|
patch: [{ op: 'replace', path: jsonPointer(entry.path), value: floor }],
|
|
34
|
-
runnableCommand:
|
|
35
|
+
runnableCommand: `${OVERRIDES_COMMAND} --fix --rule OA002`,
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
findings.push(finding);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
2
|
+
import { OVERRIDES_COMMAND } from "../../constants.js";
|
|
2
3
|
const RULE_ID = "OA003";
|
|
3
4
|
const EXPECTED_CONTAINER = {
|
|
4
5
|
npm: "overrides",
|
|
@@ -37,7 +38,7 @@ export function detect(ctx) {
|
|
|
37
38
|
from: jsonPointer(entry.path),
|
|
38
39
|
path: jsonPointer(destination),
|
|
39
40
|
}],
|
|
40
|
-
runnableCommand:
|
|
41
|
+
runnableCommand: `${OVERRIDES_COMMAND} --fix --rule OA003`,
|
|
41
42
|
},
|
|
42
43
|
references: [
|
|
43
44
|
"https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA003.md",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
2
2
|
import { compareVersions, looksLikeVersion, majorVersion } from "../../utils/version.js";
|
|
3
|
+
import { OVERRIDES_COMMAND } from "../../constants.js";
|
|
3
4
|
const RULE_ID = "OA004";
|
|
4
5
|
export function detect(ctx) {
|
|
5
6
|
if (ctx.skippedDetectors.some((s) => s.ruleId === RULE_ID))
|
|
@@ -40,7 +41,7 @@ export function detect(ctx) {
|
|
|
40
41
|
finding.fix = {
|
|
41
42
|
type: "rfc6902",
|
|
42
43
|
patch: [{ op: "remove", path: jsonPointer(entry.path) }],
|
|
43
|
-
runnableCommand:
|
|
44
|
+
runnableCommand: `${OVERRIDES_COMMAND} --fix --rule OA004`,
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
findings.push(finding);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
2
2
|
import { readInstalledManifest } from "../parsing/node-modules.js";
|
|
3
3
|
import { satisfiesRange, isValidRange } from "../../utils/version.js";
|
|
4
|
+
import { OVERRIDES_COMMAND } from "../../constants.js";
|
|
4
5
|
const RULE_ID = "OA005";
|
|
5
6
|
/**
|
|
6
7
|
* OA005-NESTED-INEFFECTIVE - nested overrides in two shapes:
|
|
@@ -74,7 +75,7 @@ function classify(args) {
|
|
|
74
75
|
fix: {
|
|
75
76
|
type: "rfc6902",
|
|
76
77
|
patch: [{ op: "remove", path: jsonPointer(entryPath) }],
|
|
77
|
-
runnableCommand:
|
|
78
|
+
runnableCommand: `${OVERRIDES_COMMAND} --fix --rule OA005`,
|
|
78
79
|
},
|
|
79
80
|
}
|
|
80
81
|
: {}),
|
|
@@ -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",
|
package/dist/parsers/bun-lock.js
CHANGED
|
@@ -54,6 +54,24 @@ function collectBunPaths(rootDepNames, childDepsByPackageName, map, packageNameT
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
+
// Walk the package graph from a set of root dependency names and return every reachable name.
|
|
58
|
+
// Used to classify dev vs prod: a package is dev only when it is reachable from a
|
|
59
|
+
// devDependency root but not from any production root.
|
|
60
|
+
function collectReachableNames(rootNames, childDepsByPackageName) {
|
|
61
|
+
const reachable = new Set();
|
|
62
|
+
const stack = [...rootNames];
|
|
63
|
+
while (stack.length > 0) {
|
|
64
|
+
const name = stack.pop();
|
|
65
|
+
if (reachable.has(name))
|
|
66
|
+
continue;
|
|
67
|
+
reachable.add(name);
|
|
68
|
+
for (const child of childDepsByPackageName.get(name) ?? []) {
|
|
69
|
+
if (!reachable.has(child))
|
|
70
|
+
stack.push(child);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return reachable;
|
|
74
|
+
}
|
|
57
75
|
export function buildBunWorkspaceMap(filePath) {
|
|
58
76
|
const raw = parseJsonc(fs.readFileSync(filePath, "utf8"));
|
|
59
77
|
const workspaces = raw?.workspaces ?? {};
|
|
@@ -80,15 +98,18 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
80
98
|
const map = new Map();
|
|
81
99
|
const childDepsByPackageName = new Map();
|
|
82
100
|
const packageNameToVersion = new Map();
|
|
83
|
-
const
|
|
84
|
-
const
|
|
101
|
+
const prodRootNames = new Set();
|
|
102
|
+
const devRootNames = new Set();
|
|
85
103
|
const rootDepNames = [];
|
|
86
104
|
for (const workspace of Object.values(workspaces)) {
|
|
87
105
|
for (const name of Object.keys(workspace?.dependencies ?? {})) {
|
|
88
|
-
|
|
106
|
+
prodRootNames.add(name);
|
|
107
|
+
}
|
|
108
|
+
for (const name of Object.keys(workspace?.optionalDependencies ?? {})) {
|
|
109
|
+
prodRootNames.add(name);
|
|
89
110
|
}
|
|
90
111
|
for (const name of Object.keys(workspace?.devDependencies ?? {})) {
|
|
91
|
-
|
|
112
|
+
devRootNames.add(name);
|
|
92
113
|
}
|
|
93
114
|
}
|
|
94
115
|
for (const [workspacePath, workspace] of Object.entries(workspaces)) {
|
|
@@ -105,6 +126,7 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
105
126
|
}
|
|
106
127
|
}
|
|
107
128
|
}
|
|
129
|
+
// First pass: build the package graph (package key -> version, package key -> child dep names).
|
|
108
130
|
for (const [pkgName, entry] of Object.entries(packages)) {
|
|
109
131
|
if (!Array.isArray(entry) || entry.length < 1)
|
|
110
132
|
continue;
|
|
@@ -112,13 +134,31 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
112
134
|
const atIndex = nameAtVersion.lastIndexOf("@");
|
|
113
135
|
if (atIndex <= 0)
|
|
114
136
|
continue;
|
|
115
|
-
const name = nameAtVersion.slice(0, atIndex);
|
|
116
137
|
const version = nameAtVersion.slice(atIndex + 1);
|
|
117
|
-
if (!
|
|
138
|
+
if (!version)
|
|
118
139
|
continue;
|
|
119
140
|
packageNameToVersion.set(pkgName, version);
|
|
120
141
|
childDepsByPackageName.set(pkgName, extractChildDependencyNames(entry[2]));
|
|
121
|
-
|
|
142
|
+
}
|
|
143
|
+
// Classify dev vs prod by graph reachability rather than by direct declaration only: a
|
|
144
|
+
// package is dev when it is reachable from a devDependency root but not from any production
|
|
145
|
+
// (dependencies/optionalDependencies) root. This correctly marks a transitive pulled in only
|
|
146
|
+
// through a devDependency as dev, while keeping any package used in production anywhere prod.
|
|
147
|
+
const prodReachable = collectReachableNames(prodRootNames, childDepsByPackageName);
|
|
148
|
+
const devReachable = collectReachableNames(devRootNames, childDepsByPackageName);
|
|
149
|
+
// Second pass: create package refs with the reachability-based dev flag.
|
|
150
|
+
for (const [, entry] of Object.entries(packages)) {
|
|
151
|
+
if (!Array.isArray(entry) || entry.length < 1)
|
|
152
|
+
continue;
|
|
153
|
+
const nameAtVersion = String(entry[0] ?? "");
|
|
154
|
+
const atIndex = nameAtVersion.lastIndexOf("@");
|
|
155
|
+
if (atIndex <= 0)
|
|
156
|
+
continue;
|
|
157
|
+
const name = nameAtVersion.slice(0, atIndex);
|
|
158
|
+
const version = nameAtVersion.slice(atIndex + 1);
|
|
159
|
+
if (!name || !version)
|
|
160
|
+
continue;
|
|
161
|
+
const dev = devReachable.has(name) && !prodReachable.has(name);
|
|
122
162
|
if (prodOnly && dev)
|
|
123
163
|
continue;
|
|
124
164
|
const resolvedUrl = typeof entry[1] === "string" && entry[1] !== "" ? entry[1] : undefined;
|