cve-lite-cli 1.5.0 β 1.5.2
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 +44 -9
- package/dist/cli/args.js +4 -0
- package/dist/cli/help.js +1 -0
- package/dist/index.js +245 -29
- package/dist/output/printers.js +45 -0
- package/dist/remediation/fix-commands.js +3 -0
- package/dist/scanner.js +7 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
<a href="#why-offline-mode-matters">Why offline mode matters</a><br/>
|
|
38
38
|
<a href="docs/case-studies/owasp-juice-shop.md">OWASP Juice Shop case study</a><br/>
|
|
39
39
|
<a href="docs/case-studies/nestjs.md">NestJS case study</a><br/>
|
|
40
|
+
<a href="docs/fix-mode.md">Fix mode guide (--fix)</a><br/>
|
|
41
|
+
<a href="docs/how-to-read-verbose-output.md">How to read verbose output</a><br/>
|
|
40
42
|
<a href="#what-it-looks-like">What it looks like</a><br/>
|
|
41
43
|
<a href="#why-this-tool-exists">Why this tool exists</a><br/>
|
|
42
44
|
<a href="#project-scope-and-differentiation">Project scope and differentiation</a>
|
|
@@ -81,15 +83,20 @@ It is designed to be:
|
|
|
81
83
|
- capable of zero-runtime-network scans through a local advisory database
|
|
82
84
|
|
|
83
85
|
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).
|
|
86
|
+
If you are new to verbose mode, use the [How to read verbose output guide](docs/how-to-read-verbose-output.md).
|
|
87
|
+
If you want automatic direct remediation, use the [Fix mode guide](docs/fix-mode.md).
|
|
84
88
|
|
|
85
89
|
## New here? Start here
|
|
86
90
|
|
|
91
|
+
If the verbose output feels dense at first, start with the [How to read verbose output guide](docs/how-to-read-verbose-output.md).
|
|
92
|
+
|
|
87
93
|
1. run one scan on a real project with `npx cve-lite-cli /path/to/project --verbose`
|
|
88
|
-
2. review direct vs transitive findings and the `Copy And Run These Fix Commands` section
|
|
94
|
+
2. review direct vs transitive findings and the `Copy And Run These Fix Commands` section (direct command groups apply to manifest-declared dependencies)
|
|
89
95
|
3. compare the output with your current scanner workflow
|
|
90
96
|
4. check a real walkthrough:
|
|
91
97
|
- [OWASP Juice Shop case study](docs/case-studies/owasp-juice-shop.md)
|
|
92
98
|
- [NestJS case study](docs/case-studies/nestjs.md)
|
|
99
|
+
5. use the [How to read verbose output guide](docs/how-to-read-verbose-output.md) to convert scan sections into next steps
|
|
93
100
|
|
|
94
101
|
If CVE Lite CLI helps your release workflow, a GitHub star helps more developers discover it: [Star CVE Lite CLI](https://github.com/sonukapoor/cve-lite-cli).
|
|
95
102
|
|
|
@@ -174,6 +181,9 @@ cve-lite /path/to/project --min-severity high
|
|
|
174
181
|
# Recommended for CI logs when you want full context
|
|
175
182
|
cve-lite /path/to/project --verbose
|
|
176
183
|
|
|
184
|
+
# Apply validated direct dependency fixes and rescan
|
|
185
|
+
cve-lite /path/to/project --fix
|
|
186
|
+
|
|
177
187
|
# Limit the scan to production dependencies where supported by the lockfile
|
|
178
188
|
cve-lite /path/to/project --prod-only
|
|
179
189
|
|
|
@@ -199,6 +209,29 @@ cve-lite /path/to/project --offline
|
|
|
199
209
|
cve-lite /path/to/project --offline-db /path/to/advisories.db
|
|
200
210
|
```
|
|
201
211
|
|
|
212
|
+
## Auto-fix mode (`--fix`)
|
|
213
|
+
|
|
214
|
+
`--fix` is designed to speed up remediation without overpromising safety.
|
|
215
|
+
|
|
216
|
+
In v1, `--fix`:
|
|
217
|
+
- applies only direct dependency fixes with a validated lowest known non-vulnerable target
|
|
218
|
+
- uses your projectβs package manager (`npm install`, `pnpm add`, or `yarn add`)
|
|
219
|
+
- rescans automatically after applying fixes
|
|
220
|
+
- prints a concise summary of applied fixes, skipped findings, and remaining findings
|
|
221
|
+
|
|
222
|
+
In v1, `--fix` does not:
|
|
223
|
+
- auto-apply transitive overrides/resolutions
|
|
224
|
+
- guarantee compatibility with your application code
|
|
225
|
+
- perform exploitability or runtime reachability analysis
|
|
226
|
+
|
|
227
|
+
Example:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
npx cve-lite-cli /path/to/project --fix
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
For output details and interpretation, see [Fix mode guide](docs/fix-mode.md).
|
|
234
|
+
|
|
202
235
|
## Workflow modes
|
|
203
236
|
|
|
204
237
|
CVE Lite CLI now supports three clear advisory workflows:
|
|
@@ -239,7 +272,7 @@ The most important section to look for in the output is:
|
|
|
239
272
|
π Copy And Run These Fix Commands
|
|
240
273
|
```
|
|
241
274
|
|
|
242
|
-
That is one of the clearest differentiators in CVE Lite CLI. Instead of only showing advisories and severity counts, the tool tries to turn
|
|
275
|
+
That is one of the clearest differentiators in CVE Lite CLI. Instead of only showing advisories and severity counts, the tool tries to turn findings into concrete commands developers can copy and run immediately for manifest-declared direct dependencies, while still showing parent-upgrade guidance for transitive issues when available.
|
|
243
276
|
|
|
244
277
|
For example, the tool can now suggest a concrete next command such as:
|
|
245
278
|
|
|
@@ -268,6 +301,7 @@ The final status line also gives the scan a clear ending, which makes terminal u
|
|
|
268
301
|
See the example below using OWASP Juice Shop for real output samples.
|
|
269
302
|
|
|
270
303
|
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).
|
|
304
|
+
For a section-by-section walkthrough of the terminal output, see [How to read verbose output](docs/how-to-read-verbose-output.md).
|
|
271
305
|
|
|
272
306
|
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.
|
|
273
307
|
|
|
@@ -526,6 +560,7 @@ The commands are:
|
|
|
526
560
|
- package-manager-aware
|
|
527
561
|
- grouped by severity and fix type
|
|
528
562
|
- designed to be copied directly from the terminal
|
|
563
|
+
- direct command groups are limited to dependencies declared in the scanned root manifest
|
|
529
564
|
- shown before the deeper remediation detail in verbose mode
|
|
530
565
|
- when enough advisory data exists, targeted to the lowest known non-vulnerable version with transparent version-scan counts in verbose output
|
|
531
566
|
|
|
@@ -799,13 +834,13 @@ Compared with other tools in this space, CVE Lite CLI focuses on:
|
|
|
799
834
|
|
|
800
835
|
### At a glance
|
|
801
836
|
|
|
802
|
-
| Tool | Best at | Ecosystem scope | Lockfile support | Dependency remediation guidance | JSON/SARIF | Best fit |
|
|
803
|
-
|
|
804
|
-
| **CVE Lite CLI** | Fast, developer-friendly pre-release CVE scanning | Focused on JS/TS | npm, pnpm, Yarn | **Dependency fix guidance** | **Yes** | Developers and small teams who want a free, practical release-time check |
|
|
805
|
-
| `npm audit` | Built-in npm auditing | npm-centric | npm | Basic remediation info | Limited compared to dedicated scanner workflows | Teams already living fully inside npm |
|
|
806
|
-
| OSV-Scanner | Broad multi-ecosystem scanning | Broad | Many ecosystems and lockfiles | More general-purpose | Strong machine-readable workflows | Teams needing wider ecosystem coverage |
|
|
807
|
-
| Snyk CLI | Broader enterprise security workflows | Broad | Strong ecosystem coverage | Strong commercial guidance | Strong | Teams adopting a larger security platform |
|
|
808
|
-
| Socket CLI | Broader package and supply-chain risk visibility | Broad | Multi-ecosystem/package-risk focus | Strong for package risk workflows | Strong | Teams that want more than CVE scanning alone |
|
|
837
|
+
| Tool | Best at | Ecosystem scope | Lockfile support | Dependency remediation guidance | Auto-fix support | JSON/SARIF | Best fit |
|
|
838
|
+
|---|---|---|---|---|---|---|---|
|
|
839
|
+
| **CVE Lite CLI** | Fast, developer-friendly pre-release CVE scanning | Focused on JS/TS | npm, pnpm, Yarn | **Dependency fix guidance** | **Yes (scoped `--fix` for validated direct dependencies in v1)** | **Yes** | Developers and small teams who want a free, practical release-time check |
|
|
840
|
+
| `npm audit` | Built-in npm auditing | npm-centric | npm | Basic remediation info | Yes (`npm audit fix`) | Limited compared to dedicated scanner workflows | Teams already living fully inside npm |
|
|
841
|
+
| OSV-Scanner | Broad multi-ecosystem scanning | Broad | Many ecosystems and lockfiles | More general-purpose | Yes (guided remediation, experimental) | Strong machine-readable workflows | Teams needing wider ecosystem coverage |
|
|
842
|
+
| Snyk CLI | Broader enterprise security workflows | Broad | Strong ecosystem coverage | Strong commercial guidance | Yes (CLI + platform-driven fix/PR workflows) | Strong | Teams adopting a larger security platform |
|
|
843
|
+
| Socket CLI | Broader package and supply-chain risk visibility | Broad | Multi-ecosystem/package-risk focus | Strong for package risk workflows | Varies by product/workflow | Strong | Teams that want more than CVE scanning alone |
|
|
809
844
|
|
|
810
845
|
### Offline support at a glance
|
|
811
846
|
|
package/dist/cli/args.js
CHANGED
package/dist/cli/help.js
CHANGED
|
@@ -31,6 +31,7 @@ export function printHelp() {
|
|
|
31
31
|
"",
|
|
32
32
|
"Scan options:",
|
|
33
33
|
" --json Print JSON output",
|
|
34
|
+
" --fix Apply validated direct dependency fixes and rescan",
|
|
34
35
|
" --osv-url <url> Use a custom OSV-compatible advisory endpoint",
|
|
35
36
|
" --verbose Show detailed output with fix plan, paths, and full table",
|
|
36
37
|
" --prod-only Exclude dev dependencies where available",
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
2
4
|
import path from "node:path";
|
|
3
5
|
import process from "node:process";
|
|
4
6
|
import { parseArgs } from "./cli/args.js";
|
|
@@ -80,6 +82,9 @@ if (parsedArgs) {
|
|
|
80
82
|
throw new Error(`Invalid value for --osv-url: ${options.osvUrl}`);
|
|
81
83
|
}
|
|
82
84
|
}
|
|
85
|
+
if (options.fix && options.json) {
|
|
86
|
+
throw new Error("--fix cannot be used with --json");
|
|
87
|
+
}
|
|
83
88
|
let advisorySourceLine;
|
|
84
89
|
let advisoryDbFreshnessLine = null;
|
|
85
90
|
let advisoryDbWarning = null;
|
|
@@ -117,8 +122,8 @@ if (parsedArgs) {
|
|
|
117
122
|
if (advisoryDbWarning) {
|
|
118
123
|
logWarn(advisoryDbWarning, options);
|
|
119
124
|
}
|
|
120
|
-
|
|
121
|
-
|
|
125
|
+
let scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
126
|
+
let packages = scanInput.packages;
|
|
122
127
|
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
128
|
printCacheSummary(options.cacheDir, options);
|
|
124
129
|
if (scanInput.warnings.length > 0) {
|
|
@@ -131,56 +136,90 @@ if (parsedArgs) {
|
|
|
131
136
|
process.exit(0);
|
|
132
137
|
return;
|
|
133
138
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
let scanState = await scanProject({
|
|
140
|
+
scanInput,
|
|
141
|
+
batchSize,
|
|
142
|
+
options,
|
|
143
|
+
projectPath,
|
|
144
|
+
});
|
|
145
|
+
const findingsBeforeFix = scanState.sorted.length;
|
|
146
|
+
let fixResult = null;
|
|
147
|
+
if (options.fix) {
|
|
148
|
+
fixResult = await applyFixesIfRequested({
|
|
149
|
+
plan: scanState.suggestedFixCommands,
|
|
150
|
+
projectPath,
|
|
151
|
+
totalFindings: scanState.sorted.length,
|
|
152
|
+
options,
|
|
153
|
+
});
|
|
154
|
+
if (fixResult.appliedFixCount > 0) {
|
|
155
|
+
console.log(`${chalk.cyan("β ")} ${chalk.gray("Rescanning project...")}`);
|
|
156
|
+
scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
157
|
+
packages = scanInput.packages;
|
|
158
|
+
if (packages.length === 0) {
|
|
159
|
+
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
160
|
+
process.exit(0);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
scanState = await scanProject({
|
|
164
|
+
scanInput,
|
|
165
|
+
batchSize,
|
|
166
|
+
options,
|
|
167
|
+
projectPath,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (options.fix) {
|
|
172
|
+
printFixModeSummary({
|
|
173
|
+
fixResult,
|
|
174
|
+
findingsBeforeFix,
|
|
175
|
+
findingsAfterFix: scanState.sorted.length,
|
|
176
|
+
remainingBySeverity: countBySeverity(scanState.sorted),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else if (options.json) {
|
|
141
180
|
console.log(JSON.stringify({
|
|
142
181
|
projectPath,
|
|
143
182
|
mode: scanInput.mode,
|
|
144
183
|
source: scanInput.source,
|
|
145
184
|
packageCount: packages.length,
|
|
146
|
-
findingCount: sorted.length,
|
|
147
|
-
suggestedFixCommands,
|
|
148
|
-
notes: [...scanInput.notes, ...coverage],
|
|
185
|
+
findingCount: scanState.sorted.length,
|
|
186
|
+
suggestedFixCommands: scanState.suggestedFixCommands,
|
|
187
|
+
notes: [...scanInput.notes, ...scanState.coverage],
|
|
149
188
|
warnings: scanInput.warnings,
|
|
150
189
|
skippedDependencies: scanInput.skippedDependencies,
|
|
151
|
-
findings: sorted.map(serializeFinding)
|
|
190
|
+
findings: scanState.sorted.map(serializeFinding)
|
|
152
191
|
}, null, 2));
|
|
153
192
|
}
|
|
154
193
|
else if (options.verbose) {
|
|
155
194
|
// 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]);
|
|
195
|
+
printSummary(scanState.sorted, packages.length, scanInput);
|
|
196
|
+
printActionSummary(scanState.sorted);
|
|
197
|
+
printSuggestedFixCommands(scanState.sorted, scanInput);
|
|
198
|
+
printPriorityFixes(scanState.sorted);
|
|
199
|
+
printFixPlan(scanState.sorted);
|
|
200
|
+
printSuggestedFixCommandSkips(scanState.sorted, scanInput);
|
|
201
|
+
printCoverage([...scanInput.notes, ...scanState.coverage]);
|
|
163
202
|
if (scanInput.skippedDependencies.length > 0) {
|
|
164
203
|
printSkippedDependencies(scanInput.skippedDependencies);
|
|
165
204
|
}
|
|
166
|
-
if (sorted.length > 0) {
|
|
167
|
-
printGroupSummary(sorted);
|
|
168
|
-
if (tableFindings.length > 0) {
|
|
169
|
-
printTable(tableFindings, options.all ? null : minSeverity);
|
|
170
|
-
printPathHints(tableFindings);
|
|
205
|
+
if (scanState.sorted.length > 0) {
|
|
206
|
+
printGroupSummary(scanState.sorted);
|
|
207
|
+
if (scanState.tableFindings.length > 0) {
|
|
208
|
+
printTable(scanState.tableFindings, options.all ? null : scanState.minSeverity);
|
|
209
|
+
printPathHints(scanState.tableFindings);
|
|
171
210
|
}
|
|
172
211
|
else {
|
|
173
|
-
logInfo(`No findings met the table threshold of ${minSeverity}. Re-run with --all to show everything.`, options);
|
|
212
|
+
logInfo(`No findings met the table threshold of ${scanState.minSeverity}. Re-run with --all to show everything.`, options);
|
|
174
213
|
}
|
|
175
214
|
}
|
|
176
|
-
printFinalStatus(sorted);
|
|
215
|
+
printFinalStatus(scanState.sorted);
|
|
177
216
|
}
|
|
178
217
|
else {
|
|
179
218
|
// Simplified output - cleaner, focused view
|
|
180
|
-
printCompactOutput(sorted, scanInput);
|
|
219
|
+
printCompactOutput(scanState.sorted, scanInput);
|
|
181
220
|
}
|
|
182
221
|
const failLevel = normalizeSeverity(options.failOn);
|
|
183
|
-
const shouldFail = sorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
222
|
+
const shouldFail = scanState.sorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
184
223
|
process.exit(shouldFail ? 1 : 0);
|
|
185
224
|
return;
|
|
186
225
|
}
|
|
@@ -197,6 +236,183 @@ function formatAdvisorySourceLine(sourceLabel) {
|
|
|
197
236
|
}
|
|
198
237
|
return `${match[1]} (${chalk.cyan(match[2])})`;
|
|
199
238
|
}
|
|
239
|
+
async function scanProject(params) {
|
|
240
|
+
const directDependencyNames = readDirectDependencyNames(params.projectPath, !!params.options.prodOnly);
|
|
241
|
+
const findings = await scanPackages(params.scanInput.packages, params.batchSize, params.options, { directDependencyNames });
|
|
242
|
+
const sorted = findings.sort((a, b) => severityOrder[b.severity] - severityOrder[a.severity]);
|
|
243
|
+
const coverage = buildCoverageNotes(params.scanInput, !!params.options.offline || !!params.options.offlineDb);
|
|
244
|
+
const minSeverity = normalizeSeverity(params.options.minSeverity || "medium");
|
|
245
|
+
const tableFindings = params.options.all
|
|
246
|
+
? sorted
|
|
247
|
+
: sorted.filter(f => severityOrder[f.severity] >= severityOrder[minSeverity]);
|
|
248
|
+
const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, params.scanInput);
|
|
249
|
+
return {
|
|
250
|
+
sorted,
|
|
251
|
+
coverage,
|
|
252
|
+
minSeverity,
|
|
253
|
+
tableFindings,
|
|
254
|
+
suggestedFixCommands,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
async function applyFixesIfRequested(params) {
|
|
258
|
+
console.log("");
|
|
259
|
+
console.log(chalk.bold.cyan("Applying fixes (--fix)"));
|
|
260
|
+
if (!params.plan) {
|
|
261
|
+
return {
|
|
262
|
+
appliedFixCount: 0,
|
|
263
|
+
skippedCount: params.totalFindings,
|
|
264
|
+
skippedTransitiveCount: 0,
|
|
265
|
+
skippedNoValidatedTargetCount: params.totalFindings,
|
|
266
|
+
applied: [],
|
|
267
|
+
note: "No package-manager-native fix command is available for this project.",
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
const directTargets = params.plan.targets.filter(target => target.kind === "direct");
|
|
271
|
+
const transitiveTargets = params.plan.targets.filter(target => target.kind !== "direct");
|
|
272
|
+
const skippedDirect = params.plan.skipped.filter(skip => skip.relationship === "direct" || skip.relationship === "unknown");
|
|
273
|
+
if (directTargets.length === 0) {
|
|
274
|
+
const skippedCount = transitiveTargets.length + skippedDirect.length;
|
|
275
|
+
return {
|
|
276
|
+
appliedFixCount: 0,
|
|
277
|
+
skippedCount,
|
|
278
|
+
skippedTransitiveCount: transitiveTargets.length,
|
|
279
|
+
skippedNoValidatedTargetCount: skippedDirect.length,
|
|
280
|
+
applied: [],
|
|
281
|
+
note: "No validated direct dependency fixes were eligible for auto-apply.",
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
const commandLabel = commandLabelForPackageManager(params.plan.packageManager);
|
|
285
|
+
const total = directTargets.length;
|
|
286
|
+
const spinner = createSpinner(`Applying direct package fixes with ${commandLabel}... 0/${total}`, params.options);
|
|
287
|
+
for (let i = 0; i < directTargets.length; i++) {
|
|
288
|
+
const target = directTargets[i];
|
|
289
|
+
const commandParts = buildFixCommandParts(params.plan.packageManager, [target]);
|
|
290
|
+
spinner.update(`Applying direct fix ${i + 1}/${total}: ${commandParts.join(" ")}`);
|
|
291
|
+
const run = await runInstallCommand(commandParts[0], commandParts.slice(1), params.projectPath);
|
|
292
|
+
if (run.error) {
|
|
293
|
+
spinner.fail("Failed to apply fixes");
|
|
294
|
+
throw new Error(`Failed to apply fixes: ${run.error.message}`);
|
|
295
|
+
}
|
|
296
|
+
if ((run.status ?? 1) !== 0) {
|
|
297
|
+
spinner.fail(`Fix command failed (${commandLabel})`);
|
|
298
|
+
throw new Error(`Fix command exited with status ${run.status ?? 1}`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
spinner.succeed(`Applied ${directTargets.length} direct package fix${directTargets.length === 1 ? "" : "es"} with ${commandLabel}`);
|
|
302
|
+
const skippedCount = transitiveTargets.length + skippedDirect.length;
|
|
303
|
+
return {
|
|
304
|
+
appliedFixCount: directTargets.length,
|
|
305
|
+
skippedCount,
|
|
306
|
+
skippedTransitiveCount: transitiveTargets.length,
|
|
307
|
+
skippedNoValidatedTargetCount: skippedDirect.length,
|
|
308
|
+
applied: directTargets.map(target => ({
|
|
309
|
+
package: target.package,
|
|
310
|
+
from: target.currentVersion ?? "unknown",
|
|
311
|
+
to: target.targetVersion,
|
|
312
|
+
})),
|
|
313
|
+
note: null,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function buildFixCommandParts(packageManager, targets) {
|
|
317
|
+
if (packageManager === "npm") {
|
|
318
|
+
return ["npm", "install", ...targets.map(target => `${target.package}@${target.targetVersion}`)];
|
|
319
|
+
}
|
|
320
|
+
if (packageManager === "pnpm") {
|
|
321
|
+
return ["pnpm", "add", ...targets.map(target => `${target.package}@${target.targetVersion}`)];
|
|
322
|
+
}
|
|
323
|
+
return ["yarn", "add", ...targets.map(target => `${target.package}@${target.targetVersion}`)];
|
|
324
|
+
}
|
|
325
|
+
async function runInstallCommand(command, args, cwd) {
|
|
326
|
+
return await new Promise(resolve => {
|
|
327
|
+
const child = spawn(command, args, {
|
|
328
|
+
cwd,
|
|
329
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
330
|
+
});
|
|
331
|
+
child.stdout.on("data", () => { });
|
|
332
|
+
child.stderr.on("data", () => { });
|
|
333
|
+
child.on("error", error => {
|
|
334
|
+
resolve({ status: null, error });
|
|
335
|
+
});
|
|
336
|
+
child.on("close", code => {
|
|
337
|
+
resolve({ status: code, error: null });
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
function commandLabelForPackageManager(packageManager) {
|
|
342
|
+
if (packageManager === "npm")
|
|
343
|
+
return "npm install";
|
|
344
|
+
if (packageManager === "pnpm")
|
|
345
|
+
return "pnpm add";
|
|
346
|
+
return "yarn add";
|
|
347
|
+
}
|
|
348
|
+
function countBySeverity(findings) {
|
|
349
|
+
const counts = {
|
|
350
|
+
none: 0,
|
|
351
|
+
low: 0,
|
|
352
|
+
medium: 0,
|
|
353
|
+
high: 0,
|
|
354
|
+
critical: 0,
|
|
355
|
+
unknown: 0,
|
|
356
|
+
};
|
|
357
|
+
for (const finding of findings) {
|
|
358
|
+
counts[finding.severity] += 1;
|
|
359
|
+
}
|
|
360
|
+
return counts;
|
|
361
|
+
}
|
|
362
|
+
function printFixModeSummary(params) {
|
|
363
|
+
const result = params.fixResult;
|
|
364
|
+
if (!result)
|
|
365
|
+
return;
|
|
366
|
+
if (result.note) {
|
|
367
|
+
console.log(chalk.gray(result.note));
|
|
368
|
+
}
|
|
369
|
+
if (result.applied.length > 0) {
|
|
370
|
+
console.log("");
|
|
371
|
+
console.log(chalk.bold.cyan("Applied fixes"));
|
|
372
|
+
for (const item of result.applied) {
|
|
373
|
+
console.log(`- ${chalk.white(item.package)}: ${chalk.gray(item.from)} ${chalk.cyan("->")} ${chalk.green(item.to)}`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
console.log("");
|
|
377
|
+
console.log(chalk.bold.cyan("Fix summary"));
|
|
378
|
+
console.log(`- Applied fixes: ${chalk.green(String(result.appliedFixCount))}`);
|
|
379
|
+
console.log(`- Skipped findings: ${chalk.yellow(String(result.skippedCount))}`);
|
|
380
|
+
if (result.skippedCount > 0) {
|
|
381
|
+
console.log(` - Transitive (v1 skip): ${chalk.yellow(String(result.skippedTransitiveCount))}`);
|
|
382
|
+
console.log(` - No validated direct target: ${chalk.yellow(String(result.skippedNoValidatedTargetCount))}`);
|
|
383
|
+
}
|
|
384
|
+
console.log(`- Findings before fix: ${chalk.white(String(params.findingsBeforeFix))}`);
|
|
385
|
+
console.log(`- Remaining findings after fix: ${chalk.white(String(params.findingsAfterFix))}`);
|
|
386
|
+
console.log(`- Remaining severity mix: critical ${chalk.redBright(String(params.remainingBySeverity.critical))}, high ${chalk.red(String(params.remainingBySeverity.high))}, medium ${chalk.yellow(String(params.remainingBySeverity.medium))}, low ${chalk.blueBright(String(params.remainingBySeverity.low))}, unknown ${chalk.magenta(String(params.remainingBySeverity.unknown))}`);
|
|
387
|
+
}
|
|
388
|
+
function readDirectDependencyNames(projectPath, prodOnly) {
|
|
389
|
+
const packageJsonPath = path.join(projectPath, "package.json");
|
|
390
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
try {
|
|
394
|
+
const raw = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
395
|
+
const directNames = new Set();
|
|
396
|
+
const sections = [
|
|
397
|
+
raw?.dependencies,
|
|
398
|
+
raw?.optionalDependencies,
|
|
399
|
+
];
|
|
400
|
+
if (!prodOnly) {
|
|
401
|
+
sections.push(raw?.devDependencies);
|
|
402
|
+
}
|
|
403
|
+
for (const section of sections) {
|
|
404
|
+
if (!section || typeof section !== "object")
|
|
405
|
+
continue;
|
|
406
|
+
for (const name of Object.keys(section)) {
|
|
407
|
+
directNames.add(name);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return directNames;
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
200
416
|
function formatAdvisoryDbFreshness(lastSyncAt) {
|
|
201
417
|
if (!lastSyncAt) {
|
|
202
418
|
return chalk.yellow("unknown");
|
package/dist/output/printers.js
CHANGED
|
@@ -122,6 +122,7 @@ export function printSuggestedFixCommands(findings, scanInput) {
|
|
|
122
122
|
if (plan.sections.length === 0)
|
|
123
123
|
return;
|
|
124
124
|
const sharedDirectTableWidths = computeSharedDirectTableWidths(plan.sections);
|
|
125
|
+
const sharedParentUpgradeTableWidths = computeSharedParentUpgradeTableWidths(plan.sections);
|
|
125
126
|
console.log("");
|
|
126
127
|
console.log(chalk.bold.yellow("π Copy And Run These Fix Commands"));
|
|
127
128
|
console.log(`${chalk.gray("Detected package manager:")} ${chalk.cyan(plan.packageManager)} ${chalk.gray(`(${plan.sourceLabel})`)}`);
|
|
@@ -137,6 +138,9 @@ export function printSuggestedFixCommands(findings, scanInput) {
|
|
|
137
138
|
console.log(chalk.gray(` Note: ${note}`));
|
|
138
139
|
}
|
|
139
140
|
}
|
|
141
|
+
else if (shouldRenderParentUpgradeTable(section.targets)) {
|
|
142
|
+
printParentUpgradeTargetsTable(section.targets, sharedParentUpgradeTableWidths);
|
|
143
|
+
}
|
|
140
144
|
console.log(renderCommandCallout(section.command));
|
|
141
145
|
}
|
|
142
146
|
}
|
|
@@ -533,6 +537,26 @@ function printDirectTargetsTable(targets, remainingNotes, validationSummary, wid
|
|
|
533
537
|
}
|
|
534
538
|
console.log(line("β", "β΄", "β"));
|
|
535
539
|
}
|
|
540
|
+
function printParentUpgradeTargetsTable(targets, widthsOverride) {
|
|
541
|
+
const headers = ["Package", "Current", "Recommended target", "Context"];
|
|
542
|
+
const rows = targets.map(target => [
|
|
543
|
+
target.package,
|
|
544
|
+
target.currentVersion ?? "-",
|
|
545
|
+
chalk.cyan(target.targetVersion),
|
|
546
|
+
chalk.gray(target.reason),
|
|
547
|
+
]);
|
|
548
|
+
if (rows.length === 0)
|
|
549
|
+
return;
|
|
550
|
+
const widths = widthsOverride ?? computeTableWidths(headers, rows);
|
|
551
|
+
const line = (left, mid, right) => left + widths.map(w => "β".repeat(w + 2)).join(mid) + right;
|
|
552
|
+
console.log(line("β", "β¬", "β"));
|
|
553
|
+
console.log(renderRow(headers, widths));
|
|
554
|
+
console.log(line("β", "βΌ", "β€"));
|
|
555
|
+
for (const row of rows) {
|
|
556
|
+
console.log(renderRow(row.map(value => String(value)), widths));
|
|
557
|
+
}
|
|
558
|
+
console.log(line("β", "β΄", "β"));
|
|
559
|
+
}
|
|
536
560
|
function computeTableWidths(headers, rows) {
|
|
537
561
|
return headers.map((header, index) => Math.min(40, Math.max(header.length, ...rows.map(row => stripAnsi(String(row[index])).length))));
|
|
538
562
|
}
|
|
@@ -557,3 +581,24 @@ function computeSharedDirectTableWidths(sections) {
|
|
|
557
581
|
}
|
|
558
582
|
return computeTableWidths(headers, rows);
|
|
559
583
|
}
|
|
584
|
+
function shouldRenderParentUpgradeTable(targets) {
|
|
585
|
+
return targets.length > 0 && targets.every(target => target.kind === "parent-upgrade");
|
|
586
|
+
}
|
|
587
|
+
function computeSharedParentUpgradeTableWidths(sections) {
|
|
588
|
+
const parentSections = sections.filter(section => shouldRenderParentUpgradeTable(section.targets));
|
|
589
|
+
if (parentSections.length === 0)
|
|
590
|
+
return undefined;
|
|
591
|
+
const headers = ["Package", "Current", "Recommended target", "Context"];
|
|
592
|
+
const rows = [];
|
|
593
|
+
for (const section of parentSections) {
|
|
594
|
+
for (const target of section.targets) {
|
|
595
|
+
rows.push([
|
|
596
|
+
target.package,
|
|
597
|
+
target.currentVersion ?? "-",
|
|
598
|
+
target.targetVersion,
|
|
599
|
+
target.reason,
|
|
600
|
+
]);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return computeTableWidths(headers, rows);
|
|
604
|
+
}
|
|
@@ -94,6 +94,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
94
94
|
isUpgradeTarget(finding.recommendedParentUpgrade.currentVersion, finding.recommendedParentUpgrade.targetVersion)) {
|
|
95
95
|
upsertTarget(targetsByPackage, {
|
|
96
96
|
package: finding.recommendedParentUpgrade.package,
|
|
97
|
+
currentVersion: finding.recommendedParentUpgrade.currentVersion,
|
|
97
98
|
targetVersion: finding.recommendedParentUpgrade.targetVersion,
|
|
98
99
|
scannedVersions: null,
|
|
99
100
|
knownVulnerableVersions: null,
|
|
@@ -196,6 +197,7 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
196
197
|
if (looksLikeVersion(existing.targetVersion) && looksLikeVersion(next.targetVersion)) {
|
|
197
198
|
if (compareVersions(next.targetVersion, existing.targetVersion) > 0) {
|
|
198
199
|
merged.targetVersion = next.targetVersion;
|
|
200
|
+
merged.currentVersion = next.currentVersion ?? merged.currentVersion;
|
|
199
201
|
merged.reason = next.reason;
|
|
200
202
|
merged.scannedVersions = next.scannedVersions ?? merged.scannedVersions ?? null;
|
|
201
203
|
merged.knownVulnerableVersions = next.knownVulnerableVersions ?? merged.knownVulnerableVersions ?? null;
|
|
@@ -204,6 +206,7 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
204
206
|
return;
|
|
205
207
|
}
|
|
206
208
|
if (next.kind === "direct" && existing.kind !== "direct") {
|
|
209
|
+
merged.currentVersion = next.currentVersion ?? merged.currentVersion;
|
|
207
210
|
merged.targetVersion = next.targetVersion;
|
|
208
211
|
merged.reason = next.reason;
|
|
209
212
|
merged.adjustmentNote = next.adjustmentNote ?? merged.adjustmentNote;
|
package/dist/scanner.js
CHANGED
|
@@ -37,7 +37,7 @@ export function createAdvisorySource(options) {
|
|
|
37
37
|
function getPackageCacheKey(pkg) {
|
|
38
38
|
return `${pkg.ecosystem}:${pkg.name}@${pkg.version}`;
|
|
39
39
|
}
|
|
40
|
-
export async function scanPackages(packages, batchSize, options) {
|
|
40
|
+
export async function scanPackages(packages, batchSize, options, context) {
|
|
41
41
|
const sourceContext = createAdvisorySource({
|
|
42
42
|
osvUrl: options.osvUrl,
|
|
43
43
|
offline: options.offline,
|
|
@@ -165,7 +165,7 @@ export async function scanPackages(packages, batchSize, options) {
|
|
|
165
165
|
const severity = maxSeverity(vulnerabilities);
|
|
166
166
|
const cveAliases = unique(vulnerabilities.flatMap(v => (v.aliases ?? []).filter(a => a.startsWith("CVE-"))));
|
|
167
167
|
const dependencyPaths = result.pkg.paths ?? [];
|
|
168
|
-
const relationship = classifyRelationship(dependencyPaths);
|
|
168
|
+
const relationship = classifyRelationship(dependencyPaths, result.pkg.name, context?.directDependencyNames);
|
|
169
169
|
const firstFixedVersion = findFirstFixedVersion(vulnerabilities);
|
|
170
170
|
return {
|
|
171
171
|
pkg: result.pkg,
|
|
@@ -252,9 +252,13 @@ function isAdvisoryDbStale(metadata) {
|
|
|
252
252
|
}
|
|
253
253
|
return Date.now() - timestamp > ADVISORY_DB_STALE_AFTER_MS;
|
|
254
254
|
}
|
|
255
|
-
function classifyRelationship(paths) {
|
|
255
|
+
function classifyRelationship(paths, packageName, directDependencyNames) {
|
|
256
|
+
if (packageName && directDependencyNames?.has(packageName))
|
|
257
|
+
return "direct";
|
|
256
258
|
if (paths.length === 0)
|
|
257
259
|
return "unknown";
|
|
260
|
+
if (directDependencyNames)
|
|
261
|
+
return "transitive";
|
|
258
262
|
const shortest = Math.min(...paths.map(p => p.length));
|
|
259
263
|
if (shortest <= 2)
|
|
260
264
|
return "direct";
|