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
package/README.md
CHANGED
|
@@ -133,6 +133,24 @@ cve-lite /path/to/project --check-overrides # CVE scan + hygiene in one pass
|
|
|
133
133
|
|
|
134
134
|
For the full guide with per-rule examples and CI patterns, see the [Override Hygiene Auditing guide](https://owasp.org/cve-lite-cli/docs/override-hygiene).
|
|
135
135
|
|
|
136
|
+
## Maintenance risk (`--check-maintenance`)
|
|
137
|
+
|
|
138
|
+
A CVE scanner tells you a transitive package is vulnerable. It does not tell you *why you can't fix it* - often a direct dependency of yours pins it below the fix, and clearing it needs a breaking major upgrade the scanner never mentions. The DM001 rule surfaces exactly that, plus direct dependencies npm has marked deprecated.
|
|
139
|
+
|
|
140
|
+
| Signal | Severity | What it means |
|
|
141
|
+
|---|---|---|
|
|
142
|
+
| Constraint drag | high | A direct dependency blocks a transitive CVE fix behind a major-version upgrade |
|
|
143
|
+
| Deprecated on npm | medium | A direct dependency is deprecated - no fix is coming through a normal update |
|
|
144
|
+
|
|
145
|
+
Packages that have not published in years get a `Last release` context line; release age is informational, not a severity signal on its own.
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
cve-lite /path/to/project --check-maintenance # CVE scan + maintenance risk
|
|
149
|
+
cve-lite /path/to/project --check-maintenance --fail-on high
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
For the full guide, see the [Maintenance Risk Detection guide](https://owasp.org/cve-lite-cli/docs/maintenance-risk).
|
|
153
|
+
|
|
136
154
|
## Release cooldown awareness
|
|
137
155
|
|
|
138
156
|
Package managers added a release cooldown to skip the danger window right after a version is published, when a hijacked release is live but not yet caught (the `chalk`/`debug` compromise sat live for about two hours). CVE Lite CLI reads the cooldown your project already configures and warns when a recommended fix is newer than that window, so it never quietly pushes you onto a version your own package manager would refuse to install.
|
|
@@ -211,6 +229,7 @@ No other free tool combines all of the following: lockfile scanning across npm,
|
|
|
211
229
|
| JSON output | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
212
230
|
| Offline/local advisory DB | ✅ | ❌ | ⚠️ | ❌ | ❌ |
|
|
213
231
|
| Override hygiene auditing | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
232
|
+
| Maintenance-risk detection (CVE-fix drag) | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
214
233
|
|
|
215
234
|
<sub>✅ = built-in strength · ⚠️ = partial or workflow-dependent · ❌ = not a core strength</sub>
|
|
216
235
|
|
|
@@ -238,7 +257,7 @@ jobs:
|
|
|
238
257
|
fix:
|
|
239
258
|
runs-on: ubuntu-latest
|
|
240
259
|
steps:
|
|
241
|
-
- uses: actions/checkout@
|
|
260
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
242
261
|
with:
|
|
243
262
|
ref: ${{ github.event.repository.default_branch }}
|
|
244
263
|
- uses: OWASP/cve-lite-cli@v1
|
|
@@ -310,10 +329,11 @@ CVE Lite CLI is used in production across organizations and independent develope
|
|
|
310
329
|
|
|
311
330
|
Notable adopters include:
|
|
312
331
|
|
|
332
|
+
- **SolidJS** - the framework's creator, Ryan Carniato, added CVE Lite CLI directly to its CI, scanning every change with results reported to GitHub Code Scanning
|
|
313
333
|
- **DINUM** (France) - integrated across four French government digital service repositories, including official AI training infrastructure for civil servants
|
|
314
334
|
- **DGAFP** (France) - Ministry for Civil Service, used as a pre-commit hook on a public-sector HR chatbot
|
|
315
335
|
- **Government of British Columbia** (Canada) - running as a required merge gate alongside Trivy at the Ministry of Citizens' Services
|
|
316
|
-
- **Valibot** and **
|
|
336
|
+
- **Valibot** and **Formisch** - integrated as a GitHub Action and dev script with branch protection
|
|
317
337
|
|
|
318
338
|
|
|
319
339
|
## Current limitations
|
|
@@ -350,7 +370,7 @@ gh attestation verify cve-lite-cli-X.Y.Z.tgz --repo OWASP/cve-lite-cli
|
|
|
350
370
|
npm audit signatures
|
|
351
371
|
```
|
|
352
372
|
|
|
353
|
-
For full details, fingerprints, and the project's threat model, see [SECURITY.md](https://github.com/OWASP/cve-lite-cli/blob/main/
|
|
373
|
+
For full details, fingerprints, and the project's threat model, see [SECURITY.md](https://github.com/OWASP/cve-lite-cli/blob/main/SECURITY.md) and the [Security Assurance Case](https://owasp.org/cve-lite-cli/docs/security-assurance-case).
|
|
354
374
|
|
|
355
375
|
For governance details - roles, decision-making, and dispute resolution - see [CONTRIBUTING.md](https://github.com/OWASP/cve-lite-cli/blob/main/src/docs/CONTRIBUTING.md).
|
|
356
376
|
|
|
@@ -378,7 +398,7 @@ Helpful feedback includes reproducible bug reports, real-world lockfile edge cas
|
|
|
378
398
|
|
|
379
399
|
Using CVE Lite CLI at your company or in your projects? [Share your use case in the community thread](https://github.com/OWASP/cve-lite-cli/discussions/481).
|
|
380
400
|
|
|
381
|
-
For security-related reporting: [SECURITY.md](https://github.com/OWASP/cve-lite-cli/blob/main/
|
|
401
|
+
For security-related reporting: [SECURITY.md](https://github.com/OWASP/cve-lite-cli/blob/main/SECURITY.md)
|
|
382
402
|
|
|
383
403
|
This project follows a [Code of Conduct](https://github.com/OWASP/cve-lite-cli/blob/main/CODE_OF_CONDUCT.md). Please review it before participating.
|
|
384
404
|
|
|
@@ -400,6 +420,12 @@ Thanks to everyone who helps improve CVE Lite CLI - issues, pull requests, docum
|
|
|
400
420
|
|
|
401
421
|
New here? See [CONTRIBUTING.md](https://github.com/OWASP/cve-lite-cli/blob/main/src/docs/CONTRIBUTING.md) to get started, and review the [Code of Conduct](https://github.com/OWASP/cve-lite-cli/blob/main/CODE_OF_CONDUCT.md) before participating.
|
|
402
422
|
|
|
423
|
+
## Sponsors
|
|
424
|
+
|
|
425
|
+
Thank you to those who sponsor CVE Lite CLI and help keep it maintained:
|
|
426
|
+
|
|
427
|
+
- [Arkadii Yakovets](https://github.com/arkid15r)
|
|
428
|
+
|
|
403
429
|
---
|
|
404
430
|
|
|
405
431
|
**Maintainer note:** CVE Lite CLI is an OWASP Lab Project maintained by [Sonu Kapoor](https://github.com/sonukapoor). The goal is to build a tool the security and developer community trusts and returns to - not a product that requires vendor lock-in or a dashboard to be useful. If you find a real-world lockfile edge case, a remediation gap, or a workflow that doesn't fit, open an issue. Real-world feedback from real projects is the most valuable input this project gets. See [CONTRIBUTING.md](https://github.com/OWASP/cve-lite-cli/blob/main/src/docs/CONTRIBUTING.md) for how to get involved.
|
|
@@ -59,6 +59,9 @@ export class OsvAdvisorySource {
|
|
|
59
59
|
throw new Error(`OSV batch query failed: ${response.status} ${response.statusText}`);
|
|
60
60
|
}
|
|
61
61
|
const data = await response.json();
|
|
62
|
+
if (!Array.isArray(data?.results)) {
|
|
63
|
+
throw new Error('OSV batch query returned a 200 response with no "results" array');
|
|
64
|
+
}
|
|
62
65
|
return data.results.map((r, i) => ({
|
|
63
66
|
package: packages[i].name,
|
|
64
67
|
version: packages[i].version,
|
package/dist/cli/help.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { chalk } from "../utils/chalk.js";
|
|
2
2
|
import { getCliVersion } from "../utils/version-info.js";
|
|
3
3
|
import { checkForUpdate } from "../utils/update-check.js";
|
|
4
|
+
import { OVERRIDES_COMMAND } from "../constants.js";
|
|
4
5
|
const CLI_VERSION = getCliVersion();
|
|
5
6
|
const CLI_BANNER = [
|
|
6
7
|
`${chalk.green(">_")} ${chalk.bold.whiteBright(`CVE Lite CLI (${CLI_VERSION})`)}`,
|
|
@@ -27,7 +28,7 @@ export function printHelp() {
|
|
|
27
28
|
" cve-lite advisories init [options]",
|
|
28
29
|
" cve-lite install-skill",
|
|
29
30
|
" cve-lite config <set|unset|show> [key] [value]",
|
|
30
|
-
|
|
31
|
+
` ${OVERRIDES_COMMAND} [path] [flags]`,
|
|
31
32
|
"",
|
|
32
33
|
"Scan options:",
|
|
33
34
|
" --json Save scan results to a timestamped JSON file",
|
|
@@ -91,7 +92,7 @@ export function printHelp() {
|
|
|
91
92
|
export function printOverridesHelp() {
|
|
92
93
|
printBanner();
|
|
93
94
|
const lines = [
|
|
94
|
-
|
|
95
|
+
`${OVERRIDES_COMMAND} [path] [flags]`,
|
|
95
96
|
"",
|
|
96
97
|
"Audit package.json overrides and phantom dependency imports (OA001-OA009, PD001-PD002).",
|
|
97
98
|
"",
|
package/dist/cli/validate.js
CHANGED
|
@@ -24,6 +24,12 @@ export async function validateOptions(options) {
|
|
|
24
24
|
if (options.fix && options.json) {
|
|
25
25
|
throw new Error("--fix cannot be used with --json");
|
|
26
26
|
}
|
|
27
|
+
if (options.fix && options.sarif) {
|
|
28
|
+
throw new Error("--fix cannot be used with --sarif");
|
|
29
|
+
}
|
|
30
|
+
if (options.fix && options.cdx) {
|
|
31
|
+
throw new Error("--fix cannot be used with --cdx");
|
|
32
|
+
}
|
|
27
33
|
if (options.createPr && !options.fix) {
|
|
28
34
|
throw new Error("--create-pr requires --fix");
|
|
29
35
|
}
|
package/dist/constants.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { loadPackages, buildNoPackagesMessage } from "./parsers/index.js";
|
|
|
9
9
|
import { scanPackages, buildCoverageNotes, createAdvisorySource } from "./scanner.js";
|
|
10
10
|
import { syncOsvAdvisories } from "./advisory/osv-sync.js";
|
|
11
11
|
import { normalizeSeverity } from "./osv/severity.js";
|
|
12
|
-
import { DEFAULT_BATCH_SIZE, DEFAULT_SEARCH_DEPTH } from "./constants.js";
|
|
12
|
+
import { DEFAULT_BATCH_SIZE, DEFAULT_SEARCH_DEPTH, OVERRIDES_COMMAND } from "./constants.js";
|
|
13
13
|
import { chalk } from "./utils/chalk.js";
|
|
14
14
|
import { createSpinner } from "./output/spinner.js";
|
|
15
15
|
import { createDebugLogger } from "./output/debug.js";
|
|
@@ -40,6 +40,7 @@ import { hasRootLockfile, findNestedLockfiles } from "./parsers/multi-package.js
|
|
|
40
40
|
import { handleMultiFolderScan } from "./scan/multi-folder-scan.js";
|
|
41
41
|
import { collectAdvisoryIdsForPackage, createPullRequestForFixes, } from "./utils/create-pr.js";
|
|
42
42
|
import { readBaseline, writeBaseline, filterNewFindings, ratchetOutcome } from "./utils/baseline.js";
|
|
43
|
+
import { formatDiagnosticMessage, getCompletenessImpact } from "./scan/completeness.js";
|
|
43
44
|
let parsedArgs = null;
|
|
44
45
|
try {
|
|
45
46
|
parsedArgs = parseArgs(process.argv.slice(2));
|
|
@@ -202,7 +203,13 @@ if (parsedArgs) {
|
|
|
202
203
|
// route to dedicated multi-folder handler instead of single-lockfile scan
|
|
203
204
|
const nestedLockfiles = findNestedLockfiles(projectPath, searchDepth);
|
|
204
205
|
if (!hasRootLockfile(projectPath) && nestedLockfiles.length >= 2) {
|
|
205
|
-
const exitCode = await handleMultiFolderScan({
|
|
206
|
+
const exitCode = await handleMultiFolderScan({
|
|
207
|
+
projectRoot: projectPath,
|
|
208
|
+
batchSize,
|
|
209
|
+
options,
|
|
210
|
+
fetchImpl: certFetch,
|
|
211
|
+
auditLog: auditLogHandle,
|
|
212
|
+
});
|
|
206
213
|
auditLogHandle.close();
|
|
207
214
|
process.exit(exitCode);
|
|
208
215
|
}
|
|
@@ -463,6 +470,7 @@ if (parsedArgs) {
|
|
|
463
470
|
// the nothing-to-fix case without parsing stdout.
|
|
464
471
|
const fixResultJson = {
|
|
465
472
|
appliedFixCount: fixResult?.appliedFixCount ?? 0,
|
|
473
|
+
appliedWithinRangeRefreshCount: fixResult?.appliedWithinRangeRefreshCount ?? 0,
|
|
466
474
|
findingsBeforeFix,
|
|
467
475
|
findingsAfterFix: scanState.sorted.length,
|
|
468
476
|
applied: (fixResult?.applied ?? []).map(entry => ({
|
|
@@ -471,6 +479,11 @@ if (parsedArgs) {
|
|
|
471
479
|
to: entry.to,
|
|
472
480
|
advisories: collectAdvisoryIdsForPackage(findingsBeforeFixList, entry.package),
|
|
473
481
|
})),
|
|
482
|
+
notAutoApplied: {
|
|
483
|
+
parentUpgradeCount: fixResult?.parentUpgradeCount ?? 0,
|
|
484
|
+
breakingUpgradeCount: fixResult?.breakingUpgradeCount ?? 0,
|
|
485
|
+
noFixCount: fixResult?.noFixCount ?? 0,
|
|
486
|
+
},
|
|
474
487
|
};
|
|
475
488
|
writeFixResultJson(fixResultJson, projectPath);
|
|
476
489
|
if (options.createPr && fixResult) {
|
|
@@ -510,13 +523,33 @@ if (parsedArgs) {
|
|
|
510
523
|
// baseline. Re-saving here would silently absorb a new vulnerability into a
|
|
511
524
|
// fresh baseline, so a ratcheted CI job could never fail on a regression.
|
|
512
525
|
if (options.ratchet) {
|
|
526
|
+
const { hasDetectionGap } = getCompletenessImpact(scanState.completeness);
|
|
527
|
+
if (hasDetectionGap) {
|
|
528
|
+
console.log(chalk.red("Scan data is incomplete. Refusing to create or evaluate a baseline from partial detection data."));
|
|
529
|
+
for (const diagnostic of scanState.completeness.diagnostics) {
|
|
530
|
+
if (diagnostic.impact !== "detection")
|
|
531
|
+
continue;
|
|
532
|
+
console.log(chalk.red(` ${formatDiagnosticMessage(diagnostic.code, diagnostic.count, diagnostic.affectedPackageCount)}`));
|
|
533
|
+
}
|
|
534
|
+
auditLogHandle.emit({
|
|
535
|
+
ts: new Date().toISOString(),
|
|
536
|
+
type: "scan.finished",
|
|
537
|
+
schemaVersion: 1,
|
|
538
|
+
durationMs: Date.now() - scanStartTime,
|
|
539
|
+
findingsCount: scanState.sorted.length,
|
|
540
|
+
exitCode: EXIT_ERROR,
|
|
541
|
+
});
|
|
542
|
+
auditLogHandle.close();
|
|
543
|
+
process.exit(EXIT_ERROR);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
513
546
|
const outcome = ratchetOutcome(baseline, scanState.sorted);
|
|
514
547
|
if (outcome.action === "save") {
|
|
515
548
|
writeBaseline(projectArg ?? ".", scanState.sorted);
|
|
516
549
|
const count = scanState.sorted.length;
|
|
517
550
|
console.log(chalk.green(`✓ Baseline saved to .cve-lite/baseline.json with ${count} ${count === 1 ? "finding" : "findings"}. Future scans will only report findings above this baseline.`));
|
|
518
551
|
if (options.checkOverrides) {
|
|
519
|
-
console.log(chalk.gray(
|
|
552
|
+
console.log(chalk.gray(`Note: override hygiene (--check-overrides) is not part of the ratchet baseline; run \`${OVERRIDES_COMMAND}\` to audit overrides.`));
|
|
520
553
|
}
|
|
521
554
|
auditLogHandle.emit({
|
|
522
555
|
ts: new Date().toISOString(),
|
|
@@ -580,7 +613,9 @@ if (parsedArgs) {
|
|
|
580
613
|
// This point is unreached in --ratchet mode (which always exits above
|
|
581
614
|
// via process.exit), so packument fetches never run wastefully there.
|
|
582
615
|
if (options.checkMaintenance) {
|
|
583
|
-
|
|
616
|
+
const directNames = readDirectDependencyNames(projectPath, !!options.prodOnly);
|
|
617
|
+
const directDependencies = scanState.allPackages.filter(p => directNames?.has(p.name));
|
|
618
|
+
maintenanceFindings = await detectDM001(scanState.sorted, directDependencies, !!options.offline || !!options.offlineDb);
|
|
584
619
|
}
|
|
585
620
|
await writeOutputs(options, {
|
|
586
621
|
sorted: scanState.sorted,
|
|
@@ -589,6 +624,7 @@ if (parsedArgs) {
|
|
|
589
624
|
coverage: scanState.coverage,
|
|
590
625
|
minSeverity: scanState.minSeverity,
|
|
591
626
|
tableFindings: scanState.tableFindings,
|
|
627
|
+
completeness: scanState.completeness,
|
|
592
628
|
overrideFindings,
|
|
593
629
|
maintenanceFindings,
|
|
594
630
|
}, scanInput, projectPath);
|
|
@@ -623,7 +659,7 @@ if (parsedArgs) {
|
|
|
623
659
|
console.log("\n" + renderMaintenanceFindings(maintenanceFindings, { verbose: true }));
|
|
624
660
|
}
|
|
625
661
|
printCoverage([...scanInput.notes, ...scanState.coverage]);
|
|
626
|
-
printFinalStatus(scanState.sorted, overrideCount);
|
|
662
|
+
printFinalStatus(scanState.sorted, overrideCount, scanState.completeness);
|
|
627
663
|
if (showOverrideHint)
|
|
628
664
|
printOverrideHint();
|
|
629
665
|
}
|
|
@@ -631,7 +667,12 @@ if (parsedArgs) {
|
|
|
631
667
|
const compactPmLabel = scanState.suggestedFixCommands
|
|
632
668
|
? `${chalk.cyan(scanState.suggestedFixCommands.packageManager)} ${chalk.gray(`(${scanState.suggestedFixCommands.sourceLabel})`)}`
|
|
633
669
|
: undefined;
|
|
634
|
-
printCompactOutput(scanState.sorted, scanInput, {
|
|
670
|
+
printCompactOutput(scanState.sorted, scanInput, {
|
|
671
|
+
offline,
|
|
672
|
+
all: !!options.all,
|
|
673
|
+
packageManager: compactPmLabel,
|
|
674
|
+
completeness: scanState.completeness,
|
|
675
|
+
});
|
|
635
676
|
if (options.checkOverrides) {
|
|
636
677
|
console.log("\n" + renderOverrideFindings(overrideFindings, { verbose: false, projectPath }));
|
|
637
678
|
}
|
|
@@ -661,6 +702,7 @@ if (parsedArgs) {
|
|
|
661
702
|
overrideFindings: options.checkOverrides ? overrideFindings : undefined,
|
|
662
703
|
// Same undefined-vs-[] convention as overrideFindings above.
|
|
663
704
|
maintenanceFindings: options.checkMaintenance ? maintenanceFindings : undefined,
|
|
705
|
+
completeness: scanState.completeness,
|
|
664
706
|
});
|
|
665
707
|
const { reportPath } = await writeHtmlReport({
|
|
666
708
|
outputDir,
|
|
@@ -731,7 +773,7 @@ if (parsedArgs) {
|
|
|
731
773
|
}
|
|
732
774
|
async function scanProject(params) {
|
|
733
775
|
const directDependencyNames = readDirectDependencyNames(params.projectPath, !!params.options.prodOnly);
|
|
734
|
-
const findings = await scanPackages(params.scanInput.packages, params.batchSize, params.options, {
|
|
776
|
+
const { findings, completeness } = await scanPackages(params.scanInput.packages, params.batchSize, params.options, {
|
|
735
777
|
directDependencyNames,
|
|
736
778
|
scanSource: params.scanInput.source,
|
|
737
779
|
scanFilePath: params.scanInput.filePath,
|
|
@@ -789,5 +831,6 @@ async function scanProject(params) {
|
|
|
789
831
|
tableFindings,
|
|
790
832
|
suggestedFixCommands,
|
|
791
833
|
allPackages: params.scanInput.packages,
|
|
834
|
+
completeness,
|
|
792
835
|
};
|
|
793
836
|
}
|
|
@@ -1,9 +1,58 @@
|
|
|
1
1
|
import { fetchPackument } from "../remediation/npm-registry.js";
|
|
2
|
-
|
|
2
|
+
import { computeStaleness, scoreMaintenanceFinding } from "./score.js";
|
|
3
|
+
import { runWithConcurrency } from "../utils/array.js";
|
|
4
|
+
const SEVERITY_ORDER_MAP = { high: 0, medium: 1, low: 2 };
|
|
5
|
+
// Bounds concurrent packument fetches for the deprecated-only pass over direct
|
|
6
|
+
// dependencies so a large dependency tree does not fire hundreds of requests at once.
|
|
7
|
+
const DEPRECATED_CHECK_CONCURRENCY = 10;
|
|
3
8
|
function majorOf(version) {
|
|
4
9
|
return parseInt(version.split(".")[0] ?? "0", 10);
|
|
5
10
|
}
|
|
6
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Looks up the deprecation message on a packument's `latest` dist-tag version, if any.
|
|
13
|
+
* Deprecation is checked on `latest` (package-level abandonment signal), not the
|
|
14
|
+
* version actually installed.
|
|
15
|
+
*/
|
|
16
|
+
function deprecationMessageOf(packument) {
|
|
17
|
+
if (!packument) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
const latestVersion = packument["dist-tags"]?.latest ?? "";
|
|
21
|
+
if (!latestVersion) {
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
return packument.versions?.[latestVersion]?.deprecated ?? "";
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks a single direct dependency (already known not to be a drag candidate) for
|
|
28
|
+
* npm-level deprecation and, if deprecated, builds a DM001 finding for it. Returns
|
|
29
|
+
* null when the dependency is not deprecated or the packument fetch fails.
|
|
30
|
+
*/
|
|
31
|
+
async function checkDeprecatedOnly(dep) {
|
|
32
|
+
let packument;
|
|
33
|
+
try {
|
|
34
|
+
packument = await fetchPackument(dep.name);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const deprecatedMsg = deprecationMessageOf(packument);
|
|
40
|
+
if (!deprecatedMsg) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const staleness = computeStaleness(packument, new Date());
|
|
44
|
+
const severity = scoreMaintenanceFinding({ drag: false, deprecated: true }).severity;
|
|
45
|
+
return {
|
|
46
|
+
ruleId: "DM001",
|
|
47
|
+
severity,
|
|
48
|
+
package: { name: dep.name, version: dep.version },
|
|
49
|
+
drag: undefined,
|
|
50
|
+
deprecated: { message: deprecatedMsg },
|
|
51
|
+
staleness: staleness ?? undefined,
|
|
52
|
+
message: `Deprecated: ${deprecatedMsg}`,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export async function detectDM001(findings, directDependencies, isOffline) {
|
|
7
56
|
// Step 1: Collect drag candidates (transitive findings requiring a major-version parent bump)
|
|
8
57
|
const candidates = new Map();
|
|
9
58
|
for (const finding of findings) {
|
|
@@ -23,39 +72,49 @@ export async function detectDM001(findings, isOffline) {
|
|
|
23
72
|
cveId: finding.cveAliases[0] ?? finding.vulnerabilities[0]?.id ?? "",
|
|
24
73
|
});
|
|
25
74
|
}
|
|
26
|
-
|
|
27
|
-
return [];
|
|
28
|
-
// Step 2: Check deprecated status for each candidate (skip when offline)
|
|
75
|
+
// Step 2: Check deprecated status for each drag candidate (skip when offline)
|
|
29
76
|
const results = [];
|
|
30
77
|
for (const [parentName, candidate] of candidates) {
|
|
31
78
|
let deprecated;
|
|
79
|
+
let packument = null;
|
|
32
80
|
if (!isOffline) {
|
|
33
81
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
? (packument.versions?.[latestVersion]?.deprecated ?? "")
|
|
39
|
-
: "";
|
|
40
|
-
if (deprecatedMsg)
|
|
41
|
-
deprecated = { message: deprecatedMsg };
|
|
82
|
+
packument = await fetchPackument(parentName);
|
|
83
|
+
const deprecatedMsg = deprecationMessageOf(packument);
|
|
84
|
+
if (deprecatedMsg) {
|
|
85
|
+
deprecated = { message: deprecatedMsg };
|
|
42
86
|
}
|
|
43
87
|
}
|
|
44
88
|
catch {
|
|
45
|
-
// Network error - emit drag finding without deprecated signal
|
|
89
|
+
// Network error - emit drag finding without deprecated/staleness signal
|
|
90
|
+
packument = null;
|
|
46
91
|
}
|
|
47
92
|
}
|
|
93
|
+
const staleness = isOffline ? null : computeStaleness(packument, new Date());
|
|
94
|
+
const severity = scoreMaintenanceFinding({ drag: true, deprecated: !!deprecated }).severity;
|
|
48
95
|
const pkgList = candidate.dragSignals.map(d => d.constrainedPackage).join(", ");
|
|
49
96
|
const message = `Constrains ${pkgList} - blocks CVE fix requiring major upgrade`;
|
|
50
97
|
results.push({
|
|
51
98
|
ruleId: "DM001",
|
|
52
|
-
severity
|
|
99
|
+
severity,
|
|
53
100
|
package: { name: parentName, version: candidate.parentVersion },
|
|
54
101
|
drag: candidate.dragSignals,
|
|
55
102
|
deprecated,
|
|
103
|
+
staleness: staleness ?? undefined,
|
|
56
104
|
message,
|
|
57
105
|
});
|
|
58
106
|
}
|
|
107
|
+
// Step 3: Deprecated-only pass over direct dependencies not already covered by
|
|
108
|
+
// drag (package-level abandonment, independent of any CVE-driven parent upgrade).
|
|
109
|
+
if (!isOffline) {
|
|
110
|
+
const uncoveredDeps = directDependencies.filter(dep => !candidates.has(dep.name));
|
|
111
|
+
const deprecatedOnlyFindings = await runWithConcurrency(uncoveredDeps, DEPRECATED_CHECK_CONCURRENCY, checkDeprecatedOnly);
|
|
112
|
+
for (const finding of deprecatedOnlyFindings) {
|
|
113
|
+
if (finding) {
|
|
114
|
+
results.push(finding);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
59
118
|
return results.sort((a, b) => {
|
|
60
119
|
const sDiff = (SEVERITY_ORDER_MAP[a.severity] ?? 4) - (SEVERITY_ORDER_MAP[b.severity] ?? 4);
|
|
61
120
|
return sDiff !== 0 ? sDiff : a.package.name.localeCompare(b.package.name);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Severity comes only from explicit maintainer signals: drag (a package holding a
|
|
2
|
+
// transitive dep below its CVE fix) and npm-deprecation. Release age is NOT a
|
|
3
|
+
// severity input - a stable, feature-complete package can be years old and fine;
|
|
4
|
+
// only an explicit signal reliably means "this will not get fixed". Staleness is
|
|
5
|
+
// surfaced as display context (see computeStaleness), never as a score.
|
|
6
|
+
export const DRAG_WEIGHT = 3;
|
|
7
|
+
export const DEPRECATED_WEIGHT = 2;
|
|
8
|
+
// A package is shown as stale (a "Last release: …" context line) only when its
|
|
9
|
+
// latest release is at least this old. This is a display threshold, not a
|
|
10
|
+
// severity threshold.
|
|
11
|
+
export const STALE_YEARS = 2;
|
|
12
|
+
const MS_PER_YEAR = 365.25 * 24 * 60 * 60 * 1000;
|
|
13
|
+
export function scoreMaintenanceFinding(signals) {
|
|
14
|
+
let score = 0;
|
|
15
|
+
if (signals.drag) {
|
|
16
|
+
score += DRAG_WEIGHT;
|
|
17
|
+
}
|
|
18
|
+
if (signals.deprecated) {
|
|
19
|
+
score += DEPRECATED_WEIGHT;
|
|
20
|
+
}
|
|
21
|
+
let severity;
|
|
22
|
+
if (score >= 3) {
|
|
23
|
+
severity = "high";
|
|
24
|
+
}
|
|
25
|
+
else if (score === 2) {
|
|
26
|
+
severity = "medium";
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
severity = "low";
|
|
30
|
+
}
|
|
31
|
+
return { score, severity };
|
|
32
|
+
}
|
|
33
|
+
// Returns a staleness signal ONLY when the latest release is at least STALE_YEARS
|
|
34
|
+
// old - a fresh package produces no signal (and no "Last release" line). This is
|
|
35
|
+
// context to help judge abandonment, not a severity input.
|
|
36
|
+
export function computeStaleness(packument, now) {
|
|
37
|
+
const latest = packument?.["dist-tags"]?.latest;
|
|
38
|
+
const lastPublish = latest ? packument?.time?.[latest] : undefined;
|
|
39
|
+
if (!lastPublish) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const published = new Date(lastPublish);
|
|
43
|
+
if (Number.isNaN(published.getTime())) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const ageYears = Math.floor((now.getTime() - published.getTime()) / MS_PER_YEAR);
|
|
47
|
+
if (ageYears < STALE_YEARS) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return { lastPublish, ageYears };
|
|
51
|
+
}
|
|
@@ -3,9 +3,10 @@ import { chalk } from "../utils/chalk.js";
|
|
|
3
3
|
import { severityOrder, MAL_PRIVATE_REGISTRY_MESSAGE, MAL_GIT_SOURCE_PINNED_MESSAGE, MAL_GIT_SOURCE_FLOATING_MESSAGE, } from "../constants.js";
|
|
4
4
|
import { loadCache } from "../osv/cache.js";
|
|
5
5
|
import { inferSeverity } from "../osv/severity.js";
|
|
6
|
-
import { getPrimaryParent } from "../utils/finding.js";
|
|
6
|
+
import { getPrimaryParent, getRootDependencies } from "../utils/finding.js";
|
|
7
7
|
import { calculatePathCoverage, formatDependencyPath } from "../utils/path-coverage.js";
|
|
8
8
|
import { pluralize } from "../utils/string.js";
|
|
9
|
+
import { hasMaliciousAdvisory } from "../utils/vuln.js";
|
|
9
10
|
export function formatRelationshipLabel(value) {
|
|
10
11
|
if (value.startsWith("direct"))
|
|
11
12
|
return chalk.green(value);
|
|
@@ -17,6 +18,16 @@ export function formatRelLabel(finding) {
|
|
|
17
18
|
const base = finding.relationship;
|
|
18
19
|
return finding.pkg.dev === true ? `${base} · dev` : base;
|
|
19
20
|
}
|
|
21
|
+
// Compact form for the terminal table, where column width is limited: shows
|
|
22
|
+
// the first root dependency plus a count of additional ones (e.g. "app +2").
|
|
23
|
+
export function formatRootDependencySummary(finding) {
|
|
24
|
+
const roots = getRootDependencies(finding);
|
|
25
|
+
if (roots.length === 0)
|
|
26
|
+
return "-";
|
|
27
|
+
if (roots.length === 1)
|
|
28
|
+
return roots[0];
|
|
29
|
+
return `${roots[0]} +${roots.length - 1}`;
|
|
30
|
+
}
|
|
20
31
|
export function formatAdvisorySourceLine(sourceLabel) {
|
|
21
32
|
const match = sourceLabel.match(/^(.*) \((.*)\)$/);
|
|
22
33
|
if (!match) {
|
|
@@ -35,7 +46,12 @@ export function formatHintLines(lines) {
|
|
|
35
46
|
}
|
|
36
47
|
// MAL-* is the OSV prefix for malicious code advisories
|
|
37
48
|
function isMaliciousAdvisory(finding) {
|
|
38
|
-
return finding.vulnerabilities
|
|
49
|
+
return hasMaliciousAdvisory(finding.vulnerabilities);
|
|
50
|
+
}
|
|
51
|
+
function transitiveRiskMessage(packageName, complete) {
|
|
52
|
+
return complete
|
|
53
|
+
? `Transitive issue. A specific parent upgrade target was found for ${packageName}.`
|
|
54
|
+
: `Transitive issue. A path-specific parent upgrade target was found for ${packageName}; run it, rescan, and review remaining paths separately.`;
|
|
39
55
|
}
|
|
40
56
|
export function getRecommendedAction(finding) {
|
|
41
57
|
if (isMaliciousAdvisory(finding)) {
|
|
@@ -106,15 +122,11 @@ export function summarizeRisk(finding) {
|
|
|
106
122
|
}
|
|
107
123
|
else if (finding.relationship === "transitive" && finding.recommendedNpmTransitiveRemediation?.kind === "upgrade-parent-to-version") {
|
|
108
124
|
const coverage = calculatePathCoverage(finding.dependencyPaths, finding.recommendedNpmTransitiveRemediation.viaPath);
|
|
109
|
-
risk = coverage.coverage === "complete"
|
|
110
|
-
? `Transitive issue. A specific parent upgrade target was found for ${finding.recommendedNpmTransitiveRemediation.package}.`
|
|
111
|
-
: `Transitive issue. A path-specific parent upgrade target was found for ${finding.recommendedNpmTransitiveRemediation.package}; run it, rescan, and review remaining paths separately.`;
|
|
125
|
+
risk = transitiveRiskMessage(finding.recommendedNpmTransitiveRemediation.package, coverage.coverage === "complete");
|
|
112
126
|
}
|
|
113
127
|
else if (finding.relationship === "transitive" && finding.recommendedParentUpgrade) {
|
|
114
128
|
const coverage = calculatePathCoverage(finding.dependencyPaths, finding.recommendedParentUpgrade.viaPath);
|
|
115
|
-
risk = coverage.coverage === "complete"
|
|
116
|
-
? `Transitive issue. A specific parent upgrade target was found for ${finding.recommendedParentUpgrade.package}.`
|
|
117
|
-
: `Transitive issue. A path-specific parent upgrade target was found for ${finding.recommendedParentUpgrade.package}; run it, rescan, and review remaining paths separately.`;
|
|
129
|
+
risk = transitiveRiskMessage(finding.recommendedParentUpgrade.package, coverage.coverage === "complete");
|
|
118
130
|
}
|
|
119
131
|
else if (finding.relationship === "transitive" && (finding.validatedFirstFixedVersion ?? finding.firstFixedVersion)) {
|
|
120
132
|
const target = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
@@ -225,6 +237,7 @@ export function serializeFinding(finding, plan) {
|
|
|
225
237
|
recommendedAction: getRecommendedAction(finding),
|
|
226
238
|
runnableFixCommand: plan ? findSuggestedCommandForFinding(plan, finding) : null,
|
|
227
239
|
primaryParent: getPrimaryParent(finding),
|
|
240
|
+
rootDependencies: getRootDependencies(finding),
|
|
228
241
|
recommendedParentUpgrade: finding.recommendedParentUpgrade,
|
|
229
242
|
recommendedNpmTransitiveRemediation: finding.recommendedNpmTransitiveRemediation ?? null,
|
|
230
243
|
cves: finding.cveAliases,
|