cve-lite-cli 1.17.2 → 1.18.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 +2 -0
- package/dist/advisory/osv-advisory-source.js +3 -2
- package/dist/cli/args.js +6 -3
- package/dist/cli/help.js +2 -0
- package/dist/cli/validate.js +22 -0
- package/dist/constants.js +2 -0
- package/dist/index.js +26 -189
- package/dist/output/formatters.js +9 -2
- package/dist/output/html-reporter.js +7 -2
- package/dist/output/printers.js +8 -1
- package/dist/parsers/bun-lock.js +19 -0
- package/dist/parsers/package-lock.js +23 -0
- package/dist/parsers/pnpm-lock.js +20 -0
- package/dist/remediation/fix-commands.js +54 -12
- package/dist/remediation/npm-transitive-resolution.js +63 -0
- package/dist/scanner.js +52 -1
- package/dist/usage/scanner.js +3 -2
- package/dist/utils/network.js +81 -16
- package/dist/utils/package-json.js +124 -0
- package/dist/utils/severity.js +14 -0
- package/dist/utils/time.js +30 -0
- package/dist/utils/update-check.js +102 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -217,6 +217,8 @@ If you maintain an open-source JavaScript or TypeScript project and want CVE Lit
|
|
|
217
217
|
|
|
218
218
|
## Press
|
|
219
219
|
|
|
220
|
+
- **[As AI speeds coding, CVE Lite CLI keeps security deliberately AI-free](https://www.csoonline.com/article/4176701/as-ai-speeds-coding-cve-lite-cli-keeps-security-deliberately-ai-free.html)** — CSO Online (Shweta Sharma), May 2026
|
|
221
|
+
- **[AI Security Is Changing Fast — These 6 Open-Source Tools Prove It](https://medium.com/@techlatest.net/ai-security-is-changing-fast-these-6-open-source-tools-prove-it-5c5c9081cff7)** — Medium (TechLatest.Net), May 2026
|
|
220
222
|
- **[CVE Lite CLI: Open-source dependency vulnerability scanner](https://www.helpnetsecurity.com/2026/05/20/cve-lite-cli-open-source-dependency-vulnerability-scanner/)** — Help Net Security, May 2026
|
|
221
223
|
- **[Review of CVE Lite CLI](https://developmentcurated.com/testing-and-security/review-of-cve-lite-cli/)** — Development Curated (Sebastian Raiffen, IT Security Consultant), April 2026
|
|
222
224
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { extractErrorMessage } from "../utils/network.js";
|
|
1
2
|
export class OsvAdvisorySource {
|
|
2
3
|
baseUrl;
|
|
3
4
|
constructor(baseUrl = "https://api.osv.dev") {
|
|
@@ -31,7 +32,7 @@ export class OsvAdvisorySource {
|
|
|
31
32
|
}));
|
|
32
33
|
}
|
|
33
34
|
catch (error) {
|
|
34
|
-
const message =
|
|
35
|
+
const message = extractErrorMessage(error);
|
|
35
36
|
throw new Error(`OSV batch query failed for ${this.baseUrl}: ${message}`);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
@@ -44,7 +45,7 @@ export class OsvAdvisorySource {
|
|
|
44
45
|
return response.json();
|
|
45
46
|
}
|
|
46
47
|
catch (error) {
|
|
47
|
-
const message =
|
|
48
|
+
const message = extractErrorMessage(error);
|
|
48
49
|
throw new Error(`OSV vuln fetch failed for ${id} via ${this.baseUrl}: ${message}`);
|
|
49
50
|
}
|
|
50
51
|
}
|
package/dist/cli/args.js
CHANGED
|
@@ -24,8 +24,9 @@ export function parseArgs(argv) {
|
|
|
24
24
|
options.output = arg.slice("--output=".length);
|
|
25
25
|
continue;
|
|
26
26
|
}
|
|
27
|
-
if (arg.startsWith("-"))
|
|
27
|
+
if (arg.startsWith("-")) {
|
|
28
28
|
throw new Error(`Unknown option: ${arg}`);
|
|
29
|
+
}
|
|
29
30
|
throw new Error(`Unexpected argument: ${arg}`);
|
|
30
31
|
}
|
|
31
32
|
return { command: "advisories-sync", options };
|
|
@@ -37,8 +38,9 @@ export function parseArgs(argv) {
|
|
|
37
38
|
options.help = true;
|
|
38
39
|
continue;
|
|
39
40
|
}
|
|
40
|
-
if (arg.startsWith("-"))
|
|
41
|
+
if (arg.startsWith("-")) {
|
|
41
42
|
throw new Error(`Unknown option: ${arg}`);
|
|
43
|
+
}
|
|
42
44
|
throw new Error(`Unexpected argument: ${arg}`);
|
|
43
45
|
}
|
|
44
46
|
return { command: "install-skill", options };
|
|
@@ -182,8 +184,9 @@ export function parseArgs(argv) {
|
|
|
182
184
|
options.cdx = true;
|
|
183
185
|
continue;
|
|
184
186
|
}
|
|
185
|
-
if (arg.startsWith("-"))
|
|
187
|
+
if (arg.startsWith("-")) {
|
|
186
188
|
throw new Error(`Unknown option: ${arg}`);
|
|
189
|
+
}
|
|
187
190
|
if (!projectArg) {
|
|
188
191
|
projectArg = arg;
|
|
189
192
|
continue;
|
package/dist/cli/help.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { chalk } from "../utils/chalk.js";
|
|
2
2
|
import { getCliVersion } from "../utils/version-info.js";
|
|
3
|
+
import { checkForUpdate } from "../utils/update-check.js";
|
|
3
4
|
const CLI_VERSION = getCliVersion();
|
|
4
5
|
const CLI_BANNER = [
|
|
5
6
|
`${chalk.green(">_")} ${chalk.bold.whiteBright(`CVE Lite CLI (${CLI_VERSION})`)}`,
|
|
@@ -15,6 +16,7 @@ export function printBanner(options) {
|
|
|
15
16
|
return;
|
|
16
17
|
console.log(CLI_BANNER);
|
|
17
18
|
console.log("");
|
|
19
|
+
checkForUpdate(options);
|
|
18
20
|
}
|
|
19
21
|
export function printHelp() {
|
|
20
22
|
printBanner();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function validateOptions(options) {
|
|
2
|
+
if ((options.offline || options.offlineDb) && options.osvUrl) {
|
|
3
|
+
throw new Error("--offline/--offline-db cannot be used with --osv-url");
|
|
4
|
+
}
|
|
5
|
+
if (options.noCache && (options.offline || options.offlineDb)) {
|
|
6
|
+
throw new Error("--no-cache cannot be used with --offline or --offline-db");
|
|
7
|
+
}
|
|
8
|
+
if (options.osvUrl) {
|
|
9
|
+
try {
|
|
10
|
+
new URL(options.osvUrl);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
throw new Error(`Invalid value for --osv-url: ${options.osvUrl}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (options.fix && options.json) {
|
|
17
|
+
throw new Error("--fix cannot be used with --json");
|
|
18
|
+
}
|
|
19
|
+
if (options.report && options.json) {
|
|
20
|
+
throw new Error("--report cannot be used with --json");
|
|
21
|
+
}
|
|
22
|
+
}
|
package/dist/constants.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
|
-
import fs from "node:fs";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
import process from "node:process";
|
|
6
5
|
import { parseArgs } from "./cli/args.js";
|
|
7
6
|
import { printBanner, printHelp } from "./cli/help.js";
|
|
7
|
+
import { validateOptions } from "./cli/validate.js";
|
|
8
8
|
import { loadPackages, buildNoPackagesMessage } from "./parsers/index.js";
|
|
9
9
|
import { scanPackages, buildCoverageNotes, createAdvisorySource } from "./scanner.js";
|
|
10
10
|
import { syncOsvAdvisories } from "./advisory/osv-sync.js";
|
|
11
11
|
import { normalizeSeverity } from "./osv/severity.js";
|
|
12
|
-
import { severityOrder } from "./constants.js";
|
|
12
|
+
import { DEFAULT_BATCH_SIZE, DEFAULT_SEARCH_DEPTH, severityOrder } from "./constants.js";
|
|
13
13
|
import { chalk } from "./utils/chalk.js";
|
|
14
14
|
import { createSpinner } from "./output/spinner.js";
|
|
15
15
|
import { buildSuggestedFixCommandPlan } from "./remediation/fix-commands.js";
|
|
16
16
|
import { scanProjectForPackageUsage } from "./usage/scanner.js";
|
|
17
17
|
import { getCliVersion } from "./utils/version-info.js";
|
|
18
|
-
import { isLikelyBlockedAdvisoryRequestError, isSslCertificateError, sslCertificateErrorHint,
|
|
19
|
-
import {
|
|
18
|
+
import { blockedAdvisoryRequestHint, isLikelyBlockedAdvisoryRequestError, isRateLimitError, isServerError, isSslCertificateError, rateLimitAdvisoryRequestHint, serverAdvisoryRequestHint, sslCertificateErrorHint, } from "./utils/network.js";
|
|
19
|
+
import { formatAdvisoryDbFreshness } from "./utils/time.js";
|
|
20
|
+
import { formatAdvisorySourceLine, logInfo, logWarn, printCacheSummary, sortFindingsForOutput } from "./output/formatters.js";
|
|
21
|
+
import { countBySeverity } from "./utils/severity.js";
|
|
20
22
|
import { buildReportData, writeHtmlReport } from "./output/html-reporter.js";
|
|
21
23
|
import { writeOutputs } from "./output/write-outputs.js";
|
|
22
24
|
import { printSummary, printActionSummary, printSuggestedFixCommands, printSuggestedFixCommandSkips, printCoverage, printSkippedDependencies, printTable, printFinalStatus, printCompactOutput } from "./output/printers.js";
|
|
23
25
|
import { installSkill } from "./skills/install.js";
|
|
26
|
+
import { readDirectDependencyNames } from "./utils/package-json.js";
|
|
24
27
|
let parsedArgs = null;
|
|
25
28
|
try {
|
|
26
29
|
parsedArgs = parseArgs(process.argv.slice(2));
|
|
@@ -39,15 +42,15 @@ if (parsedArgs) {
|
|
|
39
42
|
process.exit(0);
|
|
40
43
|
}
|
|
41
44
|
else if (options.version) {
|
|
42
|
-
printBanner();
|
|
45
|
+
printBanner(options);
|
|
43
46
|
process.exit(0);
|
|
44
47
|
}
|
|
45
48
|
else {
|
|
46
49
|
const projectPath = path.resolve(projectArg || ".");
|
|
47
|
-
const batchSize = Number(options.batchSize ||
|
|
48
|
-
const searchDepth = Math.max(0, Number(options.searchDepth ||
|
|
50
|
+
const batchSize = Number(options.batchSize || DEFAULT_BATCH_SIZE);
|
|
51
|
+
const searchDepth = Math.max(0, Number(options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
49
52
|
async function main() {
|
|
50
|
-
printBanner();
|
|
53
|
+
printBanner(options);
|
|
51
54
|
if (command === "advisories-sync") {
|
|
52
55
|
const spinner = createSpinner("Preparing advisory sync...", options);
|
|
53
56
|
const usePlainProgressLogs = !process.stdout.isTTY || !!options.json;
|
|
@@ -79,26 +82,7 @@ if (parsedArgs) {
|
|
|
79
82
|
process.exit(0);
|
|
80
83
|
return;
|
|
81
84
|
}
|
|
82
|
-
|
|
83
|
-
throw new Error("--offline/--offline-db cannot be used with --osv-url");
|
|
84
|
-
}
|
|
85
|
-
if (options.noCache && (options.offline || options.offlineDb)) {
|
|
86
|
-
throw new Error("--no-cache cannot be used with --offline or --offline-db");
|
|
87
|
-
}
|
|
88
|
-
if (options.osvUrl) {
|
|
89
|
-
try {
|
|
90
|
-
new URL(options.osvUrl);
|
|
91
|
-
}
|
|
92
|
-
catch {
|
|
93
|
-
throw new Error(`Invalid value for --osv-url: ${options.osvUrl}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (options.fix && options.json) {
|
|
97
|
-
throw new Error("--fix cannot be used with --json");
|
|
98
|
-
}
|
|
99
|
-
if (options.report && options.json) {
|
|
100
|
-
throw new Error("--report cannot be used with --json");
|
|
101
|
-
}
|
|
85
|
+
validateOptions(options);
|
|
102
86
|
let advisorySourceLine;
|
|
103
87
|
let advisoryDbFreshnessLine = null;
|
|
104
88
|
let advisoryDbWarning = null;
|
|
@@ -255,11 +239,21 @@ if (parsedArgs) {
|
|
|
255
239
|
main().catch((error) => {
|
|
256
240
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
257
241
|
console.error(chalk.red(`Error: ${errorMessage}`));
|
|
258
|
-
if (isSslCertificateError(
|
|
242
|
+
if (isSslCertificateError(error)) {
|
|
259
243
|
const [hint, ...rest] = sslCertificateErrorHint();
|
|
260
244
|
console.error(chalk.yellow(hint));
|
|
261
245
|
rest.forEach(line => console.error(chalk.gray(line)));
|
|
262
246
|
}
|
|
247
|
+
else if (isRateLimitError(errorMessage)) {
|
|
248
|
+
const [hint, ...rest] = rateLimitAdvisoryRequestHint();
|
|
249
|
+
console.error(chalk.yellow(hint));
|
|
250
|
+
rest.forEach(line => console.error(chalk.gray(line)));
|
|
251
|
+
}
|
|
252
|
+
else if (isServerError(errorMessage)) {
|
|
253
|
+
const [hint, ...rest] = serverAdvisoryRequestHint();
|
|
254
|
+
console.error(chalk.yellow(hint));
|
|
255
|
+
rest.forEach(line => console.error(chalk.gray(line)));
|
|
256
|
+
}
|
|
263
257
|
else if (isLikelyBlockedAdvisoryRequestError(errorMessage)) {
|
|
264
258
|
const [hint, ...rest] = blockedAdvisoryRequestHint();
|
|
265
259
|
console.error(chalk.yellow(hint));
|
|
@@ -269,13 +263,6 @@ if (parsedArgs) {
|
|
|
269
263
|
});
|
|
270
264
|
}
|
|
271
265
|
}
|
|
272
|
-
function formatAdvisorySourceLine(sourceLabel) {
|
|
273
|
-
const match = sourceLabel.match(/^(.*) \((.*)\)$/);
|
|
274
|
-
if (!match) {
|
|
275
|
-
return sourceLabel;
|
|
276
|
-
}
|
|
277
|
-
return `${match[1]} (${chalk.cyan(match[2])})`;
|
|
278
|
-
}
|
|
279
266
|
async function scanProject(params) {
|
|
280
267
|
const directDependencyNames = readDirectDependencyNames(params.projectPath, !!params.options.prodOnly);
|
|
281
268
|
const findings = await scanPackages(params.scanInput.packages, params.batchSize, params.options, {
|
|
@@ -348,6 +335,7 @@ async function applyFixesIfRequested(params) {
|
|
|
348
335
|
const commandLabel = commandLabelForPackageManager(params.plan.packageManager);
|
|
349
336
|
const total = directTargets.length;
|
|
350
337
|
const spinner = createSpinner(`Applying direct package fixes with ${commandLabel}... 0/${total}`, params.options);
|
|
338
|
+
const fixHint = `\nHint: Check that \`${params.plan.packageManager}\` is available and you have write access to node_modules.\nIf running in CI, ensure the install step has already run before cve-lite --fix.`;
|
|
351
339
|
for (let i = 0; i < directTargets.length; i++) {
|
|
352
340
|
const target = directTargets[i];
|
|
353
341
|
const commandParts = buildFixCommandParts(params.plan.packageManager, [target]);
|
|
@@ -355,11 +343,11 @@ async function applyFixesIfRequested(params) {
|
|
|
355
343
|
const run = await runInstallCommand(commandParts[0], commandParts.slice(1), params.projectPath);
|
|
356
344
|
if (run.error) {
|
|
357
345
|
spinner.fail("Failed to apply fixes");
|
|
358
|
-
throw new Error(`Failed to apply fixes: ${run.error.message}`);
|
|
346
|
+
throw new Error(`Failed to apply fixes: ${run.error.message}${fixHint}`);
|
|
359
347
|
}
|
|
360
348
|
if ((run.status ?? 1) !== 0) {
|
|
361
349
|
spinner.fail(`Fix command failed (${commandLabel})`);
|
|
362
|
-
throw new Error(`Fix command exited with status ${run.status ?? 1}`);
|
|
350
|
+
throw new Error(`Fix command exited with status ${run.status ?? 1}${fixHint}`);
|
|
363
351
|
}
|
|
364
352
|
}
|
|
365
353
|
spinner.succeed(`Applied ${directTargets.length} direct package fix${directTargets.length === 1 ? "" : "es"} with ${commandLabel}`);
|
|
@@ -414,20 +402,6 @@ function commandLabelForPackageManager(packageManager) {
|
|
|
414
402
|
return "bun add";
|
|
415
403
|
return "yarn add";
|
|
416
404
|
}
|
|
417
|
-
function countBySeverity(findings) {
|
|
418
|
-
const counts = {
|
|
419
|
-
none: 0,
|
|
420
|
-
low: 0,
|
|
421
|
-
medium: 0,
|
|
422
|
-
high: 0,
|
|
423
|
-
critical: 0,
|
|
424
|
-
unknown: 0,
|
|
425
|
-
};
|
|
426
|
-
for (const finding of findings) {
|
|
427
|
-
counts[finding.severity] += 1;
|
|
428
|
-
}
|
|
429
|
-
return counts;
|
|
430
|
-
}
|
|
431
405
|
function printFixModeSummary(params) {
|
|
432
406
|
const result = params.fixResult;
|
|
433
407
|
if (!result)
|
|
@@ -454,140 +428,3 @@ function printFixModeSummary(params) {
|
|
|
454
428
|
console.log(`- Remaining findings after fix: ${chalk.white(String(params.findingsAfterFix))}`);
|
|
455
429
|
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))}`);
|
|
456
430
|
}
|
|
457
|
-
function readDirectDependencyNames(projectPath, prodOnly) {
|
|
458
|
-
const packageJsonPath = path.join(projectPath, "package.json");
|
|
459
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
460
|
-
return null;
|
|
461
|
-
}
|
|
462
|
-
try {
|
|
463
|
-
const directNames = new Set();
|
|
464
|
-
const rootManifest = readPackageJsonObject(packageJsonPath);
|
|
465
|
-
if (!rootManifest) {
|
|
466
|
-
return null;
|
|
467
|
-
}
|
|
468
|
-
addDependencyNamesFromManifest(directNames, rootManifest, prodOnly);
|
|
469
|
-
const workspacePatterns = readWorkspacePatterns(rootManifest);
|
|
470
|
-
for (const workspacePackageJsonPath of resolveWorkspacePackageJsonPaths(projectPath, workspacePatterns)) {
|
|
471
|
-
const workspaceManifest = readPackageJsonObject(workspacePackageJsonPath);
|
|
472
|
-
if (!workspaceManifest)
|
|
473
|
-
continue;
|
|
474
|
-
addDependencyNamesFromManifest(directNames, workspaceManifest, prodOnly);
|
|
475
|
-
}
|
|
476
|
-
return directNames;
|
|
477
|
-
}
|
|
478
|
-
catch {
|
|
479
|
-
return null;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
function readPackageJsonObject(filePath) {
|
|
483
|
-
try {
|
|
484
|
-
const raw = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
485
|
-
return raw && typeof raw === "object" ? raw : null;
|
|
486
|
-
}
|
|
487
|
-
catch {
|
|
488
|
-
return null;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
function addDependencyNamesFromManifest(target, manifest, prodOnly) {
|
|
492
|
-
const sections = [
|
|
493
|
-
isRecord(manifest.dependencies) ? manifest.dependencies : undefined,
|
|
494
|
-
isRecord(manifest.optionalDependencies) ? manifest.optionalDependencies : undefined,
|
|
495
|
-
];
|
|
496
|
-
if (!prodOnly) {
|
|
497
|
-
sections.push(isRecord(manifest.devDependencies) ? manifest.devDependencies : undefined);
|
|
498
|
-
}
|
|
499
|
-
for (const section of sections) {
|
|
500
|
-
if (!section)
|
|
501
|
-
continue;
|
|
502
|
-
for (const name of Object.keys(section)) {
|
|
503
|
-
target.add(name);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
function readWorkspacePatterns(manifest) {
|
|
508
|
-
const workspaces = manifest.workspaces;
|
|
509
|
-
if (Array.isArray(workspaces)) {
|
|
510
|
-
return workspaces.filter((value) => typeof value === "string");
|
|
511
|
-
}
|
|
512
|
-
if (isRecord(workspaces) && Array.isArray(workspaces.packages)) {
|
|
513
|
-
return workspaces.packages.filter((value) => typeof value === "string");
|
|
514
|
-
}
|
|
515
|
-
return [];
|
|
516
|
-
}
|
|
517
|
-
function resolveWorkspacePackageJsonPaths(projectPath, patterns) {
|
|
518
|
-
const matches = new Set();
|
|
519
|
-
for (const pattern of patterns) {
|
|
520
|
-
const normalized = pattern.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
521
|
-
if (!normalized)
|
|
522
|
-
continue;
|
|
523
|
-
for (const relativeDir of expandWorkspacePattern(projectPath, normalized.split("/").filter(Boolean), "")) {
|
|
524
|
-
const packageJsonPath = path.join(projectPath, relativeDir, "package.json");
|
|
525
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
526
|
-
matches.add(packageJsonPath);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
return [...matches];
|
|
531
|
-
}
|
|
532
|
-
function expandWorkspacePattern(projectPath, segments, currentRelativePath) {
|
|
533
|
-
if (segments.length === 0) {
|
|
534
|
-
return currentRelativePath ? [currentRelativePath] : [];
|
|
535
|
-
}
|
|
536
|
-
const [segment, ...rest] = segments;
|
|
537
|
-
if (segment === "*") {
|
|
538
|
-
const baseDir = currentRelativePath ? path.join(projectPath, currentRelativePath) : projectPath;
|
|
539
|
-
let entries = [];
|
|
540
|
-
try {
|
|
541
|
-
entries = fs.readdirSync(baseDir, { withFileTypes: true });
|
|
542
|
-
}
|
|
543
|
-
catch {
|
|
544
|
-
return [];
|
|
545
|
-
}
|
|
546
|
-
return entries
|
|
547
|
-
.filter(entry => entry.isDirectory())
|
|
548
|
-
.flatMap(entry => {
|
|
549
|
-
const nextRelativePath = currentRelativePath
|
|
550
|
-
? path.join(currentRelativePath, entry.name)
|
|
551
|
-
: entry.name;
|
|
552
|
-
return expandWorkspacePattern(projectPath, rest, nextRelativePath);
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
const nextRelativePath = currentRelativePath ? path.join(currentRelativePath, segment) : segment;
|
|
556
|
-
const nextAbsolutePath = path.join(projectPath, nextRelativePath);
|
|
557
|
-
if (!fs.existsSync(nextAbsolutePath) || !fs.statSync(nextAbsolutePath).isDirectory()) {
|
|
558
|
-
return [];
|
|
559
|
-
}
|
|
560
|
-
return expandWorkspacePattern(projectPath, rest, nextRelativePath);
|
|
561
|
-
}
|
|
562
|
-
function isRecord(value) {
|
|
563
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
564
|
-
}
|
|
565
|
-
function formatAdvisoryDbFreshness(lastSyncAt) {
|
|
566
|
-
if (!lastSyncAt) {
|
|
567
|
-
return chalk.yellow("unknown");
|
|
568
|
-
}
|
|
569
|
-
const timestamp = Date.parse(lastSyncAt);
|
|
570
|
-
if (Number.isNaN(timestamp)) {
|
|
571
|
-
return chalk.yellow("unknown");
|
|
572
|
-
}
|
|
573
|
-
return `${relativeAge(timestamp)} ${chalk.gray(`(${lastSyncAt})`)}`;
|
|
574
|
-
}
|
|
575
|
-
function relativeAge(timestamp) {
|
|
576
|
-
const deltaMs = Math.max(0, Date.now() - timestamp);
|
|
577
|
-
const minute = 60 * 1000;
|
|
578
|
-
const hour = 60 * minute;
|
|
579
|
-
const day = 24 * hour;
|
|
580
|
-
if (deltaMs < minute) {
|
|
581
|
-
return "just synced";
|
|
582
|
-
}
|
|
583
|
-
if (deltaMs < hour) {
|
|
584
|
-
const minutes = Math.floor(deltaMs / minute);
|
|
585
|
-
return `synced ${minutes} minute${minutes === 1 ? "" : "s"} ago`;
|
|
586
|
-
}
|
|
587
|
-
if (deltaMs < day) {
|
|
588
|
-
const hours = Math.floor(deltaMs / hour);
|
|
589
|
-
return `synced ${hours} hour${hours === 1 ? "" : "s"} ago`;
|
|
590
|
-
}
|
|
591
|
-
const days = Math.floor(deltaMs / day);
|
|
592
|
-
return `synced ${days} day${days === 1 ? "" : "s"} ago`;
|
|
593
|
-
}
|
|
@@ -26,6 +26,13 @@ export function formatRelationshipLabel(value) {
|
|
|
26
26
|
return chalk.yellow(value);
|
|
27
27
|
return chalk.gray(value);
|
|
28
28
|
}
|
|
29
|
+
export function formatAdvisorySourceLine(sourceLabel) {
|
|
30
|
+
const match = sourceLabel.match(/^(.*) \((.*)\)$/);
|
|
31
|
+
if (!match) {
|
|
32
|
+
return sourceLabel;
|
|
33
|
+
}
|
|
34
|
+
return `${match[1]} (${chalk.cyan(match[2])})`;
|
|
35
|
+
}
|
|
29
36
|
// MAL-* is the OSV prefix for malicious code advisories
|
|
30
37
|
function isMaliciousAdvisory(finding) {
|
|
31
38
|
return finding.vulnerabilities.some(v => v.id.startsWith("MAL-"));
|
|
@@ -48,7 +55,7 @@ export function getRecommendedAction(finding) {
|
|
|
48
55
|
return `No known fix exists for ${finding.pkg.name}. Consider replacing it with an actively maintained alternative.`;
|
|
49
56
|
}
|
|
50
57
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
51
|
-
return
|
|
58
|
+
return `${finding.recommendedNpmTransitiveRemediation.package} already permits ${finding.pkg.name}@${finding.recommendedNpmTransitiveRemediation.targetChildVersion} — run the lockfile refresh command to pick it up.`;
|
|
52
59
|
}
|
|
53
60
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "upgrade-parent-to-version" &&
|
|
54
61
|
finding.recommendedNpmTransitiveRemediation.targetVersion) {
|
|
@@ -149,7 +156,7 @@ export function summarizeNextAction(finding) {
|
|
|
149
156
|
return `No known fix exists for ${finding.pkg.name}. Consider replacing it with an actively maintained alternative.`;
|
|
150
157
|
}
|
|
151
158
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
152
|
-
return `
|
|
159
|
+
return `Lockfile refresh — ${finding.recommendedNpmTransitiveRemediation.package} already permits a safe version.`;
|
|
153
160
|
}
|
|
154
161
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "upgrade-parent-to-version" &&
|
|
155
162
|
finding.recommendedNpmTransitiveRemediation.targetVersion) {
|
|
@@ -490,11 +490,12 @@ function renderFixPlan(plan) {
|
|
|
490
490
|
const skippedCount = plan.skipped.length;
|
|
491
491
|
const commandRows = plan.sections.map(section => {
|
|
492
492
|
const targetRows = section.targets.map(t => {
|
|
493
|
+
const displayVersion = t.displayTargetVersion ?? t.targetVersion;
|
|
493
494
|
const isMajor = t.currentVersion ? isMajorVersionBump(t.currentVersion, t.targetVersion) : false;
|
|
494
495
|
const breakBadge = isMajor ? ` <span class="break-badge">⚠ breaking</span>` : "";
|
|
495
496
|
const versionHtml = t.currentVersion
|
|
496
|
-
? `<span class="fix-target-pkg">${escapeHtml(t.package)}@${escapeHtml(t.currentVersion)}</span><span class="fix-target-arrow">→</span><span class="fix-target-to">${escapeHtml(
|
|
497
|
-
: `<span class="fix-target-pkg">${escapeHtml(t.package)}</span><span class="fix-target-arrow">→</span><span class="fix-target-to">${escapeHtml(
|
|
497
|
+
? `<span class="fix-target-pkg">${escapeHtml(t.package)}@${escapeHtml(t.currentVersion)}</span><span class="fix-target-arrow">→</span><span class="fix-target-to">${escapeHtml(displayVersion)}</span>`
|
|
498
|
+
: `<span class="fix-target-pkg">${escapeHtml(t.package)}</span><span class="fix-target-arrow">→</span><span class="fix-target-to">${escapeHtml(displayVersion)}</span>`;
|
|
498
499
|
const statsHtml = t.scannedVersions != null
|
|
499
500
|
? ` <span class="fix-target-stats">${t.scannedVersions} scanned${t.knownVulnerableVersions != null ? ` · ${t.knownVulnerableVersions} still vulnerable` : ""}</span>`
|
|
500
501
|
: "";
|
|
@@ -530,6 +531,9 @@ function renderFixPlan(plan) {
|
|
|
530
531
|
const skippedBadgePart = skippedCount > 0
|
|
531
532
|
? ` · <button class="skipped-toggle" onclick="toggleSkipped()">↓ ${skippedCount} skipped</button>`
|
|
532
533
|
: "";
|
|
534
|
+
const coverageText = plan.coveredFindingCount === plan.totalFindingCount
|
|
535
|
+
? `Running all commands should fix all ${plan.totalFindingCount} findings.`
|
|
536
|
+
: `Running all commands should fix <strong>${plan.coveredFindingCount}</strong> of <strong>${plan.totalFindingCount}</strong> findings.`;
|
|
533
537
|
return `<div class="fix-plan">
|
|
534
538
|
<div class="fix-plan-header">
|
|
535
539
|
<h2><span class="icon">✦</span> Suggested Fix Plan</h2>
|
|
@@ -537,6 +541,7 @@ function renderFixPlan(plan) {
|
|
|
537
541
|
</div>
|
|
538
542
|
<div class="fix-commands">${commandRows}
|
|
539
543
|
</div>${skippedSection}
|
|
544
|
+
<div style="padding:10px 18px;border-top:1px solid #21262d;font-size:11px;color:#8b949e">${coverageText}</div>
|
|
540
545
|
</div>`;
|
|
541
546
|
}
|
|
542
547
|
export async function writeHtmlReport(params) {
|
package/dist/output/printers.js
CHANGED
|
@@ -89,6 +89,13 @@ export function printSuggestedFixCommands(findings, scanInput, options) {
|
|
|
89
89
|
}
|
|
90
90
|
console.log(renderCommandCallout(section.command));
|
|
91
91
|
}
|
|
92
|
+
if (plan.coveredFindingCount > 0) {
|
|
93
|
+
console.log("");
|
|
94
|
+
const coverage = plan.coveredFindingCount === plan.totalFindingCount
|
|
95
|
+
? chalk.gray(`Running all commands above should fix all ${plan.totalFindingCount} findings.`)
|
|
96
|
+
: chalk.gray(`Running all commands above should fix ${chalk.white(String(plan.coveredFindingCount))} of ${chalk.white(String(plan.totalFindingCount))} findings.`);
|
|
97
|
+
console.log(coverage);
|
|
98
|
+
}
|
|
92
99
|
}
|
|
93
100
|
export function printSuggestedFixCommandSkips(findings, scanInput, options) {
|
|
94
101
|
const plan = buildSuggestedFixCommandPlan(findings, scanInput, options);
|
|
@@ -305,7 +312,7 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
305
312
|
console.log(` ${chalk.red(`⚠ Malicious: ${action}`)}`);
|
|
306
313
|
}
|
|
307
314
|
else if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
308
|
-
console.log(` ${chalk.gray(`Fix:
|
|
315
|
+
console.log(` ${chalk.gray(`Fix: lockfile refresh — ${finding.recommendedNpmTransitiveRemediation.package} already permits a safe version`)}`);
|
|
309
316
|
}
|
|
310
317
|
else if (finding.recommendedParentUpgrade) {
|
|
311
318
|
console.log(` ${chalk.gray(`Fix: upgrade ${finding.recommendedParentUpgrade.package} to ${finding.recommendedParentUpgrade.targetVersion}`)}`);
|
package/dist/parsers/bun-lock.js
CHANGED
|
@@ -4,6 +4,25 @@ function parseJsonc(text) {
|
|
|
4
4
|
// bun.lock uses JSONC (trailing commas). Strip them before parsing.
|
|
5
5
|
return JSON.parse(text.replace(/,(\s*[}\]])/g, "$1"));
|
|
6
6
|
}
|
|
7
|
+
export function buildBunWorkspaceMap(filePath) {
|
|
8
|
+
const raw = parseJsonc(fs.readFileSync(filePath, "utf8"));
|
|
9
|
+
const workspaces = raw?.workspaces ?? {};
|
|
10
|
+
const map = new Map();
|
|
11
|
+
for (const [workspacePath, workspace] of Object.entries(workspaces)) {
|
|
12
|
+
for (const depSectionName of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
13
|
+
const depSection = workspace?.[depSectionName];
|
|
14
|
+
if (!depSection || typeof depSection !== "object")
|
|
15
|
+
continue;
|
|
16
|
+
for (const depName of Object.keys(depSection)) {
|
|
17
|
+
const existing = map.get(depName) ?? [];
|
|
18
|
+
if (!existing.includes(workspacePath)) {
|
|
19
|
+
map.set(depName, [...existing, workspacePath]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return map;
|
|
25
|
+
}
|
|
7
26
|
export function loadFromBunLock(filePath, prodOnly) {
|
|
8
27
|
const raw = parseJsonc(fs.readFileSync(filePath, "utf8"));
|
|
9
28
|
const packages = raw?.packages ?? {};
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { upsertPackage, normalizeNodeModulesPath } from "./utils.js";
|
|
3
3
|
import { loadNpmLockGraph } from "./npm-lock-graph.js";
|
|
4
|
+
export function buildNpmWorkspaceMap(filePath) {
|
|
5
|
+
const raw = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
6
|
+
const map = new Map();
|
|
7
|
+
if (!raw.packages || typeof raw.packages !== "object")
|
|
8
|
+
return map;
|
|
9
|
+
for (const [pkgPath, meta] of Object.entries(raw.packages)) {
|
|
10
|
+
if (pkgPath.includes("node_modules/"))
|
|
11
|
+
continue;
|
|
12
|
+
const workspacePath = pkgPath === "" ? "." : pkgPath;
|
|
13
|
+
for (const depSectionName of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
14
|
+
const depSection = meta?.[depSectionName];
|
|
15
|
+
if (!depSection || typeof depSection !== "object")
|
|
16
|
+
continue;
|
|
17
|
+
for (const depName of Object.keys(depSection)) {
|
|
18
|
+
const existing = map.get(depName) ?? [];
|
|
19
|
+
if (!existing.includes(workspacePath)) {
|
|
20
|
+
map.set(depName, [...existing, workspacePath]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return map;
|
|
26
|
+
}
|
|
4
27
|
export function loadFromPackageLock(filePath, prodOnly) {
|
|
5
28
|
const raw = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
6
29
|
const map = new Map();
|
|
@@ -5,6 +5,26 @@ import { upsertPackage } from "./utils.js";
|
|
|
5
5
|
import { uniquePathArrays } from "../utils/array.js";
|
|
6
6
|
const MAX_PATHS_PER_PACKAGE = 5;
|
|
7
7
|
const MAX_PATH_DEPTH = 10;
|
|
8
|
+
export function buildPnpmWorkspaceMap(filePath) {
|
|
9
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
10
|
+
const parsed = YAML.parse(content);
|
|
11
|
+
const importers = parsed?.importers ?? {};
|
|
12
|
+
const map = new Map();
|
|
13
|
+
for (const [importerPath, importer] of Object.entries(importers)) {
|
|
14
|
+
for (const depSectionName of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
15
|
+
const depSection = importer?.[depSectionName];
|
|
16
|
+
if (!depSection || typeof depSection !== "object")
|
|
17
|
+
continue;
|
|
18
|
+
for (const depName of Object.keys(depSection)) {
|
|
19
|
+
const existing = map.get(depName) ?? [];
|
|
20
|
+
if (!existing.includes(importerPath)) {
|
|
21
|
+
map.set(depName, [...existing, importerPath]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return map;
|
|
27
|
+
}
|
|
8
28
|
export function loadFromPnpmLock(filePath, prodOnly) {
|
|
9
29
|
const content = fs.readFileSync(filePath, "utf8");
|
|
10
30
|
const parsed = YAML.parse(content);
|