cve-lite-cli 1.34.0 → 1.35.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/dist/cli/advisories-init.js +13 -0
- package/dist/cli/advisories-sync.js +30 -0
- package/dist/cli/config-command.js +15 -0
- package/dist/cli/config.js +29 -0
- package/dist/cli/help.js +4 -4
- package/dist/cli/overrides.js +10 -1
- package/dist/constants.js +52 -0
- package/dist/index.js +25 -719
- package/dist/output/cyclonedx.js +12 -0
- package/dist/output/html-reporter.js +73 -38
- package/dist/output/multi-folder-html-reporter.js +16 -10
- package/dist/output/multi-folder-printer.js +1 -1
- package/dist/output/override-findings-sarif.js +1 -0
- package/dist/output/printers.js +427 -270
- package/dist/output/sarif.js +17 -1
- package/dist/output/sbom-dependency-edges.js +29 -19
- package/dist/overrides/admitted-scan.js +158 -0
- package/dist/overrides/api.js +16 -0
- package/dist/overrides/context-builder.js +4 -0
- package/dist/overrides/context.js +8 -1
- package/dist/overrides/detectors/index.js +2 -0
- package/dist/overrides/detectors/oa010-vulnerable-floor.js +123 -0
- package/dist/overrides/parsing/registry.js +53 -0
- package/dist/parsers/bun-lock-graph.js +182 -0
- package/dist/parsers/bun-lock.js +93 -132
- package/dist/parsers/index.js +75 -149
- package/dist/parsers/multi-package.js +5 -6
- package/dist/parsers/pnpm-lock-graph.js +94 -0
- package/dist/parsers/pnpm-lock.js +5 -5
- package/dist/parsers/yarn-lock-graph.js +148 -0
- package/dist/parsers/yarn-lock.js +3 -3
- package/dist/remediation/fix-commands.js +48 -7
- package/dist/scan/completeness.js +1 -1
- package/dist/scan/single-scan.js +643 -0
- package/dist/utils/file.js +11 -14
- package/dist/utils/version.js +10 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,44 +5,21 @@ import { existsSync } from "node:fs";
|
|
|
5
5
|
import { parseArgs } from "./cli/args.js";
|
|
6
6
|
import { printBanner, printHelp, printOverridesHelp } from "./cli/help.js";
|
|
7
7
|
import { validateOptions } from "./cli/validate.js";
|
|
8
|
-
import {
|
|
9
|
-
import { scanPackages, buildCoverageNotes, createAdvisorySource } from "./scanner.js";
|
|
10
|
-
import { syncOsvAdvisories } from "./advisory/osv-sync.js";
|
|
11
|
-
import { normalizeSeverity } from "./osv/severity.js";
|
|
12
|
-
import { DEFAULT_BATCH_SIZE, DEFAULT_SEARCH_DEPTH, OVERRIDES_COMMAND } from "./constants.js";
|
|
8
|
+
import { DEFAULT_BATCH_SIZE, DEFAULT_SEARCH_DEPTH } from "./constants.js";
|
|
13
9
|
import { chalk } from "./utils/chalk.js";
|
|
14
|
-
import { createSpinner } from "./output/spinner.js";
|
|
15
10
|
import { createDebugLogger } from "./output/debug.js";
|
|
16
|
-
import { buildSuggestedFixCommandPlan } from "./remediation/fix-commands.js";
|
|
17
|
-
import { scanProjectForPackageUsage } from "./usage/scanner.js";
|
|
18
11
|
import { getCliVersion } from "./utils/version-info.js";
|
|
19
|
-
import { getNetworkErrorHint
|
|
20
|
-
import {
|
|
21
|
-
import { pluralize, nearestCommand } from "./utils/string.js";
|
|
12
|
+
import { getNetworkErrorHint } from "./utils/network.js";
|
|
13
|
+
import { nearestCommand } from "./utils/string.js";
|
|
22
14
|
import { EXIT_ERROR } from "./types.js";
|
|
23
|
-
import {
|
|
24
|
-
import { countBySeverity, reachesFailOn } from "./utils/severity.js";
|
|
25
|
-
import { buildReportData, writeHtmlReport } from "./output/html-reporter.js";
|
|
26
|
-
import { writeOutputs } from "./output/write-outputs.js";
|
|
27
|
-
import { selectFindingsForTable } from "./output/finding-display.js";
|
|
28
|
-
import { printActionSummary, printCompactOutput, printCoverage, printFinalStatus, printOverrideHint, printSkippedDependencies, printSuggestedFixCommands, printSuggestedFixCommandSkips, printSummary, printTable, } from "./output/printers.js";
|
|
29
|
-
import { renderOverrideFindings } from "./output/override-findings-terminal.js";
|
|
30
|
-
import { detectDM001 } from "./maintenance/dm001-maintenance-risk.js";
|
|
31
|
-
import { renderMaintenanceFindings } from "./output/maintenance-terminal.js";
|
|
32
|
-
import { detectLicenseIssues } from "./licenses/license-check.js";
|
|
33
|
-
import { renderLicenseFindings } from "./output/license-terminal.js";
|
|
15
|
+
import { formatHintLines, logWarn } from "./output/formatters.js";
|
|
34
16
|
import { installSkill } from "./skills/install.js";
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import { readDirectDependencyNames, hasOverrideEntries } from "./utils/package-json.js";
|
|
38
|
-
import { applyFixesIfRequested, printFixModeSummary, writeFixResultJson, } from "./utils/fix-runner.js";
|
|
17
|
+
import { setupCaCert } from "./cli/config.js";
|
|
18
|
+
import { handleConfigCommand } from "./cli/config-command.js";
|
|
39
19
|
import { createAuditLog } from "./audit-log/index.js";
|
|
40
|
-
import { audit, buildOverrideContext } from "./overrides/index.js";
|
|
41
20
|
import { hasRootLockfile, findNestedLockfiles } from "./parsers/multi-package.js";
|
|
42
21
|
import { handleMultiFolderScan } from "./scan/multi-folder-scan.js";
|
|
43
|
-
import {
|
|
44
|
-
import { readBaseline, writeBaseline, filterNewFindings, ratchetOutcome } from "./utils/baseline.js";
|
|
45
|
-
import { formatDiagnosticMessage, getCompletenessImpact, shouldFailForIncompleteScan } from "./scan/completeness.js";
|
|
22
|
+
import { handleSingleFolderScan } from "./scan/single-scan.js";
|
|
46
23
|
let parsedArgs = null;
|
|
47
24
|
try {
|
|
48
25
|
parsedArgs = parseArgs(process.argv.slice(2));
|
|
@@ -54,7 +31,7 @@ catch (error) {
|
|
|
54
31
|
process.exit(1);
|
|
55
32
|
}
|
|
56
33
|
if (parsedArgs) {
|
|
57
|
-
const { command, options, projectArg } = parsedArgs;
|
|
34
|
+
const { command, options, projectArg, configSubcommand } = parsedArgs;
|
|
58
35
|
const cliVersion = getCliVersion();
|
|
59
36
|
if (options.help) {
|
|
60
37
|
if (command === "overrides") {
|
|
@@ -98,82 +75,21 @@ if (parsedArgs) {
|
|
|
98
75
|
args: process.argv.slice(2),
|
|
99
76
|
});
|
|
100
77
|
if (command === "config") {
|
|
101
|
-
|
|
102
|
-
if (!configSubcommand) {
|
|
103
|
-
console.error(chalk.red("Error: config requires a subcommand: set, unset, show"));
|
|
104
|
-
console.error(chalk.gray("Run `cve-lite --help` for usage."));
|
|
105
|
-
process.exit(1);
|
|
106
|
-
}
|
|
107
|
-
try {
|
|
108
|
-
runConfigCommand(configSubcommand);
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
112
|
-
console.error(chalk.red(`Error: ${message}`));
|
|
113
|
-
process.exit(1);
|
|
114
|
-
}
|
|
78
|
+
handleConfigCommand(configSubcommand);
|
|
115
79
|
process.exit(0);
|
|
80
|
+
return;
|
|
116
81
|
}
|
|
117
|
-
const
|
|
118
|
-
const resolvedCaCert = options.caCert ?? savedConfig.caCert;
|
|
119
|
-
if (resolvedCaCert) {
|
|
120
|
-
if (!options.caCert && savedConfig.caCert) {
|
|
121
|
-
try {
|
|
122
|
-
validateCaCertFile(resolvedCaCert);
|
|
123
|
-
}
|
|
124
|
-
catch (err) {
|
|
125
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
126
|
-
console.error(chalk.red(`Error: Saved ca-cert is no longer valid: ${message}`));
|
|
127
|
-
console.error(chalk.gray(`Run \`cve-lite config unset ca-cert\` to remove it.`));
|
|
128
|
-
process.exit(1);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
process.env.NODE_EXTRA_CA_CERTS = resolvedCaCert;
|
|
132
|
-
}
|
|
133
|
-
const certFetch = resolvedCaCert ? createCertAwareFetch(resolvedCaCert) : undefined;
|
|
134
|
-
debugLog("Config loaded", {
|
|
135
|
-
caCert: resolvedCaCert ?? null,
|
|
136
|
-
nodeExtraCaCerts: process.env.NODE_EXTRA_CA_CERTS ?? null,
|
|
137
|
-
});
|
|
82
|
+
const certFetch = setupCaCert(options, debugLog);
|
|
138
83
|
if (command === "advisories-sync") {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
const result = await syncOsvAdvisories({
|
|
142
|
-
outputPath: options.output,
|
|
143
|
-
fetchImpl: certFetch,
|
|
144
|
-
onProgress: event => {
|
|
145
|
-
if (event.phase === "complete") {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
if (usePlainProgressLogs) {
|
|
149
|
-
console.log(event.message);
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
spinner.update(event.message);
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
if (usePlainProgressLogs) {
|
|
156
|
-
console.log(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
spinner.succeed(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
160
|
-
}
|
|
161
|
-
console.log(`${chalk.gray("Advisory database:")} synced ${result.advisoryCount} ${pluralize(result.advisoryCount, "record")} to ${chalk.cyan(result.dbPath)}`);
|
|
84
|
+
const { runAdvisoriesSync } = await import("./cli/advisories-sync.js");
|
|
85
|
+
await runAdvisoriesSync({ options, fetchImpl: certFetch });
|
|
162
86
|
process.exit(0);
|
|
163
87
|
return;
|
|
164
88
|
}
|
|
165
89
|
if (command === "advisories-init") {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
console.log(`${chalk.gray("Advisory database:")} created an empty advisory database at ${chalk.cyan(dbPath)}`);
|
|
170
|
-
console.log(chalk.gray(`Populate it from your own sources, then scan with \`--offline-db ${dbPath}\`.`));
|
|
171
|
-
process.exit(0);
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
175
|
-
process.exit(1);
|
|
176
|
-
}
|
|
90
|
+
const { runAdvisoriesInit } = await import("./cli/advisories-init.js");
|
|
91
|
+
runAdvisoriesInit(options);
|
|
92
|
+
process.exit(0);
|
|
177
93
|
return;
|
|
178
94
|
}
|
|
179
95
|
if (command === "install-skill") {
|
|
@@ -197,6 +113,7 @@ if (parsedArgs) {
|
|
|
197
113
|
});
|
|
198
114
|
auditLogHandle.close();
|
|
199
115
|
process.exit(exitCode);
|
|
116
|
+
return;
|
|
200
117
|
}
|
|
201
118
|
const validationWarning = await validateOptions(options);
|
|
202
119
|
if (validationWarning)
|
|
@@ -214,566 +131,19 @@ if (parsedArgs) {
|
|
|
214
131
|
});
|
|
215
132
|
auditLogHandle.close();
|
|
216
133
|
process.exit(exitCode);
|
|
217
|
-
}
|
|
218
|
-
let advisorySourceLine = "";
|
|
219
|
-
let advisoryDbFreshnessLine = null;
|
|
220
|
-
let advisoryDbWarning = null;
|
|
221
|
-
try {
|
|
222
|
-
const advisorySource = createAdvisorySource({
|
|
223
|
-
osvUrl: options.osvUrl,
|
|
224
|
-
offline: options.offline,
|
|
225
|
-
offlineDb: options.offlineDb,
|
|
226
|
-
debugLog,
|
|
227
|
-
fetchImpl: certFetch,
|
|
228
|
-
});
|
|
229
|
-
advisorySourceLine = advisorySource.sourceLabel;
|
|
230
|
-
debugLog("Advisory source", {
|
|
231
|
-
mode: advisorySource.offline ? "offline" : "online",
|
|
232
|
-
url: options.osvUrl ?? (advisorySource.offline ? null : "https://api.osv.dev"),
|
|
233
|
-
label: advisorySourceLine,
|
|
234
|
-
});
|
|
235
|
-
if (advisorySource.offline) {
|
|
236
|
-
const metadata = advisorySource.advisoryDbMetadata;
|
|
237
|
-
advisoryDbFreshnessLine = formatAdvisoryDbFreshness(metadata?.lastSyncAt ?? null);
|
|
238
|
-
if (advisorySource.advisoryDbIsStale) {
|
|
239
|
-
advisoryDbWarning = metadata?.lastSyncAt
|
|
240
|
-
? "The local advisory DB appears stale. Re-run `cve-lite advisories sync` to refresh it."
|
|
241
|
-
: "The local advisory DB has no recorded sync timestamp. Re-run `cve-lite advisories sync` to refresh it.";
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
advisorySource.cleanup();
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
if (options.offline || options.offlineDb) {
|
|
248
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
249
|
-
throw new Error(`Offline advisory database is not available: ${reason}\n${offlineDbSyncHint(options.offlineDb).join("\n")}`);
|
|
250
|
-
}
|
|
251
|
-
throw error;
|
|
252
|
-
}
|
|
253
|
-
if (!options.json && !options.ratchet) {
|
|
254
|
-
if (options.offline || options.offlineDb) {
|
|
255
|
-
console.log(chalk.gray("Offline mode:") + " " + chalk.yellow("enabled") + " " + chalk.gray("(no external advisory calls will be made)"));
|
|
256
|
-
}
|
|
257
|
-
if (advisorySourceLine) {
|
|
258
|
-
console.log(`${chalk.gray("Advisory source:")} ${formatAdvisorySourceLine(advisorySourceLine)}`);
|
|
259
|
-
}
|
|
260
|
-
if (advisoryDbFreshnessLine) {
|
|
261
|
-
console.log(`${chalk.gray("Advisory DB freshness:")} ${advisoryDbFreshnessLine}`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
if (advisoryDbWarning) {
|
|
265
|
-
logWarn(advisoryDbWarning, options);
|
|
266
|
-
}
|
|
267
|
-
let scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
268
|
-
let packages = scanInput.packages;
|
|
269
|
-
if (scanInput.filePath) {
|
|
270
|
-
debugLog("Lockfile selected", {
|
|
271
|
-
source: scanInput.source,
|
|
272
|
-
path: scanInput.filePath,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
debugLog("Packages parsed", {
|
|
276
|
-
count: packages.length,
|
|
277
|
-
source: scanInput.source,
|
|
278
|
-
});
|
|
279
|
-
// Emit scan.started event after loading packages
|
|
280
|
-
const scanStartTime = Date.now();
|
|
281
|
-
auditLogHandle.emit({
|
|
282
|
-
ts: new Date().toISOString(),
|
|
283
|
-
type: "scan.started",
|
|
284
|
-
schemaVersion: 1,
|
|
285
|
-
projectPath,
|
|
286
|
-
mode: scanInput.mode,
|
|
287
|
-
source: scanInput.source,
|
|
288
|
-
flags: {
|
|
289
|
-
fix: options.fix === true,
|
|
290
|
-
json: options.json === true,
|
|
291
|
-
prodOnly: options.prodOnly === true,
|
|
292
|
-
offline: options.offline === true,
|
|
293
|
-
checkOverrides: options.checkOverrides === true,
|
|
294
|
-
},
|
|
295
|
-
});
|
|
296
|
-
if (!options.ratchet) {
|
|
297
|
-
logInfo(`Parsed ${packages.length} ${pluralize(packages.length, "package")} from ${scanInput.source}${scanInput.filePath ? ` (${path.relative(projectPath, scanInput.filePath) || path.basename(scanInput.filePath)})` : ""}`, options);
|
|
298
|
-
printCacheSummary(options.cacheDir, options);
|
|
299
|
-
}
|
|
300
|
-
if (scanInput.warnings.length > 0) {
|
|
301
|
-
for (const warning of scanInput.warnings) {
|
|
302
|
-
logWarn(warning, options);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
if (packages.length === 0) {
|
|
306
|
-
debugLog("Scan skipped", { reason: "no packages found", projectPath });
|
|
307
|
-
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
308
|
-
auditLogHandle.emit({
|
|
309
|
-
ts: new Date().toISOString(),
|
|
310
|
-
type: "scan.finished",
|
|
311
|
-
schemaVersion: 1,
|
|
312
|
-
durationMs: Date.now() - scanStartTime,
|
|
313
|
-
findingsCount: 0,
|
|
314
|
-
exitCode: 0,
|
|
315
|
-
});
|
|
316
|
-
auditLogHandle.close();
|
|
317
|
-
process.exit(0);
|
|
318
134
|
return;
|
|
319
135
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
scanInput,
|
|
136
|
+
const exitCode = await handleSingleFolderScan({
|
|
137
|
+
projectPath,
|
|
138
|
+
projectArg,
|
|
324
139
|
batchSize,
|
|
140
|
+
searchDepth,
|
|
325
141
|
options,
|
|
326
|
-
projectPath,
|
|
327
142
|
debugLog,
|
|
328
143
|
fetchImpl: certFetch,
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
let fixResult = null;
|
|
333
|
-
let baseline = readBaseline(projectArg ?? ".");
|
|
334
|
-
let suppressedCount = 0;
|
|
335
|
-
// Collect override findings if --check-overrides is set.
|
|
336
|
-
// Boundary: override hygiene is independent of the CVE ratchet/baseline. The
|
|
337
|
-
// baseline only ever records CVE findings (see src/utils/baseline.ts), so a
|
|
338
|
-
// --ratchet run skips the override audit entirely - override findings are never
|
|
339
|
-
// baselined or suppressed.
|
|
340
|
-
let overrideFindings = [];
|
|
341
|
-
if (options.checkOverrides && !options.ratchet) {
|
|
342
|
-
const overrideCtx = buildOverrideContext(projectPath, {
|
|
343
|
-
auditLog: auditLogHandle,
|
|
344
|
-
logger: {
|
|
345
|
-
info: (msg) => debugLog("oa.info", { message: msg }),
|
|
346
|
-
warn: (msg) => debugLog("oa.warn", { message: msg }),
|
|
347
|
-
error: (msg) => debugLog("oa.error", { message: msg }),
|
|
348
|
-
debug: (msg) => debugLog("oa.debug", { message: msg }),
|
|
349
|
-
},
|
|
350
|
-
checkNetwork: !!options.checkNetwork,
|
|
351
|
-
});
|
|
352
|
-
const auditResult = await audit(overrideCtx, { checkNetwork: !!options.checkNetwork });
|
|
353
|
-
overrideFindings = auditResult.findings;
|
|
354
|
-
}
|
|
355
|
-
let maintenanceFindings = [];
|
|
356
|
-
let licenseFindings = [];
|
|
357
|
-
let licenseLimitedToDirectOnly = false;
|
|
358
|
-
// Emit cve.detected for each CVE finding
|
|
359
|
-
for (const f of scanState.sorted) {
|
|
360
|
-
auditLogHandle.emit({
|
|
361
|
-
ts: new Date().toISOString(),
|
|
362
|
-
type: "cve.detected",
|
|
363
|
-
schemaVersion: 1,
|
|
364
|
-
package: { name: f.pkg.name, version: f.pkg.version },
|
|
365
|
-
severity: f.severity,
|
|
366
|
-
cveAliases: f.cveAliases,
|
|
367
|
-
vulnerabilityIds: f.vulnerabilities.map((v) => v.id),
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
if (options.fix) {
|
|
371
|
-
fixResult = await applyFixesIfRequested({
|
|
372
|
-
plan: scanState.suggestedFixCommands,
|
|
373
|
-
projectPath,
|
|
374
|
-
totalFindings: scanState.sorted.length,
|
|
375
|
-
options,
|
|
376
|
-
debugLog,
|
|
377
|
-
});
|
|
378
|
-
if (fixResult.appliedFixCount > 0) {
|
|
379
|
-
console.log(`${chalk.cyan("⠋")} ${chalk.gray("Rescanning project...")}`);
|
|
380
|
-
scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
381
|
-
packages = scanInput.packages;
|
|
382
|
-
if (packages.length === 0) {
|
|
383
|
-
debugLog("Scan skipped", { reason: "no packages found after fix rescan", projectPath });
|
|
384
|
-
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
385
|
-
auditLogHandle.emit({
|
|
386
|
-
ts: new Date().toISOString(),
|
|
387
|
-
type: "scan.finished",
|
|
388
|
-
schemaVersion: 1,
|
|
389
|
-
durationMs: Date.now() - scanStartTime,
|
|
390
|
-
findingsCount: 0,
|
|
391
|
-
exitCode: 0,
|
|
392
|
-
});
|
|
393
|
-
auditLogHandle.close();
|
|
394
|
-
process.exit(0);
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
scanState = await scanProject({
|
|
398
|
-
scanInput,
|
|
399
|
-
batchSize,
|
|
400
|
-
options,
|
|
401
|
-
projectPath,
|
|
402
|
-
debugLog,
|
|
403
|
-
fetchImpl: certFetch,
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
let overridesFixHookResult = null;
|
|
408
|
-
// Override hygiene is opt-in. Only run the fix hook (which can patch
|
|
409
|
-
// package.json) when --check-overrides was requested, so `cve-lite . --fix`
|
|
410
|
-
// stays a pure CVE operation and never touches overrides unasked.
|
|
411
|
-
if (options.fix && fixResult && options.checkOverrides) {
|
|
412
|
-
const { runOverridesFixHook } = await import("./cli/fix-overrides-hook.js");
|
|
413
|
-
const projectPathResolved = path.resolve(projectArg ?? ".");
|
|
414
|
-
// Collect CVE-touched targets from cve-lite's fix result.
|
|
415
|
-
const cveFixTargets = fixResult.applied.map((entry) => ({
|
|
416
|
-
name: entry.package,
|
|
417
|
-
version: entry.to,
|
|
418
|
-
}));
|
|
419
|
-
// Create a simple logger adapter if needed
|
|
420
|
-
const hookLogger = {
|
|
421
|
-
info: (msg) => debugLog("hook.info", { message: msg }),
|
|
422
|
-
warn: (msg) => debugLog("hook.warn", { message: msg }),
|
|
423
|
-
error: (msg) => debugLog("hook.error", { message: msg }),
|
|
424
|
-
debug: (msg) => debugLog("hook.debug", { message: msg }),
|
|
425
|
-
};
|
|
426
|
-
overridesFixHookResult = await runOverridesFixHook({
|
|
427
|
-
projectPath: projectPathResolved,
|
|
428
|
-
auditLog: auditLogHandle,
|
|
429
|
-
logger: hookLogger,
|
|
430
|
-
cveFixTargets,
|
|
431
|
-
});
|
|
432
|
-
if (!overridesFixHookResult.verifyOk) {
|
|
433
|
-
debugLog("overrides-fix-hook verify failed", {
|
|
434
|
-
failures: overridesFixHookResult.verifyFailures,
|
|
435
|
-
});
|
|
436
|
-
console.log(chalk.red(`Overrides fix verify failed:\n${overridesFixHookResult.verifyFailures
|
|
437
|
-
.map((v) => ` ${v.ruleId} ${v.package}: ${v.reason}`)
|
|
438
|
-
.join("\n")}`));
|
|
439
|
-
auditLogHandle.emit({
|
|
440
|
-
ts: new Date().toISOString(),
|
|
441
|
-
type: "scan.finished",
|
|
442
|
-
schemaVersion: 1,
|
|
443
|
-
durationMs: Date.now() - scanStartTime,
|
|
444
|
-
findingsCount: scanState.sorted.length + overrideFindings.length,
|
|
445
|
-
exitCode: 2,
|
|
446
|
-
});
|
|
447
|
-
auditLogHandle.close();
|
|
448
|
-
process.exit(2);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
// Emit cve.fix.applied for each target in the fix plan
|
|
452
|
-
if (scanState.suggestedFixCommands?.targets) {
|
|
453
|
-
for (const target of scanState.suggestedFixCommands.targets) {
|
|
454
|
-
auditLogHandle.emit({
|
|
455
|
-
ts: new Date().toISOString(),
|
|
456
|
-
type: "cve.fix.applied",
|
|
457
|
-
schemaVersion: 1,
|
|
458
|
-
package: target.package,
|
|
459
|
-
fromVersion: target.currentVersion ?? "unknown",
|
|
460
|
-
toVersion: target.targetVersion,
|
|
461
|
-
mechanism: target.kind,
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
if (options.fix) {
|
|
466
|
-
printFixModeSummary({
|
|
467
|
-
fixResult,
|
|
468
|
-
findingsBeforeFix,
|
|
469
|
-
findingsAfterFix: scanState.sorted.length,
|
|
470
|
-
remainingBySeverity: countBySeverity(scanState.sorted),
|
|
471
|
-
});
|
|
472
|
-
// Write fix result JSON for Action-level PR creation.
|
|
473
|
-
// Written even when appliedFixCount is 0 so the Action can detect
|
|
474
|
-
// the nothing-to-fix case without parsing stdout.
|
|
475
|
-
const fixResultJson = {
|
|
476
|
-
appliedFixCount: fixResult?.appliedFixCount ?? 0,
|
|
477
|
-
appliedWithinRangeRefreshCount: fixResult?.appliedWithinRangeRefreshCount ?? 0,
|
|
478
|
-
findingsBeforeFix,
|
|
479
|
-
findingsAfterFix: scanState.sorted.length,
|
|
480
|
-
applied: (fixResult?.applied ?? []).map(entry => ({
|
|
481
|
-
package: entry.package,
|
|
482
|
-
from: entry.from,
|
|
483
|
-
to: entry.to,
|
|
484
|
-
advisories: collectAdvisoryIdsForPackage(findingsBeforeFixList, entry.package),
|
|
485
|
-
})),
|
|
486
|
-
notAutoApplied: {
|
|
487
|
-
parentUpgradeCount: fixResult?.parentUpgradeCount ?? 0,
|
|
488
|
-
breakingUpgradeCount: fixResult?.breakingUpgradeCount ?? 0,
|
|
489
|
-
noFixCount: fixResult?.noFixCount ?? 0,
|
|
490
|
-
},
|
|
491
|
-
};
|
|
492
|
-
writeFixResultJson(fixResultJson, projectPath);
|
|
493
|
-
if (options.createPr && fixResult) {
|
|
494
|
-
// Override hygiene fixes also land in package.json (staged by create-pr), so
|
|
495
|
-
// a PR is warranted when either CVE fixes or override fixes were applied.
|
|
496
|
-
const overrideFixCount = overridesFixHookResult?.applied ?? 0;
|
|
497
|
-
if (fixResult.appliedFixCount === 0 && overrideFixCount === 0) {
|
|
498
|
-
logWarn("Skipping pull request creation: no direct fixes were applied.", options);
|
|
499
|
-
}
|
|
500
|
-
else {
|
|
501
|
-
console.log("");
|
|
502
|
-
console.log(chalk.bold.cyan("Creating pull request (--create-pr)"));
|
|
503
|
-
const prResult = await createPullRequestForFixes({
|
|
504
|
-
projectPath,
|
|
505
|
-
baseBranch: options.prBase ?? "main",
|
|
506
|
-
fixResult,
|
|
507
|
-
findingsBeforeFix: findingsBeforeFixList,
|
|
508
|
-
findingsAfterFix: scanState.sorted,
|
|
509
|
-
overrideFixCount,
|
|
510
|
-
});
|
|
511
|
-
if (prResult.skipped) {
|
|
512
|
-
logWarn(prResult.skipReason ?? "Pull request was not created.", options);
|
|
513
|
-
}
|
|
514
|
-
else if (prResult.prUrl) {
|
|
515
|
-
console.log(`${chalk.gray("Pull request:")} ${chalk.cyan(prResult.prUrl)}`);
|
|
516
|
-
console.log(`${chalk.gray("Branch:")} ${chalk.cyan(prResult.branchName)}`);
|
|
517
|
-
}
|
|
518
|
-
else {
|
|
519
|
-
logWarn(`Branch ${prResult.branchName} was pushed, but no pull request URL was returned.`, options);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
// --ratchet: with no baseline yet, save the current findings. With an
|
|
526
|
-
// existing baseline, GATE instead of re-saving - fail on findings not in the
|
|
527
|
-
// baseline. Re-saving here would silently absorb a new vulnerability into a
|
|
528
|
-
// fresh baseline, so a ratcheted CI job could never fail on a regression.
|
|
529
|
-
if (options.ratchet) {
|
|
530
|
-
const { hasDetectionGap } = getCompletenessImpact(scanState.completeness);
|
|
531
|
-
if (hasDetectionGap) {
|
|
532
|
-
console.log(chalk.red("Scan data is incomplete. Refusing to create or evaluate a baseline from partial detection data."));
|
|
533
|
-
for (const diagnostic of scanState.completeness.diagnostics) {
|
|
534
|
-
if (diagnostic.impact !== "detection")
|
|
535
|
-
continue;
|
|
536
|
-
console.log(chalk.red(` ${formatDiagnosticMessage(diagnostic.code, diagnostic.count, diagnostic.affectedPackageCount)}`));
|
|
537
|
-
}
|
|
538
|
-
auditLogHandle.emit({
|
|
539
|
-
ts: new Date().toISOString(),
|
|
540
|
-
type: "scan.finished",
|
|
541
|
-
schemaVersion: 1,
|
|
542
|
-
durationMs: Date.now() - scanStartTime,
|
|
543
|
-
findingsCount: scanState.sorted.length,
|
|
544
|
-
exitCode: EXIT_ERROR,
|
|
545
|
-
});
|
|
546
|
-
auditLogHandle.close();
|
|
547
|
-
process.exit(EXIT_ERROR);
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
const outcome = ratchetOutcome(baseline, scanState.sorted);
|
|
551
|
-
if (outcome.action === "save") {
|
|
552
|
-
writeBaseline(projectArg ?? ".", scanState.sorted);
|
|
553
|
-
const count = scanState.sorted.length;
|
|
554
|
-
console.log(chalk.green(`✓ Baseline saved to .cve-lite/baseline.json with ${count} ${count === 1 ? "finding" : "findings"}. Future scans will only report findings above this baseline.`));
|
|
555
|
-
if (options.checkOverrides) {
|
|
556
|
-
console.log(chalk.gray(`Note: override hygiene (--check-overrides) is not part of the ratchet baseline; run \`${OVERRIDES_COMMAND}\` to audit overrides.`));
|
|
557
|
-
}
|
|
558
|
-
auditLogHandle.emit({
|
|
559
|
-
ts: new Date().toISOString(),
|
|
560
|
-
type: "scan.finished",
|
|
561
|
-
schemaVersion: 1,
|
|
562
|
-
durationMs: Date.now() - scanStartTime,
|
|
563
|
-
findingsCount: scanState.sorted.length,
|
|
564
|
-
exitCode: 0,
|
|
565
|
-
});
|
|
566
|
-
auditLogHandle.close();
|
|
567
|
-
process.exit(0);
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
const { newFindings, suppressedCount } = outcome;
|
|
571
|
-
const suppressedLabel = `${suppressedCount} existing ${suppressedCount === 1 ? "finding" : "findings"} suppressed`;
|
|
572
|
-
if (newFindings.length === 0) {
|
|
573
|
-
console.log(chalk.green(`No new findings above baseline - ${suppressedLabel}`));
|
|
574
|
-
auditLogHandle.emit({
|
|
575
|
-
ts: new Date().toISOString(),
|
|
576
|
-
type: "scan.finished",
|
|
577
|
-
schemaVersion: 1,
|
|
578
|
-
durationMs: Date.now() - scanStartTime,
|
|
579
|
-
findingsCount: scanState.sorted.length,
|
|
580
|
-
exitCode: 0,
|
|
581
|
-
});
|
|
582
|
-
auditLogHandle.close();
|
|
583
|
-
process.exit(0);
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
console.log(chalk.red(`${newFindings.length} new ${newFindings.length === 1 ? "finding" : "findings"} above baseline - ${suppressedLabel}`));
|
|
587
|
-
for (const f of newFindings) {
|
|
588
|
-
const ids = f.vulnerabilities.map(v => v.id).join(", ");
|
|
589
|
-
console.log(` ${chalk.yellow(f.severity)} ${f.pkg.name}@${f.pkg.version}${ids ? ` (${ids})` : ""}`);
|
|
590
|
-
}
|
|
591
|
-
console.log(chalk.gray("To accept these, re-baseline intentionally by deleting .cve-lite/baseline.json and re-running --ratchet."));
|
|
592
|
-
auditLogHandle.emit({
|
|
593
|
-
ts: new Date().toISOString(),
|
|
594
|
-
type: "scan.finished",
|
|
595
|
-
schemaVersion: 1,
|
|
596
|
-
durationMs: Date.now() - scanStartTime,
|
|
597
|
-
findingsCount: newFindings.length,
|
|
598
|
-
exitCode: 1,
|
|
599
|
-
});
|
|
600
|
-
auditLogHandle.close();
|
|
601
|
-
process.exit(1);
|
|
602
|
-
return;
|
|
603
|
-
}
|
|
604
|
-
// auto-apply baseline if it exists - filter before output
|
|
605
|
-
if (baseline) {
|
|
606
|
-
const filtered = filterNewFindings(scanState.sorted, baseline);
|
|
607
|
-
scanState.sorted = filtered.newFindings;
|
|
608
|
-
scanState.tableFindings = scanState.tableFindings.filter(f => filtered.newFindings.some(nf => nf.pkg.name === f.pkg.name && nf.pkg.version === f.pkg.version));
|
|
609
|
-
suppressedCount = filtered.suppressedCount;
|
|
610
|
-
}
|
|
611
|
-
// Maintenance risk findings are derived from CVE findings (via
|
|
612
|
-
// recommendedParentUpgrade), so they must be computed from the same
|
|
613
|
-
// baseline-filtered set everything below uses (JSON, rendering,
|
|
614
|
-
// --fail-on). Computing this earlier - before the baseline filter above -
|
|
615
|
-
// let a DM001 finding on an already-baselined CVE keep failing
|
|
616
|
-
// --fail-on forever, even as printFinalStatus reported a clean scan.
|
|
617
|
-
// This point is unreached in --ratchet mode (which always exits above
|
|
618
|
-
// via process.exit), so packument fetches never run wastefully there.
|
|
619
|
-
if (options.checkMaintenance) {
|
|
620
|
-
const directNames = readDirectDependencyNames(projectPath, !!options.prodOnly);
|
|
621
|
-
const directDependencies = scanState.allPackages.filter(p => directNames?.has(p.name));
|
|
622
|
-
maintenanceFindings = await detectDM001(scanState.sorted, directDependencies, !!options.offline || !!options.offlineDb);
|
|
623
|
-
}
|
|
624
|
-
if (options.checkLicenses) {
|
|
625
|
-
const directNames = readDirectDependencyNames(projectPath, !!options.prodOnly);
|
|
626
|
-
const directDeps = scanState.allPackages.filter(p => directNames?.has(p.name));
|
|
627
|
-
const licenseResult = await detectLicenseIssues({
|
|
628
|
-
lockfilePath: scanInput.filePath,
|
|
629
|
-
directDeps,
|
|
630
|
-
isNpm: scanInput.source === "package-lock" || scanInput.source === "npm-shrinkwrap",
|
|
631
|
-
isOffline: !!options.offline || !!options.offlineDb,
|
|
632
|
-
});
|
|
633
|
-
licenseFindings = licenseResult.findings;
|
|
634
|
-
licenseLimitedToDirectOnly = licenseResult.limitedToDirectOnly;
|
|
635
|
-
}
|
|
636
|
-
await writeOutputs(options, {
|
|
637
|
-
sorted: scanState.sorted,
|
|
638
|
-
allPackages: scanState.allPackages,
|
|
639
|
-
suggestedFixCommands: scanState.suggestedFixCommands,
|
|
640
|
-
coverage: scanState.coverage,
|
|
641
|
-
minSeverity: scanState.minSeverity,
|
|
642
|
-
tableFindings: scanState.tableFindings,
|
|
643
|
-
completeness: scanState.completeness,
|
|
644
|
-
overrideFindings,
|
|
645
|
-
maintenanceFindings,
|
|
646
|
-
licenseFindings,
|
|
647
|
-
licenseLimitedToDirectOnly,
|
|
648
|
-
}, scanInput, projectPath);
|
|
649
|
-
if (!(options.json || options.sarif || options.sbom) || options.verbose) {
|
|
650
|
-
const offline = !!options.offline || !!options.offlineDb;
|
|
651
|
-
const showOverrideHint = !options.checkOverrides && !options.ratchet && hasOverrideEntries(projectPath);
|
|
652
|
-
if (options.verbose) {
|
|
653
|
-
const overrideCount = options.checkOverrides ? overrideFindings.length : 0;
|
|
654
|
-
printSummary(scanState.sorted, packages.length, scanInput);
|
|
655
|
-
const pmLabel = scanState.suggestedFixCommands
|
|
656
|
-
? `${chalk.cyan(scanState.suggestedFixCommands.packageManager)} ${chalk.gray(`(${scanState.suggestedFixCommands.sourceLabel})`)}`
|
|
657
|
-
: undefined;
|
|
658
|
-
printActionSummary(scanState.sorted, overrideCount, pmLabel);
|
|
659
|
-
printSuggestedFixCommands(scanState.sorted, scanInput, { offline, overrideCount });
|
|
660
|
-
printSuggestedFixCommandSkips(scanState.sorted, scanInput, { offline });
|
|
661
|
-
if (scanInput.skippedDependencies.length > 0) {
|
|
662
|
-
printSkippedDependencies(scanInput.skippedDependencies);
|
|
663
|
-
}
|
|
664
|
-
if (scanState.sorted.length > 0) {
|
|
665
|
-
if (scanState.tableFindings.length > 0) {
|
|
666
|
-
const skippedKeys = new Set((scanState.suggestedFixCommands?.skipped ?? []).map(s => `${s.package}@${s.version}`));
|
|
667
|
-
printTable(scanState.tableFindings, options.all ? null : scanState.minSeverity, skippedKeys);
|
|
668
|
-
}
|
|
669
|
-
else {
|
|
670
|
-
logInfo(`No findings met the table threshold of ${scanState.minSeverity}. Re-run with --all to show everything.`, options);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
if (options.checkOverrides && overrideFindings.length > 0) {
|
|
674
|
-
console.log("\n" + renderOverrideFindings(overrideFindings, { verbose: true, projectPath }));
|
|
675
|
-
}
|
|
676
|
-
if (options.checkMaintenance && maintenanceFindings.length > 0) {
|
|
677
|
-
console.log("\n" + renderMaintenanceFindings(maintenanceFindings, { verbose: true }));
|
|
678
|
-
}
|
|
679
|
-
if (options.checkLicenses) {
|
|
680
|
-
console.log("\n" + renderLicenseFindings(licenseFindings, { limitedToDirectOnly: licenseLimitedToDirectOnly }));
|
|
681
|
-
}
|
|
682
|
-
printCoverage([...scanInput.notes, ...scanState.coverage]);
|
|
683
|
-
printFinalStatus(scanState.sorted, overrideCount, scanState.completeness);
|
|
684
|
-
if (showOverrideHint)
|
|
685
|
-
printOverrideHint();
|
|
686
|
-
}
|
|
687
|
-
else {
|
|
688
|
-
const compactPmLabel = scanState.suggestedFixCommands
|
|
689
|
-
? `${chalk.cyan(scanState.suggestedFixCommands.packageManager)} ${chalk.gray(`(${scanState.suggestedFixCommands.sourceLabel})`)}`
|
|
690
|
-
: undefined;
|
|
691
|
-
printCompactOutput(scanState.sorted, scanInput, {
|
|
692
|
-
offline,
|
|
693
|
-
all: !!options.all,
|
|
694
|
-
packageManager: compactPmLabel,
|
|
695
|
-
completeness: scanState.completeness,
|
|
696
|
-
licenseFindings: options.checkLicenses ? licenseFindings : undefined,
|
|
697
|
-
licenseLimitedToDirectOnly: options.checkLicenses ? licenseLimitedToDirectOnly : undefined,
|
|
698
|
-
});
|
|
699
|
-
if (options.checkOverrides) {
|
|
700
|
-
console.log("\n" + renderOverrideFindings(overrideFindings, { verbose: false, projectPath }));
|
|
701
|
-
}
|
|
702
|
-
if (options.checkMaintenance && maintenanceFindings.length > 0) {
|
|
703
|
-
console.log("\n" + renderMaintenanceFindings(maintenanceFindings, { verbose: false }));
|
|
704
|
-
}
|
|
705
|
-
if (showOverrideHint)
|
|
706
|
-
printOverrideHint();
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
if (options.report) {
|
|
711
|
-
const outputDir = path.resolve(typeof options.report === "string" ? options.report : "./cve-report");
|
|
712
|
-
const reportData = buildReportData({
|
|
713
|
-
projectPath,
|
|
714
|
-
cliVersion,
|
|
715
|
-
packageManager: scanInput.source,
|
|
716
|
-
lockfileSource: scanInput.filePath ? path.basename(scanInput.filePath) : scanInput.source,
|
|
717
|
-
packageCount: packages.length,
|
|
718
|
-
findings: scanState.sorted,
|
|
719
|
-
suggestedFixCommands: scanState.suggestedFixCommands,
|
|
720
|
-
notes: [...scanInput.notes, ...scanState.coverage],
|
|
721
|
-
warnings: scanInput.warnings,
|
|
722
|
-
skippedDependencies: scanInput.skippedDependencies,
|
|
723
|
-
// undefined (not []) when override checking was not requested, so the HTML
|
|
724
|
-
// report omits the Override hygiene panel entirely on a plain scan.
|
|
725
|
-
overrideFindings: options.checkOverrides ? overrideFindings : undefined,
|
|
726
|
-
// Same undefined-vs-[] convention as overrideFindings above.
|
|
727
|
-
maintenanceFindings: options.checkMaintenance ? maintenanceFindings : undefined,
|
|
728
|
-
licenseFindings: options.checkLicenses ? licenseFindings : undefined,
|
|
729
|
-
licenseLimitedToDirectOnly: options.checkLicenses ? licenseLimitedToDirectOnly : undefined,
|
|
730
|
-
completeness: scanState.completeness,
|
|
731
|
-
});
|
|
732
|
-
const { reportPath } = await writeHtmlReport({
|
|
733
|
-
outputDir,
|
|
734
|
-
data: reportData,
|
|
735
|
-
autoOpen: !options.noOpen,
|
|
736
|
-
});
|
|
737
|
-
console.log(`${chalk.gray("Report:")} ${chalk.cyan(reportPath)}`);
|
|
738
|
-
}
|
|
739
|
-
debugLog("Scan finished", {
|
|
740
|
-
totalDurationMs: Date.now() - scanStartedAt,
|
|
741
|
-
findings: scanState.sorted.length,
|
|
742
|
-
packages: packages.length,
|
|
743
|
-
});
|
|
744
|
-
if (baseline) {
|
|
745
|
-
if (scanState.sorted.length === 0) {
|
|
746
|
-
console.log(chalk.green(`No new findings above baseline - ${suppressedCount} existing ${suppressedCount === 1 ? "finding" : "findings"} suppressed`));
|
|
747
|
-
}
|
|
748
|
-
else {
|
|
749
|
-
console.log(chalk.yellow(`${scanState.sorted.length} new ${scanState.sorted.length === 1 ? "finding" : "findings"} above baseline - ${suppressedCount} existing ${suppressedCount === 1 ? "finding" : "findings"} suppressed`));
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
// Override hygiene findings count toward --fail-on too, using the shared
|
|
753
|
-
// reachesFailOn helper from src/utils/severity.ts, the same logic used by
|
|
754
|
-
// the standalone `overrides` command. Without this, a CI run
|
|
755
|
-
// of `cve-lite . --check-overrides --fail-on high` would exit 0 despite high-severity
|
|
756
|
-
// override findings, giving a false sense of protection. overrideFindings is empty
|
|
757
|
-
// unless --check-overrides (and non-ratchet), so this is a no-op otherwise.
|
|
758
|
-
const shouldFail = reachesFailOn(scanState.sorted, options.failOn) ||
|
|
759
|
-
reachesFailOn(overrideFindings, options.failOn) ||
|
|
760
|
-
reachesFailOn(maintenanceFindings, options.failOn);
|
|
761
|
-
// In fix mode, remaining transitive findings cannot be auto-fixed.
|
|
762
|
-
// Exiting non-zero would prevent the Action PR step from running.
|
|
763
|
-
const incompleteFailure = shouldFailForIncompleteScan(scanState.completeness, options.incompletePolicy);
|
|
764
|
-
const exitCode = incompleteFailure
|
|
765
|
-
? EXIT_ERROR
|
|
766
|
-
: shouldFail && !options.fix
|
|
767
|
-
? 1
|
|
768
|
-
: 0;
|
|
769
|
-
// Emit scan.finished event and close audit-log
|
|
770
|
-
auditLogHandle.emit({
|
|
771
|
-
ts: new Date().toISOString(),
|
|
772
|
-
type: "scan.finished",
|
|
773
|
-
schemaVersion: 1,
|
|
774
|
-
durationMs: Date.now() - scanStartTime,
|
|
775
|
-
findingsCount: scanState.sorted.length + overrideFindings.length,
|
|
776
|
-
exitCode,
|
|
144
|
+
auditLog: auditLogHandle,
|
|
145
|
+
scanStartedAt,
|
|
146
|
+
cliVersion,
|
|
777
147
|
});
|
|
778
148
|
auditLogHandle.close();
|
|
779
149
|
process.exit(exitCode);
|
|
@@ -795,72 +165,8 @@ if (parsedArgs) {
|
|
|
795
165
|
stack: error instanceof Error ? error.stack : undefined,
|
|
796
166
|
});
|
|
797
167
|
auditLogHandle.close();
|
|
798
|
-
formatHintLines(getNetworkErrorHint(error, errorMessage))
|
|
799
|
-
.forEach(line => console.error(line));
|
|
168
|
+
formatHintLines(getNetworkErrorHint(error, errorMessage)).forEach((line) => console.error(line));
|
|
800
169
|
process.exit(1);
|
|
801
170
|
});
|
|
802
171
|
}
|
|
803
172
|
}
|
|
804
|
-
async function scanProject(params) {
|
|
805
|
-
const directDependencyNames = readDirectDependencyNames(params.projectPath, !!params.options.prodOnly);
|
|
806
|
-
const { findings, completeness } = await scanPackages(params.scanInput.packages, params.batchSize, params.options, {
|
|
807
|
-
directDependencyNames,
|
|
808
|
-
scanSource: params.scanInput.source,
|
|
809
|
-
scanFilePath: params.scanInput.filePath,
|
|
810
|
-
}, params.debugLog, params.fetchImpl);
|
|
811
|
-
if (params.options.usage) {
|
|
812
|
-
logInfo(`Scanning project source for usage hints...`, params.options);
|
|
813
|
-
const usageStartedAt = Date.now();
|
|
814
|
-
const pkgNames = new Set(findings.map(f => f.pkg.name));
|
|
815
|
-
const usageData = scanProjectForPackageUsage(params.projectPath, pkgNames);
|
|
816
|
-
let matchedPackages = 0;
|
|
817
|
-
for (const finding of findings) {
|
|
818
|
-
const files = usageData[finding.pkg.name];
|
|
819
|
-
if (files) {
|
|
820
|
-
if (files.length > 0) {
|
|
821
|
-
matchedPackages += 1;
|
|
822
|
-
}
|
|
823
|
-
finding.usage = {
|
|
824
|
-
imported: files.length > 0,
|
|
825
|
-
files,
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
if (params.options.debug) {
|
|
830
|
-
params.debugLog("Usage scan", {
|
|
831
|
-
durationMs: Date.now() - usageStartedAt,
|
|
832
|
-
packagesChecked: pkgNames.size,
|
|
833
|
-
matchedPackages,
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
let finalFindings = findings;
|
|
838
|
-
if (params.options.onlyUsed) {
|
|
839
|
-
const beforeCount = finalFindings.length;
|
|
840
|
-
finalFindings = finalFindings.filter(f => f.usage?.imported);
|
|
841
|
-
if (params.options.debug) {
|
|
842
|
-
params.debugLog("Findings filtered", {
|
|
843
|
-
reason: "only-used",
|
|
844
|
-
before: beforeCount,
|
|
845
|
-
after: finalFindings.length,
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
const offline = !!params.options.offline || !!params.options.offlineDb;
|
|
850
|
-
const sorted = sortFindingsForOutput(finalFindings);
|
|
851
|
-
const coverage = buildCoverageNotes(params.scanInput, offline);
|
|
852
|
-
const minSeverity = normalizeSeverity(params.options.minSeverity || "medium");
|
|
853
|
-
const tableFindings = params.options.all
|
|
854
|
-
? sorted
|
|
855
|
-
: selectFindingsForTable(sorted, minSeverity);
|
|
856
|
-
const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, params.scanInput, { offline });
|
|
857
|
-
return {
|
|
858
|
-
sorted,
|
|
859
|
-
coverage,
|
|
860
|
-
minSeverity,
|
|
861
|
-
tableFindings,
|
|
862
|
-
suggestedFixCommands,
|
|
863
|
-
allPackages: params.scanInput.packages,
|
|
864
|
-
completeness,
|
|
865
|
-
};
|
|
866
|
-
}
|