cve-lite-cli 1.3.0 → 1.4.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 +45 -11
- package/dist/index.js +159 -146
- package/dist/output/formatters.js +2 -0
- package/dist/output/printers.js +120 -21
- package/dist/remediation/fix-commands.js +156 -10
- package/dist/remediation/npm-registry.js +67 -0
- package/dist/remediation/parent-upgrade.js +1 -18
- package/dist/scanner.js +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
<a href="#new-offline-advisory-db-support">Offline advisory DB support</a><br/>
|
|
35
35
|
<a href="#why-offline-mode-matters">Why offline mode matters</a><br/>
|
|
36
36
|
<a href="docs/case-studies/owasp-juice-shop.md">OWASP Juice Shop case study</a><br/>
|
|
37
|
+
<a href="docs/case-studies/nestjs.md">NestJS case study</a><br/>
|
|
37
38
|
<a href="#what-it-looks-like">What it looks like</a><br/>
|
|
38
39
|
<a href="#why-this-tool-exists">Why this tool exists</a><br/>
|
|
39
40
|
<a href="#project-scope-and-differentiation">Project scope and differentiation</a>
|
|
@@ -77,7 +78,7 @@ It is designed to be:
|
|
|
77
78
|
- usable in enterprise and restricted-network environments
|
|
78
79
|
- capable of zero-runtime-network scans through a local advisory database
|
|
79
80
|
|
|
80
|
-
For
|
|
81
|
+
For real-world remediation examples, see the [OWASP Juice Shop case study](docs/case-studies/owasp-juice-shop.md) and the [NestJS case study](docs/case-studies/nestjs.md).
|
|
81
82
|
|
|
82
83
|
## New: Offline advisory DB support
|
|
83
84
|
|
|
@@ -210,7 +211,15 @@ cve-lite /path/to/project --offline
|
|
|
210
211
|
|
|
211
212
|
CVE Lite CLI produces a clean, summary-first console view by default, designed for fast triage before release.
|
|
212
213
|
|
|
213
|
-
The default output is designed to stay concise while still surfacing the most important next step, including package-manager-aware
|
|
214
|
+
The default output is designed to stay concise while still surfacing the most important next step, including package-manager-aware fix commands when confident targets exist.
|
|
215
|
+
|
|
216
|
+
The most important section to look for in the output is:
|
|
217
|
+
|
|
218
|
+
```text
|
|
219
|
+
🛠 Copy And Run These Fix Commands
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
That is one of the clearest differentiators in CVE Lite CLI. Instead of only showing advisories and severity counts, the tool tries to turn the findings into concrete commands developers can copy and run immediately.
|
|
214
223
|
|
|
215
224
|
For example, the tool can now suggest a concrete next command such as:
|
|
216
225
|
|
|
@@ -220,15 +229,25 @@ npm install jsonwebtoken@4.2.2 express-jwt@2.1.0 sanitize-html@2.17.2
|
|
|
220
229
|
|
|
221
230
|
The exact command adapts to the dependency file used for the scan, so `package-lock.json`, `pnpm-lock.yaml`, and `yarn.lock` can each produce a package-manager-specific suggestion.
|
|
222
231
|
|
|
223
|
-
For deeper investigation, running with `--verbose` provides the fuller remediation context, including dependency paths, parent upgrade guidance for transitive issues when available, a complete fix plan, skipped-item context for unresolved urgent findings, and a detailed table view.
|
|
232
|
+
For deeper investigation, running with `--verbose` provides the fuller remediation context, including the `Copy And Run These Fix Commands` section, dependency paths, parent upgrade guidance for transitive issues when available, a complete fix plan, skipped-item context for unresolved urgent findings, and a detailed table view.
|
|
224
233
|
|
|
225
234
|
That is the core idea: install it, point it at your project, and immediately get a practical fix plan instead of a wall of raw advisories.
|
|
226
235
|
|
|
236
|
+
That local loop matters a lot in practice. In the NestJS case study, one dependency path required several `tar` upgrades in sequence as the dependency graph changed after each install. If a team only relied on pipeline scanners, they would likely:
|
|
237
|
+
|
|
238
|
+
1. upgrade `tar`
|
|
239
|
+
2. push a branch
|
|
240
|
+
3. wait for CI or a scheduled scanner to report back
|
|
241
|
+
4. learn they need to upgrade `tar` again
|
|
242
|
+
5. repeat the full cycle
|
|
243
|
+
|
|
244
|
+
That kind of branch-and-pipeline remediation can easily burn hours or days for one CVE path, and in slower teams it can stretch into weeks. CVE Lite CLI brings that feedback loop down to a local scan-fix-rescan workflow that can happen in the same session, and its local caching keeps consecutive rescans extremely fast instead of redoing the same advisory lookups from scratch each time.
|
|
245
|
+
|
|
227
246
|
The final status line also gives the scan a clear ending, which makes terminal use and screenshots easier to read.
|
|
228
247
|
|
|
229
248
|
See the example below using OWASP Juice Shop for real output samples.
|
|
230
249
|
|
|
231
|
-
For
|
|
250
|
+
For real-world case studies, see the [OWASP Juice Shop case study](docs/case-studies/owasp-juice-shop.md) and the [NestJS case study](docs/case-studies/nestjs.md).
|
|
232
251
|
|
|
233
252
|
If you maintain an open-source JavaScript or TypeScript project and want CVE Lite CLI evaluated on it, open an issue and share the repository. Strong candidates may be turned into future public case studies.
|
|
234
253
|
|
|
@@ -254,6 +273,8 @@ cve-lite .
|
|
|
254
273
|
|
|
255
274
|
Verbose examples:
|
|
256
275
|
|
|
276
|
+
Look for the `Copy And Run These Fix Commands` section in the screenshots below. That is the part of the output that turns findings into direct remediation steps.
|
|
277
|
+
|
|
257
278
|
<p align="center">
|
|
258
279
|
<img src="https://raw.githubusercontent.com/sonukapoor/cve-lite-cli/main/assets/verbose-output-1.png" alt="CVE Lite CLI verbose output screenshot" width="900"/>
|
|
259
280
|
<img src="https://raw.githubusercontent.com/sonukapoor/cve-lite-cli/main/assets/verbose-output-2.png" alt="CVE Lite CLI verbose output screenshot" width="900"/>
|
|
@@ -430,7 +451,7 @@ CVE Lite CLI is designed as a **local-first, metadata-only** scanner. Unlike tra
|
|
|
430
451
|
- **fast, low-friction workflow**
|
|
431
452
|
Run it locally against a project without adopting a large security platform.
|
|
432
453
|
- **practical remediation guidance**
|
|
433
|
-
It does not stop at raw advisory output. It highlights top-priority fixes, suggests a fix plan, and
|
|
454
|
+
It does not stop at raw advisory output. It highlights top-priority fixes, suggests a fix plan, and generates package-manager-aware commands developers can copy and run when confident upgrade targets exist.
|
|
434
455
|
- **direct vs transitive visibility**
|
|
435
456
|
The output makes it easier to see whether the risk comes from something you installed directly or from a nested package.
|
|
436
457
|
- **developer-first**
|
|
@@ -472,11 +493,24 @@ Instead of only showing advisory IDs, the CLI reports:
|
|
|
472
493
|
|
|
473
494
|
By default, the CLI now presents a cleaner summary-first view, with `--verbose` available for the full detailed output.
|
|
474
495
|
|
|
475
|
-
### 3.
|
|
496
|
+
### 3. Copy-and-run fix commands
|
|
497
|
+
|
|
498
|
+
This is one of the most important parts of the CLI output.
|
|
499
|
+
|
|
500
|
+
When confident upgrade targets exist, CVE Lite CLI shows a dedicated `Copy And Run These Fix Commands` section so developers can move straight from findings to action.
|
|
501
|
+
|
|
502
|
+
The commands are:
|
|
503
|
+
|
|
504
|
+
- package-manager-aware
|
|
505
|
+
- grouped by severity and fix type
|
|
506
|
+
- designed to be copied directly from the terminal
|
|
507
|
+
- shown before the deeper remediation detail in verbose mode
|
|
508
|
+
|
|
509
|
+
### 4. Top priority fixes
|
|
476
510
|
|
|
477
511
|
The CLI highlights the most important issues first, so developers can focus on the findings most likely to matter immediately.
|
|
478
512
|
|
|
479
|
-
###
|
|
513
|
+
### 5. Suggested fix plan
|
|
480
514
|
|
|
481
515
|
CVE Lite CLI organizes likely remediation work into a practical sequence, such as:
|
|
482
516
|
|
|
@@ -485,19 +519,19 @@ CVE Lite CLI organizes likely remediation work into a practical sequence, such a
|
|
|
485
519
|
- medium direct cleanup after that
|
|
486
520
|
- duplicated vulnerable packages to consolidate
|
|
487
521
|
|
|
488
|
-
###
|
|
522
|
+
### 6. Parent package hints for transitive issues
|
|
489
523
|
|
|
490
524
|
For transitive vulnerabilities, CVE Lite CLI can show the dependency path and, when it can determine one reliably, recommend the parent package upgrade to make. That makes the output more actionable than simply saying a nested package is vulnerable.
|
|
491
525
|
|
|
492
|
-
###
|
|
526
|
+
### 7. JSON output
|
|
493
527
|
|
|
494
528
|
Structured JSON output makes it easier to integrate with scripts, logs, or pipeline artifacts.
|
|
495
529
|
|
|
496
|
-
###
|
|
530
|
+
### 8. CI-friendly behavior
|
|
497
531
|
|
|
498
532
|
The CLI can be used in CI/CD pipelines and can fail builds based on severity thresholds.
|
|
499
533
|
|
|
500
|
-
###
|
|
534
|
+
### 9. Offline advisory DB support
|
|
501
535
|
|
|
502
536
|
The CLI can sync the official OSV npm advisory dump into a local SQLite advisory database and scan against it later with zero runtime advisory API calls.
|
|
503
537
|
|
package/dist/index.js
CHANGED
|
@@ -13,169 +13,182 @@ import { createSpinner } from "./output/spinner.js";
|
|
|
13
13
|
import { buildSuggestedFixCommandPlan } from "./remediation/fix-commands.js";
|
|
14
14
|
import { getCliVersion } from "./utils/version-info.js";
|
|
15
15
|
import { logInfo, logWarn, printCacheSummary, serializeFinding } from "./output/formatters.js";
|
|
16
|
-
import { printSummary, printActionSummary, printPriorityFixes, printFixPlan, printSuggestedFixCommands, printCoverage, printSkippedDependencies, printGroupSummary, printTable, printPathHints, printFinalStatus, printCompactOutput } from "./output/printers.js";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
printHelp();
|
|
21
|
-
process.exit(0);
|
|
16
|
+
import { printSummary, printActionSummary, printPriorityFixes, printFixPlan, printSuggestedFixCommands, printSuggestedFixCommandSkips, printCoverage, printSkippedDependencies, printGroupSummary, printTable, printPathHints, printFinalStatus, printCompactOutput } from "./output/printers.js";
|
|
17
|
+
let parsedArgs = null;
|
|
18
|
+
try {
|
|
19
|
+
parsedArgs = parseArgs(process.argv.slice(2));
|
|
22
20
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
catch (error) {
|
|
22
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
23
|
+
console.error(chalk.red(`Error: ${message}`));
|
|
24
|
+
console.error(chalk.gray("Run `cve-lite --help` to see supported options."));
|
|
25
|
+
process.exit(1);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
console.log(event.message);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
spinner.update(event.message);
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
if (usePlainProgressLogs) {
|
|
52
|
-
console.log(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
27
|
+
if (parsedArgs) {
|
|
28
|
+
const { command, options, projectArg } = parsedArgs;
|
|
29
|
+
const cliVersion = getCliVersion();
|
|
30
|
+
if (options.help) {
|
|
31
|
+
printHelp();
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
else if (options.version) {
|
|
35
|
+
printBanner();
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const projectPath = path.resolve(projectArg || ".");
|
|
40
|
+
const batchSize = Number(options.batchSize || 100);
|
|
41
|
+
const searchDepth = Math.max(0, Number(options.searchDepth || 4));
|
|
42
|
+
async function main() {
|
|
43
|
+
if (!options.json) {
|
|
44
|
+
printBanner();
|
|
53
45
|
}
|
|
54
|
-
|
|
55
|
-
spinner
|
|
46
|
+
if (command === "advisories-sync") {
|
|
47
|
+
const spinner = createSpinner("Preparing advisory sync...", options);
|
|
48
|
+
const usePlainProgressLogs = !process.stdout.isTTY || !!options.json;
|
|
49
|
+
const result = await syncOsvAdvisories({
|
|
50
|
+
outputPath: options.output,
|
|
51
|
+
onProgress: event => {
|
|
52
|
+
if (event.phase === "complete") {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (usePlainProgressLogs) {
|
|
56
|
+
console.log(event.message);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
spinner.update(event.message);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
if (usePlainProgressLogs) {
|
|
63
|
+
console.log(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
spinner.succeed(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
67
|
+
}
|
|
68
|
+
console.log(`${chalk.gray("Advisory database:")} synced ${result.advisoryCount} record${result.advisoryCount === 1 ? "" : "s"} to ${chalk.cyan(result.dbPath)}`);
|
|
69
|
+
process.exit(0);
|
|
70
|
+
return;
|
|
56
71
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if ((options.offline || options.offlineDb) && options.osvUrl) {
|
|
62
|
-
throw new Error("--offline/--offline-db cannot be used with --osv-url");
|
|
63
|
-
}
|
|
64
|
-
if (options.osvUrl) {
|
|
65
|
-
try {
|
|
66
|
-
new URL(options.osvUrl);
|
|
72
|
+
if ((options.offline || options.offlineDb) && options.osvUrl) {
|
|
73
|
+
throw new Error("--offline/--offline-db cannot be used with --osv-url");
|
|
67
74
|
}
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
if (options.osvUrl) {
|
|
76
|
+
try {
|
|
77
|
+
new URL(options.osvUrl);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
throw new Error(`Invalid value for --osv-url: ${options.osvUrl}`);
|
|
81
|
+
}
|
|
70
82
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
let advisorySourceLine;
|
|
84
|
+
let advisoryDbFreshnessLine = null;
|
|
85
|
+
let advisoryDbWarning = null;
|
|
86
|
+
try {
|
|
87
|
+
const advisorySource = createAdvisorySource({
|
|
88
|
+
osvUrl: options.osvUrl,
|
|
89
|
+
offline: options.offline,
|
|
90
|
+
offlineDb: options.offlineDb,
|
|
91
|
+
});
|
|
92
|
+
advisorySourceLine = advisorySource.sourceLabel;
|
|
93
|
+
if (advisorySource.offline) {
|
|
94
|
+
const metadata = advisorySource.advisoryDbMetadata;
|
|
95
|
+
advisoryDbFreshnessLine = formatAdvisoryDbFreshness(metadata?.lastSyncAt ?? null);
|
|
96
|
+
if (advisorySource.advisoryDbIsStale) {
|
|
97
|
+
advisoryDbWarning = metadata?.lastSyncAt
|
|
98
|
+
? "The local advisory DB appears stale. Re-run `cve-lite advisories sync` to refresh it."
|
|
99
|
+
: "The local advisory DB has no recorded sync timestamp. Re-run `cve-lite advisories sync` to refresh it.";
|
|
100
|
+
}
|
|
89
101
|
}
|
|
102
|
+
advisorySource.cleanup();
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (options.offline || options.offlineDb) {
|
|
106
|
+
throw new Error(`Offline advisory database is not available: ${error instanceof Error ? error.message : String(error)}`);
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
90
109
|
}
|
|
91
|
-
advisorySource.cleanup();
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
110
|
if (options.offline || options.offlineDb) {
|
|
95
|
-
|
|
111
|
+
console.log(chalk.gray("Offline mode:") + " " + chalk.yellow("enabled") + " " + chalk.gray("(no external advisory calls will be made)"));
|
|
96
112
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
console.log(chalk.gray("Offline mode:") + " " + chalk.yellow("enabled") + " " + chalk.gray("(no external advisory calls will be made)"));
|
|
101
|
-
}
|
|
102
|
-
console.log(`${chalk.gray("Advisory source:")} ${formatAdvisorySourceLine(advisorySourceLine)}`);
|
|
103
|
-
if (advisoryDbFreshnessLine) {
|
|
104
|
-
console.log(`${chalk.gray("Advisory DB freshness:")} ${advisoryDbFreshnessLine}`);
|
|
105
|
-
}
|
|
106
|
-
if (advisoryDbWarning) {
|
|
107
|
-
logWarn(advisoryDbWarning, options);
|
|
108
|
-
}
|
|
109
|
-
const scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
110
|
-
const packages = scanInput.packages;
|
|
111
|
-
logInfo(`Parsed ${packages.length} package${packages.length === 1 ? "" : "s"} from ${scanInput.source}${scanInput.filePath ? ` (${path.relative(projectPath, scanInput.filePath) || path.basename(scanInput.filePath)})` : ""}`, options);
|
|
112
|
-
printCacheSummary(options.cacheDir, options);
|
|
113
|
-
if (scanInput.warnings.length > 0) {
|
|
114
|
-
for (const warning of scanInput.warnings) {
|
|
115
|
-
logWarn(warning, options);
|
|
113
|
+
console.log(`${chalk.gray("Advisory source:")} ${formatAdvisorySourceLine(advisorySourceLine)}`);
|
|
114
|
+
if (advisoryDbFreshnessLine) {
|
|
115
|
+
console.log(`${chalk.gray("Advisory DB freshness:")} ${advisoryDbFreshnessLine}`);
|
|
116
116
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
120
|
-
process.exit(0);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const findings = await scanPackages(packages, batchSize, options);
|
|
124
|
-
const sorted = findings.sort((a, b) => severityOrder[b.severity] - severityOrder[a.severity]);
|
|
125
|
-
const coverage = buildCoverageNotes(scanInput, !!options.offline || !!options.offlineDb);
|
|
126
|
-
const minSeverity = normalizeSeverity(options.minSeverity || "medium");
|
|
127
|
-
const tableFindings = options.all ? sorted : sorted.filter(f => severityOrder[f.severity] >= severityOrder[minSeverity]);
|
|
128
|
-
const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, scanInput);
|
|
129
|
-
if (options.json) {
|
|
130
|
-
console.log(JSON.stringify({
|
|
131
|
-
projectPath,
|
|
132
|
-
mode: scanInput.mode,
|
|
133
|
-
source: scanInput.source,
|
|
134
|
-
packageCount: packages.length,
|
|
135
|
-
findingCount: sorted.length,
|
|
136
|
-
suggestedFixCommands,
|
|
137
|
-
notes: [...scanInput.notes, ...coverage],
|
|
138
|
-
warnings: scanInput.warnings,
|
|
139
|
-
skippedDependencies: scanInput.skippedDependencies,
|
|
140
|
-
findings: sorted.map(serializeFinding)
|
|
141
|
-
}, null, 2));
|
|
142
|
-
}
|
|
143
|
-
else if (options.verbose) {
|
|
144
|
-
// Verbose output - show all details
|
|
145
|
-
printSummary(sorted, packages.length, scanInput);
|
|
146
|
-
printActionSummary(sorted);
|
|
147
|
-
printPriorityFixes(sorted);
|
|
148
|
-
printSuggestedFixCommands(sorted, scanInput);
|
|
149
|
-
printFixPlan(sorted);
|
|
150
|
-
printCoverage([...scanInput.notes, ...coverage]);
|
|
151
|
-
if (scanInput.skippedDependencies.length > 0) {
|
|
152
|
-
printSkippedDependencies(scanInput.skippedDependencies);
|
|
117
|
+
if (advisoryDbWarning) {
|
|
118
|
+
logWarn(advisoryDbWarning, options);
|
|
153
119
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
120
|
+
const scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
121
|
+
const packages = scanInput.packages;
|
|
122
|
+
logInfo(`Parsed ${packages.length} package${packages.length === 1 ? "" : "s"} from ${scanInput.source}${scanInput.filePath ? ` (${path.relative(projectPath, scanInput.filePath) || path.basename(scanInput.filePath)})` : ""}`, options);
|
|
123
|
+
printCacheSummary(options.cacheDir, options);
|
|
124
|
+
if (scanInput.warnings.length > 0) {
|
|
125
|
+
for (const warning of scanInput.warnings) {
|
|
126
|
+
logWarn(warning, options);
|
|
159
127
|
}
|
|
160
|
-
|
|
161
|
-
|
|
128
|
+
}
|
|
129
|
+
if (packages.length === 0) {
|
|
130
|
+
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
131
|
+
process.exit(0);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const findings = await scanPackages(packages, batchSize, options);
|
|
135
|
+
const sorted = findings.sort((a, b) => severityOrder[b.severity] - severityOrder[a.severity]);
|
|
136
|
+
const coverage = buildCoverageNotes(scanInput, !!options.offline || !!options.offlineDb);
|
|
137
|
+
const minSeverity = normalizeSeverity(options.minSeverity || "medium");
|
|
138
|
+
const tableFindings = options.all ? sorted : sorted.filter(f => severityOrder[f.severity] >= severityOrder[minSeverity]);
|
|
139
|
+
const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, scanInput);
|
|
140
|
+
if (options.json) {
|
|
141
|
+
console.log(JSON.stringify({
|
|
142
|
+
projectPath,
|
|
143
|
+
mode: scanInput.mode,
|
|
144
|
+
source: scanInput.source,
|
|
145
|
+
packageCount: packages.length,
|
|
146
|
+
findingCount: sorted.length,
|
|
147
|
+
suggestedFixCommands,
|
|
148
|
+
notes: [...scanInput.notes, ...coverage],
|
|
149
|
+
warnings: scanInput.warnings,
|
|
150
|
+
skippedDependencies: scanInput.skippedDependencies,
|
|
151
|
+
findings: sorted.map(serializeFinding)
|
|
152
|
+
}, null, 2));
|
|
153
|
+
}
|
|
154
|
+
else if (options.verbose) {
|
|
155
|
+
// Verbose output - show all details
|
|
156
|
+
printSummary(sorted, packages.length, scanInput);
|
|
157
|
+
printActionSummary(sorted);
|
|
158
|
+
printSuggestedFixCommands(sorted, scanInput);
|
|
159
|
+
printPriorityFixes(sorted);
|
|
160
|
+
printFixPlan(sorted);
|
|
161
|
+
printSuggestedFixCommandSkips(sorted, scanInput);
|
|
162
|
+
printCoverage([...scanInput.notes, ...coverage]);
|
|
163
|
+
if (scanInput.skippedDependencies.length > 0) {
|
|
164
|
+
printSkippedDependencies(scanInput.skippedDependencies);
|
|
165
|
+
}
|
|
166
|
+
if (sorted.length > 0) {
|
|
167
|
+
printGroupSummary(sorted);
|
|
168
|
+
if (tableFindings.length > 0) {
|
|
169
|
+
printTable(tableFindings, options.all ? null : minSeverity);
|
|
170
|
+
printPathHints(tableFindings);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
logInfo(`No findings met the table threshold of ${minSeverity}. Re-run with --all to show everything.`, options);
|
|
174
|
+
}
|
|
162
175
|
}
|
|
176
|
+
printFinalStatus(sorted);
|
|
163
177
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
178
|
+
else {
|
|
179
|
+
// Simplified output - cleaner, focused view
|
|
180
|
+
printCompactOutput(sorted, scanInput);
|
|
181
|
+
}
|
|
182
|
+
const failLevel = normalizeSeverity(options.failOn);
|
|
183
|
+
const shouldFail = sorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
184
|
+
process.exit(shouldFail ? 1 : 0);
|
|
185
|
+
return;
|
|
169
186
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
187
|
+
main().catch((error) => {
|
|
188
|
+
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
189
|
+
process.exit(1);
|
|
190
|
+
});
|
|
174
191
|
}
|
|
175
|
-
main().catch((error) => {
|
|
176
|
-
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
177
|
-
process.exit(1);
|
|
178
|
-
});
|
|
179
192
|
}
|
|
180
193
|
function formatAdvisorySourceLine(sourceLabel) {
|
|
181
194
|
const match = sourceLabel.match(/^(.*) \((.*)\)$/);
|
|
@@ -94,6 +94,8 @@ export function serializeFinding(finding) {
|
|
|
94
94
|
severity: finding.severity,
|
|
95
95
|
relationship: finding.relationship,
|
|
96
96
|
firstFixedVersion: finding.firstFixedVersion,
|
|
97
|
+
validatedFirstFixedVersion: finding.validatedFirstFixedVersion ?? null,
|
|
98
|
+
fixVersionValidationNote: finding.fixVersionValidationNote ?? null,
|
|
97
99
|
recommendedAction: getRecommendedAction(finding),
|
|
98
100
|
primaryParent: getPrimaryParent(finding),
|
|
99
101
|
recommendedParentUpgrade: finding.recommendedParentUpgrade,
|
package/dist/output/printers.js
CHANGED
|
@@ -119,24 +119,49 @@ export function printSuggestedFixCommands(findings, scanInput) {
|
|
|
119
119
|
const plan = buildSuggestedFixCommandPlan(findings, scanInput);
|
|
120
120
|
if (!plan)
|
|
121
121
|
return;
|
|
122
|
-
if (
|
|
122
|
+
if (plan.sections.length === 0)
|
|
123
123
|
return;
|
|
124
124
|
console.log("");
|
|
125
|
-
console.log(chalk.bold.
|
|
125
|
+
console.log(chalk.bold.yellow("🛠 Copy And Run These Fix Commands"));
|
|
126
126
|
console.log(`${chalk.gray("Detected package manager:")} ${chalk.cyan(plan.packageManager)} ${chalk.gray(`(${plan.sourceLabel})`)}`);
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
console.log(chalk.white(formatFixCommandSummary(plan)));
|
|
128
|
+
for (const section of plan.sections) {
|
|
129
|
+
console.log("");
|
|
130
|
+
console.log(colorFixSectionTitle(section.severity, section.title));
|
|
131
|
+
if (section.kind === "direct-adjusted") {
|
|
132
|
+
for (const target of section.targets) {
|
|
133
|
+
if (!target.adjustmentNote)
|
|
134
|
+
continue;
|
|
135
|
+
console.log(chalk.gray(` Note: ${target.adjustmentNote}`));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
console.log(renderCommandCallout(section.command));
|
|
129
139
|
}
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
}
|
|
141
|
+
export function printSuggestedFixCommandSkips(findings, scanInput) {
|
|
142
|
+
const plan = buildSuggestedFixCommandPlan(findings, scanInput);
|
|
143
|
+
if (!plan || plan.skipped.length === 0)
|
|
144
|
+
return;
|
|
145
|
+
const unpublishable = plan.skipped.filter(skipped => skipped.reason.includes("not published on npm"));
|
|
146
|
+
const remaining = plan.skipped.filter(skipped => !skipped.reason.includes("not published on npm"));
|
|
147
|
+
if (unpublishable.length > 0) {
|
|
148
|
+
console.log("");
|
|
149
|
+
console.log(chalk.gray("Unpublishable fixed-version hints:"));
|
|
150
|
+
for (const skipped of unpublishable.slice(0, 5)) {
|
|
151
|
+
console.log(`- ${skipped.package}@${skipped.version}: ${skipped.reason}`);
|
|
152
|
+
}
|
|
153
|
+
if (unpublishable.length > 5) {
|
|
154
|
+
console.log(`- ...and ${unpublishable.length - 5} more`);
|
|
155
|
+
}
|
|
132
156
|
}
|
|
133
|
-
if (
|
|
157
|
+
if (remaining.length > 0) {
|
|
158
|
+
console.log("");
|
|
134
159
|
console.log(chalk.gray("Not included automatically:"));
|
|
135
|
-
for (const skipped of
|
|
160
|
+
for (const skipped of remaining.slice(0, 5)) {
|
|
136
161
|
console.log(`- ${skipped.package}@${skipped.version}: ${skipped.reason}`);
|
|
137
162
|
}
|
|
138
|
-
if (
|
|
139
|
-
console.log(`- ...and ${
|
|
163
|
+
if (remaining.length > 5) {
|
|
164
|
+
console.log(`- ...and ${remaining.length - 5} more`);
|
|
140
165
|
}
|
|
141
166
|
}
|
|
142
167
|
}
|
|
@@ -291,11 +316,34 @@ export function printCompactOutput(findings, scanInput) {
|
|
|
291
316
|
}
|
|
292
317
|
console.log("");
|
|
293
318
|
}
|
|
319
|
+
const plan = scanInput ? buildSuggestedFixCommandPlan(findings, scanInput) : null;
|
|
320
|
+
if (plan) {
|
|
321
|
+
if (plan?.sections.length) {
|
|
322
|
+
console.log("────────────────────────────────");
|
|
323
|
+
console.log(chalk.bold.yellow("🛠 Copy And Run These Fix Commands"));
|
|
324
|
+
console.log("────────────────────────────────\n");
|
|
325
|
+
console.log(`${chalk.gray("Detected package manager:")} ${chalk.cyan(plan.packageManager)} ${chalk.gray(`(${plan.sourceLabel})`)}`);
|
|
326
|
+
console.log(formatFixCommandSummary(plan));
|
|
327
|
+
console.log("");
|
|
328
|
+
for (const section of plan.sections.slice(0, 3)) {
|
|
329
|
+
console.log(`${section.title}`);
|
|
330
|
+
if (section.kind === "direct-adjusted") {
|
|
331
|
+
for (const target of section.targets) {
|
|
332
|
+
if (!target.adjustmentNote)
|
|
333
|
+
continue;
|
|
334
|
+
console.log(chalk.gray(` Note: ${target.adjustmentNote}`));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
console.log(renderCommandCallout(section.command));
|
|
338
|
+
console.log("");
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
294
342
|
// Top Priority Fix section
|
|
295
343
|
if (urgentFindings.length > 0) {
|
|
296
344
|
const topFinding = urgentFindings[0];
|
|
297
345
|
console.log("────────────────────────────────");
|
|
298
|
-
console.log(chalk.bold("🚀 Top Priority
|
|
346
|
+
console.log(chalk.bold("🚀 Top Priority Issue"));
|
|
299
347
|
console.log("────────────────────────────────\n");
|
|
300
348
|
if (topFinding.relationship === "direct" && topFinding.firstFixedVersion) {
|
|
301
349
|
console.log(`Upgrade ${chalk.whiteBright(topFinding.pkg.name)} → ${topFinding.firstFixedVersion}`);
|
|
@@ -315,17 +363,17 @@ export function printCompactOutput(findings, scanInput) {
|
|
|
315
363
|
console.log(`Upgrade parent chain to resolve ${chalk.whiteBright(topFinding.pkg.name)}`);
|
|
316
364
|
}
|
|
317
365
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
console.log("");
|
|
366
|
+
if (plan) {
|
|
367
|
+
const topFindingCommand = findSuggestedCommandForFinding(plan, topFinding);
|
|
368
|
+
if (topFindingCommand) {
|
|
369
|
+
console.log(chalk.gray("Command:"));
|
|
370
|
+
console.log(renderCommandCallout(topFindingCommand));
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
console.log(chalk.gray("No confident automatic command is available for this issue yet."));
|
|
374
|
+
}
|
|
328
375
|
}
|
|
376
|
+
console.log("");
|
|
329
377
|
}
|
|
330
378
|
// Summary
|
|
331
379
|
console.log("────────────────────────────────");
|
|
@@ -368,3 +416,54 @@ export function printCompactOutput(findings, scanInput) {
|
|
|
368
416
|
console.log(chalk.gray(`Run with ${chalk.whiteBright("--verbose")} for fix plan, paths, and full table.`));
|
|
369
417
|
console.log("");
|
|
370
418
|
}
|
|
419
|
+
function colorFixSectionTitle(severity, title) {
|
|
420
|
+
if (severity === "critical")
|
|
421
|
+
return chalk.redBright(title);
|
|
422
|
+
if (severity === "high")
|
|
423
|
+
return chalk.magenta(title);
|
|
424
|
+
if (severity === "medium")
|
|
425
|
+
return chalk.yellow(title);
|
|
426
|
+
if (severity === "low")
|
|
427
|
+
return chalk.green(title);
|
|
428
|
+
return chalk.gray(title);
|
|
429
|
+
}
|
|
430
|
+
function formatFixCommandSummary(plan) {
|
|
431
|
+
if (!plan)
|
|
432
|
+
return "";
|
|
433
|
+
const packageCount = plan.targets.length;
|
|
434
|
+
const sectionCount = plan.sections.length;
|
|
435
|
+
const severityCounts = new Map();
|
|
436
|
+
for (const section of plan.sections) {
|
|
437
|
+
severityCounts.set(section.severity, (severityCounts.get(section.severity) ?? 0) + 1);
|
|
438
|
+
}
|
|
439
|
+
const severitySummary = ["critical", "high", "medium", "low", "unknown"]
|
|
440
|
+
.filter(severity => (severityCounts.get(severity) ?? 0) > 0)
|
|
441
|
+
.map(severity => `${severityCounts.get(severity)} ${severity}`)
|
|
442
|
+
.join(", ");
|
|
443
|
+
const packageLabel = packageCount === 1 ? "package" : "packages";
|
|
444
|
+
const sectionLabel = sectionCount === 1 ? "group" : "groups";
|
|
445
|
+
return `${sectionCount} command ${sectionLabel} ready across ${packageCount} ${packageLabel}${severitySummary ? ` (${severitySummary})` : ""}.`;
|
|
446
|
+
}
|
|
447
|
+
function renderCommandCallout(command) {
|
|
448
|
+
return chalk.bold.cyan(`> ${command}`);
|
|
449
|
+
}
|
|
450
|
+
function findSuggestedCommandForFinding(plan, finding) {
|
|
451
|
+
const target = plan.targets.find(item => {
|
|
452
|
+
if (finding.recommendedParentUpgrade) {
|
|
453
|
+
return (item.package === finding.recommendedParentUpgrade.package &&
|
|
454
|
+
item.targetVersion === finding.recommendedParentUpgrade.targetVersion);
|
|
455
|
+
}
|
|
456
|
+
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
457
|
+
return item.package === finding.pkg.name && item.targetVersion === directTarget;
|
|
458
|
+
});
|
|
459
|
+
if (!target)
|
|
460
|
+
return null;
|
|
461
|
+
return `${packageManagerCommandPrefix(plan.packageManager)} ${target.package}@${target.targetVersion}`;
|
|
462
|
+
}
|
|
463
|
+
function packageManagerCommandPrefix(packageManager) {
|
|
464
|
+
if (packageManager === "npm")
|
|
465
|
+
return "npm install";
|
|
466
|
+
if (packageManager === "pnpm")
|
|
467
|
+
return "pnpm add";
|
|
468
|
+
return "yarn add";
|
|
469
|
+
}
|
|
@@ -4,7 +4,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
4
4
|
const packageManager = inferPackageManager(scanInput);
|
|
5
5
|
if (!packageManager)
|
|
6
6
|
return null;
|
|
7
|
-
const
|
|
7
|
+
const prioritizedFindings = [...findings]
|
|
8
8
|
.filter(f => f.severity === "critical" || f.severity === "high")
|
|
9
9
|
.sort((a, b) => {
|
|
10
10
|
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
@@ -18,45 +18,114 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
18
18
|
});
|
|
19
19
|
const targetsByPackage = new Map();
|
|
20
20
|
const skippedByKey = new Map();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const orderedFindings = [
|
|
22
|
+
...prioritizedFindings,
|
|
23
|
+
...findings
|
|
24
|
+
.filter(f => f.severity !== "critical" && f.severity !== "high")
|
|
25
|
+
.sort((a, b) => {
|
|
26
|
+
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
27
|
+
if (sevDelta !== 0)
|
|
28
|
+
return sevDelta;
|
|
29
|
+
const relScore = (finding) => finding.relationship === "direct" ? 1 : 0;
|
|
30
|
+
const relDelta = relScore(b) - relScore(a);
|
|
31
|
+
if (relDelta !== 0)
|
|
32
|
+
return relDelta;
|
|
33
|
+
return a.pkg.name.localeCompare(b.pkg.name);
|
|
34
|
+
}),
|
|
35
|
+
];
|
|
36
|
+
for (const finding of orderedFindings) {
|
|
37
|
+
const urgent = finding.severity === "critical" || finding.severity === "high";
|
|
38
|
+
if (finding.relationship === "direct" || finding.relationship === "unknown") {
|
|
39
|
+
const hasValidatedField = Object.prototype.hasOwnProperty.call(finding, "validatedFirstFixedVersion");
|
|
40
|
+
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
41
|
+
if (directTarget &&
|
|
42
|
+
isUpgradeTarget(finding.pkg.version, directTarget) &&
|
|
43
|
+
(!hasValidatedField || finding.validatedFirstFixedVersion !== null)) {
|
|
24
44
|
upsertTarget(targetsByPackage, {
|
|
25
45
|
package: finding.pkg.name,
|
|
26
|
-
targetVersion:
|
|
46
|
+
targetVersion: directTarget,
|
|
27
47
|
kind: "direct",
|
|
48
|
+
urgent,
|
|
49
|
+
severity: finding.severity,
|
|
50
|
+
adjusted: Boolean(finding.fixVersionValidationNote &&
|
|
51
|
+
finding.validatedFirstFixedVersion &&
|
|
52
|
+
finding.validatedFirstFixedVersion !== finding.firstFixedVersion),
|
|
53
|
+
adjustmentNote: finding.fixVersionValidationNote &&
|
|
54
|
+
finding.validatedFirstFixedVersion &&
|
|
55
|
+
finding.validatedFirstFixedVersion !== finding.firstFixedVersion
|
|
56
|
+
? finding.fixVersionValidationNote
|
|
57
|
+
: null,
|
|
28
58
|
reason: `Direct upgrade target for ${finding.pkg.name}@${finding.pkg.version}`,
|
|
29
59
|
});
|
|
30
60
|
}
|
|
61
|
+
else if (finding.fixVersionValidationNote) {
|
|
62
|
+
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
63
|
+
package: finding.pkg.name,
|
|
64
|
+
version: finding.pkg.version,
|
|
65
|
+
relationship: finding.relationship,
|
|
66
|
+
reason: finding.fixVersionValidationNote,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else if (finding.firstFixedVersion) {
|
|
70
|
+
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
71
|
+
package: finding.pkg.name,
|
|
72
|
+
version: finding.pkg.version,
|
|
73
|
+
relationship: finding.relationship,
|
|
74
|
+
reason: `Fixed-version hint ${directTarget} is not an upgrade from installed ${finding.pkg.version}.`,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
31
77
|
else {
|
|
32
78
|
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
33
79
|
package: finding.pkg.name,
|
|
34
80
|
version: finding.pkg.version,
|
|
35
81
|
relationship: finding.relationship,
|
|
36
|
-
reason:
|
|
82
|
+
reason: urgent
|
|
83
|
+
? "No safe upgrade target is known for this urgent direct dependency."
|
|
84
|
+
: "No safe upgrade target is known for this direct dependency.",
|
|
37
85
|
});
|
|
38
86
|
}
|
|
39
87
|
continue;
|
|
40
88
|
}
|
|
41
|
-
if (finding.relationship === "transitive" &&
|
|
89
|
+
if (finding.relationship === "transitive" &&
|
|
90
|
+
finding.recommendedParentUpgrade &&
|
|
91
|
+
isUpgradeTarget(finding.recommendedParentUpgrade.currentVersion, finding.recommendedParentUpgrade.targetVersion)) {
|
|
42
92
|
upsertTarget(targetsByPackage, {
|
|
43
93
|
package: finding.recommendedParentUpgrade.package,
|
|
44
94
|
targetVersion: finding.recommendedParentUpgrade.targetVersion,
|
|
45
95
|
kind: "parent-upgrade",
|
|
96
|
+
urgent,
|
|
97
|
+
severity: finding.severity,
|
|
98
|
+
adjusted: false,
|
|
99
|
+
adjustmentNote: null,
|
|
46
100
|
reason: `Parent upgrade for vulnerable ${finding.pkg.name}@${finding.pkg.version}`,
|
|
47
101
|
});
|
|
48
102
|
continue;
|
|
49
103
|
}
|
|
104
|
+
if (finding.relationship === "transitive" && finding.recommendedParentUpgrade) {
|
|
105
|
+
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
106
|
+
package: finding.pkg.name,
|
|
107
|
+
version: finding.pkg.version,
|
|
108
|
+
relationship: finding.relationship,
|
|
109
|
+
reason: `Suggested parent target ${finding.recommendedParentUpgrade.package}@${finding.recommendedParentUpgrade.targetVersion} is not an upgrade from installed ${finding.recommendedParentUpgrade.currentVersion}.`,
|
|
110
|
+
});
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
50
113
|
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
51
114
|
package: finding.pkg.name,
|
|
52
115
|
version: finding.pkg.version,
|
|
53
116
|
relationship: finding.relationship,
|
|
54
117
|
reason: finding.relationship === "transitive"
|
|
55
|
-
? "No specific parent upgrade target was found for this
|
|
118
|
+
? "No specific parent upgrade target was found for this transitive issue."
|
|
56
119
|
: "No confident automatic fix command could be generated for this issue.",
|
|
57
120
|
});
|
|
58
121
|
}
|
|
59
122
|
const targets = [...targetsByPackage.values()].sort((a, b) => {
|
|
123
|
+
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
124
|
+
if (sevDelta !== 0)
|
|
125
|
+
return sevDelta;
|
|
126
|
+
const urgentDelta = Number(b.urgent) - Number(a.urgent);
|
|
127
|
+
if (urgentDelta !== 0)
|
|
128
|
+
return urgentDelta;
|
|
60
129
|
const kindScore = (target) => target.kind === "direct" ? 1 : 0;
|
|
61
130
|
const kindDelta = kindScore(b) - kindScore(a);
|
|
62
131
|
if (kindDelta !== 0)
|
|
@@ -64,6 +133,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
64
133
|
return a.package.localeCompare(b.package);
|
|
65
134
|
});
|
|
66
135
|
const skipped = [...skippedByKey.values()].sort((a, b) => a.package.localeCompare(b.package));
|
|
136
|
+
const sections = buildSections(targets, packageManager);
|
|
67
137
|
const command = targets.length > 0
|
|
68
138
|
? `${commandPrefix(packageManager)} ${targets.map(target => `${target.package}@${target.targetVersion}`).join(" ")}`
|
|
69
139
|
: null;
|
|
@@ -71,6 +141,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
71
141
|
packageManager,
|
|
72
142
|
sourceLabel: packageManagerSourceLabel(scanInput),
|
|
73
143
|
command,
|
|
144
|
+
sections,
|
|
74
145
|
targets,
|
|
75
146
|
skipped,
|
|
76
147
|
};
|
|
@@ -109,13 +180,88 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
109
180
|
targetsByPackage.set(next.package, next);
|
|
110
181
|
return;
|
|
111
182
|
}
|
|
183
|
+
const merged = {
|
|
184
|
+
...existing,
|
|
185
|
+
urgent: existing.urgent || next.urgent,
|
|
186
|
+
severity: severityOrder[next.severity] > severityOrder[existing.severity] ? next.severity : existing.severity,
|
|
187
|
+
adjusted: existing.adjusted || next.adjusted,
|
|
188
|
+
adjustmentNote: existing.adjustmentNote ?? next.adjustmentNote ?? null,
|
|
189
|
+
kind: existing.kind === "direct" || next.kind === "direct" ? "direct" : "parent-upgrade",
|
|
190
|
+
};
|
|
112
191
|
if (looksLikeVersion(existing.targetVersion) && looksLikeVersion(next.targetVersion)) {
|
|
113
192
|
if (compareVersions(next.targetVersion, existing.targetVersion) > 0) {
|
|
114
|
-
|
|
193
|
+
merged.targetVersion = next.targetVersion;
|
|
194
|
+
merged.reason = next.reason;
|
|
115
195
|
}
|
|
196
|
+
targetsByPackage.set(next.package, merged);
|
|
116
197
|
return;
|
|
117
198
|
}
|
|
118
199
|
if (next.kind === "direct" && existing.kind !== "direct") {
|
|
119
|
-
|
|
200
|
+
merged.targetVersion = next.targetVersion;
|
|
201
|
+
merged.reason = next.reason;
|
|
202
|
+
merged.adjustmentNote = next.adjustmentNote ?? merged.adjustmentNote;
|
|
120
203
|
}
|
|
204
|
+
targetsByPackage.set(next.package, merged);
|
|
205
|
+
}
|
|
206
|
+
function isUpgradeTarget(currentVersion, targetVersion) {
|
|
207
|
+
if (!currentVersion || !targetVersion || currentVersion === targetVersion)
|
|
208
|
+
return false;
|
|
209
|
+
if (looksLikeVersion(currentVersion) && looksLikeVersion(targetVersion)) {
|
|
210
|
+
return compareVersions(targetVersion, currentVersion) > 0;
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
function buildSections(targets, packageManager) {
|
|
215
|
+
const groups = [];
|
|
216
|
+
const commandForTargets = (items) => `${commandPrefix(packageManager)} ${items.map(target => `${target.package}@${target.targetVersion}`).join(" ")}`;
|
|
217
|
+
const sectionOrder = [
|
|
218
|
+
{ kind: "urgent", severity: "critical" },
|
|
219
|
+
{ kind: "urgent", severity: "high" },
|
|
220
|
+
{ kind: "direct", severity: "medium" },
|
|
221
|
+
{ kind: "direct", severity: "low" },
|
|
222
|
+
{ kind: "direct", severity: "unknown" },
|
|
223
|
+
{ kind: "direct-adjusted", severity: "medium" },
|
|
224
|
+
{ kind: "direct-adjusted", severity: "low" },
|
|
225
|
+
{ kind: "direct-adjusted", severity: "unknown" },
|
|
226
|
+
{ kind: "parent-upgrade", severity: "medium" },
|
|
227
|
+
{ kind: "parent-upgrade", severity: "low" },
|
|
228
|
+
{ kind: "parent-upgrade", severity: "unknown" },
|
|
229
|
+
];
|
|
230
|
+
for (const entry of sectionOrder) {
|
|
231
|
+
const sectionTargets = targets.filter(target => {
|
|
232
|
+
const targetKind = target.urgent ? "urgent" : target.adjusted ? "direct-adjusted" : target.kind;
|
|
233
|
+
return targetKind === entry.kind && target.severity === entry.severity;
|
|
234
|
+
});
|
|
235
|
+
if (sectionTargets.length === 0)
|
|
236
|
+
continue;
|
|
237
|
+
groups.push({
|
|
238
|
+
key: `${entry.kind}:${entry.severity}`,
|
|
239
|
+
kind: entry.kind,
|
|
240
|
+
severity: entry.severity,
|
|
241
|
+
title: buildSectionTitle(entry.kind, entry.severity),
|
|
242
|
+
command: commandForTargets(sectionTargets),
|
|
243
|
+
targets: sectionTargets,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return groups;
|
|
247
|
+
}
|
|
248
|
+
function buildSectionTitle(kind, severity) {
|
|
249
|
+
const severityTitle = severity === "unknown"
|
|
250
|
+
? "Unknown severity"
|
|
251
|
+
: `${capitalize(severity)} severity`;
|
|
252
|
+
if (kind === "urgent") {
|
|
253
|
+
return severity === "critical"
|
|
254
|
+
? "Critical severity fix commands"
|
|
255
|
+
: "High severity fix commands";
|
|
256
|
+
}
|
|
257
|
+
if (kind === "direct") {
|
|
258
|
+
return `${severityTitle} direct fixes`;
|
|
259
|
+
}
|
|
260
|
+
if (kind === "direct-adjusted") {
|
|
261
|
+
return `${severityTitle} direct fixes (registry-adjusted)`;
|
|
262
|
+
}
|
|
263
|
+
return `${severityTitle} parent upgrades`;
|
|
264
|
+
}
|
|
265
|
+
function capitalize(value) {
|
|
266
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
121
267
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
2
|
+
const packumentCache = new Map();
|
|
3
|
+
const DEFAULT_NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
4
|
+
export function clearPackumentCache() {
|
|
5
|
+
packumentCache.clear();
|
|
6
|
+
}
|
|
7
|
+
export async function fetchPackument(packageName) {
|
|
8
|
+
if (packumentCache.has(packageName)) {
|
|
9
|
+
return packumentCache.get(packageName) ?? null;
|
|
10
|
+
}
|
|
11
|
+
const url = `${DEFAULT_NPM_REGISTRY_URL}/${encodeURIComponent(packageName)
|
|
12
|
+
.replace(/%40/g, "@")
|
|
13
|
+
.replace(/%2F/g, "/")}`;
|
|
14
|
+
try {
|
|
15
|
+
const response = await fetch(url);
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
packumentCache.set(packageName, null);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const json = (await response.json());
|
|
21
|
+
packumentCache.set(packageName, json);
|
|
22
|
+
return json;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
packumentCache.set(packageName, null);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export async function packageVersionExists(packageName, version) {
|
|
30
|
+
const packument = await fetchPackument(packageName);
|
|
31
|
+
if (!packument)
|
|
32
|
+
return null;
|
|
33
|
+
return Boolean(packument.versions && version in packument.versions);
|
|
34
|
+
}
|
|
35
|
+
export async function resolvePublishedFixVersion(packageName, fixedVersionHint) {
|
|
36
|
+
const packument = await fetchPackument(packageName);
|
|
37
|
+
if (!packument) {
|
|
38
|
+
return {
|
|
39
|
+
resolvedVersion: null,
|
|
40
|
+
note: `Fixed-version hint ${fixedVersionHint} could not be verified against the npm registry for ${packageName}.`,
|
|
41
|
+
verified: false,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const publishedVersions = Object.keys(packument.versions ?? {})
|
|
45
|
+
.filter(looksLikeVersion)
|
|
46
|
+
.sort(compareVersions);
|
|
47
|
+
if (publishedVersions.includes(fixedVersionHint)) {
|
|
48
|
+
return {
|
|
49
|
+
resolvedVersion: fixedVersionHint,
|
|
50
|
+
note: null,
|
|
51
|
+
verified: true,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const nearestPublishedVersion = publishedVersions.find(version => compareVersions(version, fixedVersionHint) >= 0) ?? null;
|
|
55
|
+
if (nearestPublishedVersion) {
|
|
56
|
+
return {
|
|
57
|
+
resolvedVersion: nearestPublishedVersion,
|
|
58
|
+
note: `Advisory fixed-version hint ${fixedVersionHint} is not published on npm for ${packageName}; using nearest published version ${nearestPublishedVersion}.`,
|
|
59
|
+
verified: true,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
resolvedVersion: null,
|
|
64
|
+
note: `Advisory fixed-version hint ${fixedVersionHint} is not published on npm for ${packageName}, and no published version >= ${fixedVersionHint} was found.`,
|
|
65
|
+
verified: true,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
2
|
-
|
|
3
|
-
const DEFAULT_NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
2
|
+
import { fetchPackument } from "./npm-registry.js";
|
|
4
3
|
export async function resolveRecommendedParentUpgrade(finding, packages) {
|
|
5
4
|
if (finding.relationship !== "transitive")
|
|
6
5
|
return null;
|
|
@@ -132,22 +131,6 @@ async function findUpgradeForImmediateIntermediate(args) {
|
|
|
132
131
|
}
|
|
133
132
|
return null;
|
|
134
133
|
}
|
|
135
|
-
async function fetchPackument(packageName) {
|
|
136
|
-
if (packumentCache.has(packageName)) {
|
|
137
|
-
return packumentCache.get(packageName) ?? null;
|
|
138
|
-
}
|
|
139
|
-
const url = `${DEFAULT_NPM_REGISTRY_URL}/${encodeURIComponent(packageName)
|
|
140
|
-
.replace(/%40/g, "@")
|
|
141
|
-
.replace(/%2F/g, "/")}`;
|
|
142
|
-
const response = await fetch(url);
|
|
143
|
-
if (!response.ok) {
|
|
144
|
-
packumentCache.set(packageName, null);
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
const json = (await response.json());
|
|
148
|
-
packumentCache.set(packageName, json);
|
|
149
|
-
return json;
|
|
150
|
-
}
|
|
151
134
|
function versionSatisfiesRange(version, rawRange) {
|
|
152
135
|
const range = rawRange.trim();
|
|
153
136
|
if (!range)
|
package/dist/scanner.js
CHANGED
|
@@ -8,6 +8,7 @@ import { LocalAdvisorySource } from "./advisory/local-advisory-source.js";
|
|
|
8
8
|
import { LocalAdvisoryDatabase } from "./advisory/local-db.js";
|
|
9
9
|
import { ADVISORY_DB_STALE_AFTER_MS, getDefaultAdvisoryDbPath } from "./advisory/osv-sync.js";
|
|
10
10
|
import { resolveRecommendedParentUpgrade } from "./remediation/parent-upgrade.js";
|
|
11
|
+
import { resolvePublishedFixVersion } from "./remediation/npm-registry.js";
|
|
11
12
|
export function createAdvisorySource(options) {
|
|
12
13
|
const offline = !!options?.offline || !!options?.offlineDb;
|
|
13
14
|
if (offline) {
|
|
@@ -174,9 +175,14 @@ export async function scanPackages(packages, batchSize, options) {
|
|
|
174
175
|
dependencyPaths,
|
|
175
176
|
relationship,
|
|
176
177
|
firstFixedVersion,
|
|
178
|
+
validatedFirstFixedVersion: null,
|
|
179
|
+
fixVersionValidationNote: null,
|
|
177
180
|
recommendedParentUpgrade: undefined,
|
|
178
181
|
};
|
|
179
182
|
});
|
|
183
|
+
if (!offline) {
|
|
184
|
+
await validateDirectFixTargets(findings);
|
|
185
|
+
}
|
|
180
186
|
for (const finding of findings) {
|
|
181
187
|
if (finding.relationship !== "transitive" || offline)
|
|
182
188
|
continue;
|
|
@@ -197,6 +203,18 @@ export async function scanPackages(packages, batchSize, options) {
|
|
|
197
203
|
sourceContext.cleanup();
|
|
198
204
|
}
|
|
199
205
|
}
|
|
206
|
+
async function validateDirectFixTargets(findings) {
|
|
207
|
+
const directCandidates = findings.filter(finding => (finding.relationship === "direct" || finding.relationship === "unknown") &&
|
|
208
|
+
Boolean(finding.firstFixedVersion));
|
|
209
|
+
for (const finding of directCandidates) {
|
|
210
|
+
const targetVersion = finding.firstFixedVersion;
|
|
211
|
+
if (!targetVersion)
|
|
212
|
+
continue;
|
|
213
|
+
const resolution = await resolvePublishedFixVersion(finding.pkg.name, targetVersion);
|
|
214
|
+
finding.validatedFirstFixedVersion = resolution.resolvedVersion;
|
|
215
|
+
finding.fixVersionValidationNote = resolution.note;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
200
218
|
function isAdvisoryDbStale(metadata) {
|
|
201
219
|
if (!metadata.lastSyncAt) {
|
|
202
220
|
return true;
|