cve-lite-cli 1.5.1 → 1.5.3
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 +151 -798
- package/dist/cli/args.js +4 -0
- package/dist/cli/help.js +1 -0
- package/dist/index.js +224 -31
- package/dist/osv/severity.js +6 -0
- package/dist/utils/network.js +33 -0
- package/package.json +1 -1
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,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import process from "node:process";
|
|
@@ -13,6 +14,7 @@ import { chalk } from "./utils/chalk.js";
|
|
|
13
14
|
import { createSpinner } from "./output/spinner.js";
|
|
14
15
|
import { buildSuggestedFixCommandPlan } from "./remediation/fix-commands.js";
|
|
15
16
|
import { getCliVersion } from "./utils/version-info.js";
|
|
17
|
+
import { isLikelyBlockedAdvisoryRequestError } from "./utils/network.js";
|
|
16
18
|
import { logInfo, logWarn, printCacheSummary, serializeFinding } from "./output/formatters.js";
|
|
17
19
|
import { printSummary, printActionSummary, printPriorityFixes, printFixPlan, printSuggestedFixCommands, printSuggestedFixCommandSkips, printCoverage, printSkippedDependencies, printGroupSummary, printTable, printPathHints, printFinalStatus, printCompactOutput } from "./output/printers.js";
|
|
18
20
|
let parsedArgs = null;
|
|
@@ -81,6 +83,9 @@ if (parsedArgs) {
|
|
|
81
83
|
throw new Error(`Invalid value for --osv-url: ${options.osvUrl}`);
|
|
82
84
|
}
|
|
83
85
|
}
|
|
86
|
+
if (options.fix && options.json) {
|
|
87
|
+
throw new Error("--fix cannot be used with --json");
|
|
88
|
+
}
|
|
84
89
|
let advisorySourceLine;
|
|
85
90
|
let advisoryDbFreshnessLine = null;
|
|
86
91
|
let advisoryDbWarning = null;
|
|
@@ -118,8 +123,8 @@ if (parsedArgs) {
|
|
|
118
123
|
if (advisoryDbWarning) {
|
|
119
124
|
logWarn(advisoryDbWarning, options);
|
|
120
125
|
}
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
let scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
127
|
+
let packages = scanInput.packages;
|
|
123
128
|
logInfo(`Parsed ${packages.length} package${packages.length === 1 ? "" : "s"} from ${scanInput.source}${scanInput.filePath ? ` (${path.relative(projectPath, scanInput.filePath) || path.basename(scanInput.filePath)})` : ""}`, options);
|
|
124
129
|
printCacheSummary(options.cacheDir, options);
|
|
125
130
|
if (scanInput.warnings.length > 0) {
|
|
@@ -132,62 +137,101 @@ if (parsedArgs) {
|
|
|
132
137
|
process.exit(0);
|
|
133
138
|
return;
|
|
134
139
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
140
|
+
let scanState = await scanProject({
|
|
141
|
+
scanInput,
|
|
142
|
+
batchSize,
|
|
143
|
+
options,
|
|
144
|
+
projectPath,
|
|
145
|
+
});
|
|
146
|
+
const findingsBeforeFix = scanState.sorted.length;
|
|
147
|
+
let fixResult = null;
|
|
148
|
+
if (options.fix) {
|
|
149
|
+
fixResult = await applyFixesIfRequested({
|
|
150
|
+
plan: scanState.suggestedFixCommands,
|
|
151
|
+
projectPath,
|
|
152
|
+
totalFindings: scanState.sorted.length,
|
|
153
|
+
options,
|
|
154
|
+
});
|
|
155
|
+
if (fixResult.appliedFixCount > 0) {
|
|
156
|
+
console.log(`${chalk.cyan("⠋")} ${chalk.gray("Rescanning project...")}`);
|
|
157
|
+
scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
158
|
+
packages = scanInput.packages;
|
|
159
|
+
if (packages.length === 0) {
|
|
160
|
+
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
161
|
+
process.exit(0);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
scanState = await scanProject({
|
|
165
|
+
scanInput,
|
|
166
|
+
batchSize,
|
|
167
|
+
options,
|
|
168
|
+
projectPath,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (options.fix) {
|
|
173
|
+
printFixModeSummary({
|
|
174
|
+
fixResult,
|
|
175
|
+
findingsBeforeFix,
|
|
176
|
+
findingsAfterFix: scanState.sorted.length,
|
|
177
|
+
remainingBySeverity: countBySeverity(scanState.sorted),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
else if (options.json) {
|
|
143
181
|
console.log(JSON.stringify({
|
|
144
182
|
projectPath,
|
|
145
183
|
mode: scanInput.mode,
|
|
146
184
|
source: scanInput.source,
|
|
147
185
|
packageCount: packages.length,
|
|
148
|
-
findingCount: sorted.length,
|
|
149
|
-
suggestedFixCommands,
|
|
150
|
-
notes: [...scanInput.notes, ...coverage],
|
|
186
|
+
findingCount: scanState.sorted.length,
|
|
187
|
+
suggestedFixCommands: scanState.suggestedFixCommands,
|
|
188
|
+
notes: [...scanInput.notes, ...scanState.coverage],
|
|
151
189
|
warnings: scanInput.warnings,
|
|
152
190
|
skippedDependencies: scanInput.skippedDependencies,
|
|
153
|
-
findings: sorted.map(serializeFinding)
|
|
191
|
+
findings: scanState.sorted.map(serializeFinding)
|
|
154
192
|
}, null, 2));
|
|
155
193
|
}
|
|
156
194
|
else if (options.verbose) {
|
|
157
195
|
// Verbose output - show all details
|
|
158
|
-
printSummary(sorted, packages.length, scanInput);
|
|
159
|
-
printActionSummary(sorted);
|
|
160
|
-
printSuggestedFixCommands(sorted, scanInput);
|
|
161
|
-
printPriorityFixes(sorted);
|
|
162
|
-
printFixPlan(sorted);
|
|
163
|
-
printSuggestedFixCommandSkips(sorted, scanInput);
|
|
164
|
-
printCoverage([...scanInput.notes, ...coverage]);
|
|
196
|
+
printSummary(scanState.sorted, packages.length, scanInput);
|
|
197
|
+
printActionSummary(scanState.sorted);
|
|
198
|
+
printSuggestedFixCommands(scanState.sorted, scanInput);
|
|
199
|
+
printPriorityFixes(scanState.sorted);
|
|
200
|
+
printFixPlan(scanState.sorted);
|
|
201
|
+
printSuggestedFixCommandSkips(scanState.sorted, scanInput);
|
|
202
|
+
printCoverage([...scanInput.notes, ...scanState.coverage]);
|
|
165
203
|
if (scanInput.skippedDependencies.length > 0) {
|
|
166
204
|
printSkippedDependencies(scanInput.skippedDependencies);
|
|
167
205
|
}
|
|
168
|
-
if (sorted.length > 0) {
|
|
169
|
-
printGroupSummary(sorted);
|
|
170
|
-
if (tableFindings.length > 0) {
|
|
171
|
-
printTable(tableFindings, options.all ? null : minSeverity);
|
|
172
|
-
printPathHints(tableFindings);
|
|
206
|
+
if (scanState.sorted.length > 0) {
|
|
207
|
+
printGroupSummary(scanState.sorted);
|
|
208
|
+
if (scanState.tableFindings.length > 0) {
|
|
209
|
+
printTable(scanState.tableFindings, options.all ? null : scanState.minSeverity);
|
|
210
|
+
printPathHints(scanState.tableFindings);
|
|
173
211
|
}
|
|
174
212
|
else {
|
|
175
|
-
logInfo(`No findings met the table threshold of ${minSeverity}. Re-run with --all to show everything.`, options);
|
|
213
|
+
logInfo(`No findings met the table threshold of ${scanState.minSeverity}. Re-run with --all to show everything.`, options);
|
|
176
214
|
}
|
|
177
215
|
}
|
|
178
|
-
printFinalStatus(sorted);
|
|
216
|
+
printFinalStatus(scanState.sorted);
|
|
179
217
|
}
|
|
180
218
|
else {
|
|
181
219
|
// Simplified output - cleaner, focused view
|
|
182
|
-
printCompactOutput(sorted, scanInput);
|
|
220
|
+
printCompactOutput(scanState.sorted, scanInput);
|
|
183
221
|
}
|
|
184
222
|
const failLevel = normalizeSeverity(options.failOn);
|
|
185
|
-
const shouldFail = sorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
223
|
+
const shouldFail = scanState.sorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
186
224
|
process.exit(shouldFail ? 1 : 0);
|
|
187
225
|
return;
|
|
188
226
|
}
|
|
189
227
|
main().catch((error) => {
|
|
190
|
-
|
|
228
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
229
|
+
console.error(chalk.red(`Error: ${errorMessage}`));
|
|
230
|
+
if (isLikelyBlockedAdvisoryRequestError(errorMessage)) {
|
|
231
|
+
console.error(chalk.yellow("Hint: Outbound access to the OSV API may be blocked or restricted in this environment."));
|
|
232
|
+
console.error(chalk.gray("If that is expected, build the advisory DB on a machine with OSV access, then scan here with `--offline` or `--offline-db /path/to/advisories.db`."));
|
|
233
|
+
console.error(chalk.gray("Command to build the DB on a network-allowed machine: `cve-lite advisories sync --output /path/to/advisories.db`"));
|
|
234
|
+
}
|
|
191
235
|
process.exit(1);
|
|
192
236
|
});
|
|
193
237
|
}
|
|
@@ -199,6 +243,155 @@ function formatAdvisorySourceLine(sourceLabel) {
|
|
|
199
243
|
}
|
|
200
244
|
return `${match[1]} (${chalk.cyan(match[2])})`;
|
|
201
245
|
}
|
|
246
|
+
async function scanProject(params) {
|
|
247
|
+
const directDependencyNames = readDirectDependencyNames(params.projectPath, !!params.options.prodOnly);
|
|
248
|
+
const findings = await scanPackages(params.scanInput.packages, params.batchSize, params.options, { directDependencyNames });
|
|
249
|
+
const sorted = findings.sort((a, b) => severityOrder[b.severity] - severityOrder[a.severity]);
|
|
250
|
+
const coverage = buildCoverageNotes(params.scanInput, !!params.options.offline || !!params.options.offlineDb);
|
|
251
|
+
const minSeverity = normalizeSeverity(params.options.minSeverity || "medium");
|
|
252
|
+
const tableFindings = params.options.all
|
|
253
|
+
? sorted
|
|
254
|
+
: sorted.filter(f => severityOrder[f.severity] >= severityOrder[minSeverity]);
|
|
255
|
+
const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, params.scanInput);
|
|
256
|
+
return {
|
|
257
|
+
sorted,
|
|
258
|
+
coverage,
|
|
259
|
+
minSeverity,
|
|
260
|
+
tableFindings,
|
|
261
|
+
suggestedFixCommands,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
async function applyFixesIfRequested(params) {
|
|
265
|
+
console.log("");
|
|
266
|
+
console.log(chalk.bold.cyan("Applying fixes (--fix)"));
|
|
267
|
+
if (!params.plan) {
|
|
268
|
+
return {
|
|
269
|
+
appliedFixCount: 0,
|
|
270
|
+
skippedCount: params.totalFindings,
|
|
271
|
+
skippedTransitiveCount: 0,
|
|
272
|
+
skippedNoValidatedTargetCount: params.totalFindings,
|
|
273
|
+
applied: [],
|
|
274
|
+
note: "No package-manager-native fix command is available for this project.",
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
const directTargets = params.plan.targets.filter(target => target.kind === "direct");
|
|
278
|
+
const transitiveTargets = params.plan.targets.filter(target => target.kind !== "direct");
|
|
279
|
+
const skippedDirect = params.plan.skipped.filter(skip => skip.relationship === "direct" || skip.relationship === "unknown");
|
|
280
|
+
if (directTargets.length === 0) {
|
|
281
|
+
const skippedCount = transitiveTargets.length + skippedDirect.length;
|
|
282
|
+
return {
|
|
283
|
+
appliedFixCount: 0,
|
|
284
|
+
skippedCount,
|
|
285
|
+
skippedTransitiveCount: transitiveTargets.length,
|
|
286
|
+
skippedNoValidatedTargetCount: skippedDirect.length,
|
|
287
|
+
applied: [],
|
|
288
|
+
note: "No validated direct dependency fixes were eligible for auto-apply.",
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const commandLabel = commandLabelForPackageManager(params.plan.packageManager);
|
|
292
|
+
const total = directTargets.length;
|
|
293
|
+
const spinner = createSpinner(`Applying direct package fixes with ${commandLabel}... 0/${total}`, params.options);
|
|
294
|
+
for (let i = 0; i < directTargets.length; i++) {
|
|
295
|
+
const target = directTargets[i];
|
|
296
|
+
const commandParts = buildFixCommandParts(params.plan.packageManager, [target]);
|
|
297
|
+
spinner.update(`Applying direct fix ${i + 1}/${total}: ${commandParts.join(" ")}`);
|
|
298
|
+
const run = await runInstallCommand(commandParts[0], commandParts.slice(1), params.projectPath);
|
|
299
|
+
if (run.error) {
|
|
300
|
+
spinner.fail("Failed to apply fixes");
|
|
301
|
+
throw new Error(`Failed to apply fixes: ${run.error.message}`);
|
|
302
|
+
}
|
|
303
|
+
if ((run.status ?? 1) !== 0) {
|
|
304
|
+
spinner.fail(`Fix command failed (${commandLabel})`);
|
|
305
|
+
throw new Error(`Fix command exited with status ${run.status ?? 1}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
spinner.succeed(`Applied ${directTargets.length} direct package fix${directTargets.length === 1 ? "" : "es"} with ${commandLabel}`);
|
|
309
|
+
const skippedCount = transitiveTargets.length + skippedDirect.length;
|
|
310
|
+
return {
|
|
311
|
+
appliedFixCount: directTargets.length,
|
|
312
|
+
skippedCount,
|
|
313
|
+
skippedTransitiveCount: transitiveTargets.length,
|
|
314
|
+
skippedNoValidatedTargetCount: skippedDirect.length,
|
|
315
|
+
applied: directTargets.map(target => ({
|
|
316
|
+
package: target.package,
|
|
317
|
+
from: target.currentVersion ?? "unknown",
|
|
318
|
+
to: target.targetVersion,
|
|
319
|
+
})),
|
|
320
|
+
note: null,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function buildFixCommandParts(packageManager, targets) {
|
|
324
|
+
if (packageManager === "npm") {
|
|
325
|
+
return ["npm", "install", ...targets.map(target => `${target.package}@${target.targetVersion}`)];
|
|
326
|
+
}
|
|
327
|
+
if (packageManager === "pnpm") {
|
|
328
|
+
return ["pnpm", "add", ...targets.map(target => `${target.package}@${target.targetVersion}`)];
|
|
329
|
+
}
|
|
330
|
+
return ["yarn", "add", ...targets.map(target => `${target.package}@${target.targetVersion}`)];
|
|
331
|
+
}
|
|
332
|
+
async function runInstallCommand(command, args, cwd) {
|
|
333
|
+
return await new Promise(resolve => {
|
|
334
|
+
const child = spawn(command, args, {
|
|
335
|
+
cwd,
|
|
336
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
337
|
+
});
|
|
338
|
+
child.stdout.on("data", () => { });
|
|
339
|
+
child.stderr.on("data", () => { });
|
|
340
|
+
child.on("error", error => {
|
|
341
|
+
resolve({ status: null, error });
|
|
342
|
+
});
|
|
343
|
+
child.on("close", code => {
|
|
344
|
+
resolve({ status: code, error: null });
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
function commandLabelForPackageManager(packageManager) {
|
|
349
|
+
if (packageManager === "npm")
|
|
350
|
+
return "npm install";
|
|
351
|
+
if (packageManager === "pnpm")
|
|
352
|
+
return "pnpm add";
|
|
353
|
+
return "yarn add";
|
|
354
|
+
}
|
|
355
|
+
function countBySeverity(findings) {
|
|
356
|
+
const counts = {
|
|
357
|
+
none: 0,
|
|
358
|
+
low: 0,
|
|
359
|
+
medium: 0,
|
|
360
|
+
high: 0,
|
|
361
|
+
critical: 0,
|
|
362
|
+
unknown: 0,
|
|
363
|
+
};
|
|
364
|
+
for (const finding of findings) {
|
|
365
|
+
counts[finding.severity] += 1;
|
|
366
|
+
}
|
|
367
|
+
return counts;
|
|
368
|
+
}
|
|
369
|
+
function printFixModeSummary(params) {
|
|
370
|
+
const result = params.fixResult;
|
|
371
|
+
if (!result)
|
|
372
|
+
return;
|
|
373
|
+
if (result.note) {
|
|
374
|
+
console.log(chalk.gray(result.note));
|
|
375
|
+
}
|
|
376
|
+
if (result.applied.length > 0) {
|
|
377
|
+
console.log("");
|
|
378
|
+
console.log(chalk.bold.cyan("Applied fixes"));
|
|
379
|
+
for (const item of result.applied) {
|
|
380
|
+
console.log(`- ${chalk.white(item.package)}: ${chalk.gray(item.from)} ${chalk.cyan("->")} ${chalk.green(item.to)}`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
console.log("");
|
|
384
|
+
console.log(chalk.bold.cyan("Fix summary"));
|
|
385
|
+
console.log(`- Applied fixes: ${chalk.green(String(result.appliedFixCount))}`);
|
|
386
|
+
console.log(`- Skipped findings: ${chalk.yellow(String(result.skippedCount))}`);
|
|
387
|
+
if (result.skippedCount > 0) {
|
|
388
|
+
console.log(` - Transitive (v1 skip): ${chalk.yellow(String(result.skippedTransitiveCount))}`);
|
|
389
|
+
console.log(` - No validated direct target: ${chalk.yellow(String(result.skippedNoValidatedTargetCount))}`);
|
|
390
|
+
}
|
|
391
|
+
console.log(`- Findings before fix: ${chalk.white(String(params.findingsBeforeFix))}`);
|
|
392
|
+
console.log(`- Remaining findings after fix: ${chalk.white(String(params.findingsAfterFix))}`);
|
|
393
|
+
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))}`);
|
|
394
|
+
}
|
|
202
395
|
function readDirectDependencyNames(projectPath, prodOnly) {
|
|
203
396
|
const packageJsonPath = path.join(projectPath, "package.json");
|
|
204
397
|
if (!fs.existsSync(packageJsonPath)) {
|
package/dist/osv/severity.js
CHANGED
|
@@ -25,6 +25,12 @@ export function inferSeverity(vuln) {
|
|
|
25
25
|
return "unknown";
|
|
26
26
|
}
|
|
27
27
|
function severityFromScore(score) {
|
|
28
|
+
// CVSS vector strings (e.g. "CVSS:3.1/AV:N/...") are not numerical scores.
|
|
29
|
+
// Extracting the first number would yield the CVSS version (3.1), not the base
|
|
30
|
+
// score — causing every CVSS_V3 advisory to be misclassified as "low".
|
|
31
|
+
// Return unknown so the caller falls through to database_specific.severity.
|
|
32
|
+
if (String(score).startsWith("CVSS:"))
|
|
33
|
+
return "unknown";
|
|
28
34
|
const match = String(score).match(/([0-9]+(?:\.[0-9]+)?)/);
|
|
29
35
|
if (!match)
|
|
30
36
|
return "unknown";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function isLikelyBlockedAdvisoryRequestError(message) {
|
|
2
|
+
if (!message.includes("OSV")) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const normalized = message.toLowerCase();
|
|
6
|
+
const finalCause = normalized.split(":").pop()?.trim() ?? normalized;
|
|
7
|
+
const blockedIndicators = [
|
|
8
|
+
"access denied",
|
|
9
|
+
"blocked",
|
|
10
|
+
"body timeout",
|
|
11
|
+
"connection refused",
|
|
12
|
+
"eai_again",
|
|
13
|
+
"econnrefused",
|
|
14
|
+
"econnreset",
|
|
15
|
+
"enotfound",
|
|
16
|
+
"etimedout",
|
|
17
|
+
"fetch failed",
|
|
18
|
+
"forbidden",
|
|
19
|
+
"gateway timeout",
|
|
20
|
+
"host unreachable",
|
|
21
|
+
"network unavailable",
|
|
22
|
+
"proxy",
|
|
23
|
+
"socket hang up",
|
|
24
|
+
"timed out",
|
|
25
|
+
"timeout",
|
|
26
|
+
"tunneling socket",
|
|
27
|
+
"unable to verify the first certificate",
|
|
28
|
+
];
|
|
29
|
+
if (blockedIndicators.some(indicator => finalCause.includes(indicator))) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return /^(401|403|407|408|429|451|502|503|504)\b/.test(finalCause);
|
|
33
|
+
}
|