cve-lite-cli 1.27.0 → 1.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -3
- package/dist/advisory/osv-advisory-source.js +5 -3
- package/dist/cli/advisories-init.js +24 -0
- package/dist/cli/args.js +30 -0
- package/dist/cli/help.js +6 -2
- package/dist/cli/validate.js +6 -0
- package/dist/constants.js +1 -0
- package/dist/index.js +67 -7
- package/dist/maintenance/dm001-maintenance-risk.js +122 -0
- package/dist/maintenance/score.js +51 -0
- package/dist/maintenance/types.js +1 -0
- package/dist/osv/cache.js +49 -50
- package/dist/output/formatters.js +10 -4
- package/dist/output/html-reporter.js +163 -14
- package/dist/output/maintenance-findings-html.js +60 -0
- package/dist/output/maintenance-findings-json.js +3 -0
- package/dist/output/maintenance-findings-sarif.js +58 -0
- package/dist/output/maintenance-terminal.js +138 -0
- package/dist/output/multi-folder-html-reporter.js +61 -5
- package/dist/output/multi-folder-printer.js +11 -2
- package/dist/output/override-findings-html.js +22 -32
- package/dist/output/printers.js +95 -22
- package/dist/output/sarif.js +23 -7
- package/dist/output/spinner.js +5 -0
- package/dist/output/write-outputs.js +7 -2
- package/dist/parsers/bun-lock.js +47 -7
- package/dist/parsers/npm-lock-graph.js +90 -12
- package/dist/parsers/pnpm-lock.js +42 -6
- package/dist/parsers/utils.js +0 -15
- package/dist/parsers/yarn-lock.js +140 -58
- package/dist/remediation/cooldown.js +74 -0
- package/dist/remediation/fix-commands.js +42 -2
- package/dist/remediation/npm-registry.js +70 -42
- package/dist/remediation/parent-upgrade.js +114 -18
- package/dist/scan/completeness.js +49 -0
- package/dist/scan/multi-folder-scan.js +193 -13
- package/dist/scanner.js +284 -165
- package/dist/usage/scanner.js +12 -2
- package/dist/utils/network.js +66 -0
- package/dist/utils/vuln.js +16 -0
- package/package.json +2 -2
package/dist/scanner.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { chunk,
|
|
1
|
+
import { chunk, runWithConcurrency } from "./utils/array.js";
|
|
2
2
|
import { isPrivateRegistrySource, isGitSource, hasCommitShaPinning } from "./utils/advisory.js";
|
|
3
|
+
import { extractCveAliases, hasMaliciousAdvisory } from "./utils/vuln.js";
|
|
3
4
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "./utils/version.js";
|
|
4
5
|
import { loadCache, saveCache, isEntryStale } from "./osv/cache.js";
|
|
5
6
|
import { maxSeverity } from "./osv/severity.js";
|
|
@@ -9,7 +10,7 @@ import { LocalAdvisorySource } from "./advisory/local-advisory-source.js";
|
|
|
9
10
|
import { LocalAdvisoryDatabase } from "./advisory/local-db.js";
|
|
10
11
|
import { ADVISORY_DB_STALE_AFTER_MS, getDefaultAdvisoryDbPath } from "./advisory/osv-sync.js";
|
|
11
12
|
import { resolveRecommendedParentUpgrade } from "./remediation/parent-upgrade.js";
|
|
12
|
-
import { configureNpmRegistryDebug, fetchPackument, resolveLowestKnownNonVulnerableVersion, resolvePublishedFixVersion, } from "./remediation/npm-registry.js";
|
|
13
|
+
import { configureNpmRegistryDebug, fetchPackument, resolveLowestKnownNonVulnerableVersion, resolvePublishedFixVersion, runWithObserver, } from "./remediation/npm-registry.js";
|
|
13
14
|
import { countBySeverity } from "./utils/severity.js";
|
|
14
15
|
import { resolveNpmTransitiveRemediation, resolveTransitiveRemediationViaRegistry } from "./remediation/npm-transitive-resolution.js";
|
|
15
16
|
import { resolveChainFix } from "./remediation/transitive-chain-resolver.js";
|
|
@@ -18,6 +19,9 @@ import { buildPnpmWorkspaceMap } from "./parsers/pnpm-lock.js";
|
|
|
18
19
|
import { buildNpmWorkspaceMap } from "./parsers/package-lock.js";
|
|
19
20
|
import { buildBunWorkspaceMap } from "./parsers/bun-lock.js";
|
|
20
21
|
import { pluralize } from "./utils/string.js";
|
|
22
|
+
import { extractErrorMessage } from "./utils/network.js";
|
|
23
|
+
import { logWarn } from "./output/formatters.js";
|
|
24
|
+
import { formatDiagnosticMessage } from "./scan/completeness.js";
|
|
21
25
|
export function createAdvisorySource(options) {
|
|
22
26
|
const offline = !!options?.offline || !!options?.offlineDb;
|
|
23
27
|
if (offline) {
|
|
@@ -33,7 +37,7 @@ export function createAdvisorySource(options) {
|
|
|
33
37
|
};
|
|
34
38
|
}
|
|
35
39
|
return {
|
|
36
|
-
advisorySource: new OsvAdvisorySource(options?.osvUrl, options?.debugLog),
|
|
40
|
+
advisorySource: new OsvAdvisorySource(options?.osvUrl, options?.debugLog, options?.fetchImpl),
|
|
37
41
|
offline: false,
|
|
38
42
|
sourceLabel: options?.osvUrl
|
|
39
43
|
? `custom OSV endpoint (${options.osvUrl})`
|
|
@@ -57,13 +61,22 @@ function inferPackageManagerForChain(source) {
|
|
|
57
61
|
return "bun";
|
|
58
62
|
return null;
|
|
59
63
|
}
|
|
60
|
-
|
|
64
|
+
function isTransientFailure(error) {
|
|
65
|
+
if (!(error instanceof Error))
|
|
66
|
+
return true;
|
|
67
|
+
const msg = error.message;
|
|
68
|
+
if (msg.includes(" 404 ") || msg.includes(" 410 "))
|
|
69
|
+
return false;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
export async function scanPackages(packages, batchSize, options, context, debugLog, fetchImpl) {
|
|
61
73
|
const log = debugLog ?? (() => { });
|
|
62
74
|
const sourceContext = createAdvisorySource({
|
|
63
75
|
osvUrl: options.osvUrl,
|
|
64
76
|
offline: options.offline,
|
|
65
77
|
offlineDb: options.offlineDb,
|
|
66
78
|
debugLog: log,
|
|
79
|
+
fetchImpl,
|
|
67
80
|
});
|
|
68
81
|
const offline = sourceContext.offline;
|
|
69
82
|
const cacheDirOverride = options.cacheDir;
|
|
@@ -151,42 +164,64 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
151
164
|
}
|
|
152
165
|
const idSet = new Set(results.flatMap(r => r.vulnIds));
|
|
153
166
|
const vulnMap = new Map();
|
|
167
|
+
const transientDetailIds = new Set();
|
|
168
|
+
const offlineMissingDetailIds = new Set();
|
|
169
|
+
const confirmedMissingDetailIds = new Set();
|
|
154
170
|
if (idSet.size > 0 && !offline) {
|
|
155
171
|
const ids = [...idSet];
|
|
156
172
|
const detailSpinner = createSpinner("Fetching vulnerability details...", options);
|
|
157
173
|
try {
|
|
158
|
-
|
|
159
|
-
// 30-minute staleness check applied earlier in this function), detail records have no
|
|
160
|
-
// expiry — they are considered valid for the lifetime of the cache file. The check below
|
|
161
|
-
// is therefore a simple presence check, not a staleness check. This is intentional and
|
|
162
|
-
// matches the original behaviour. Fetches run concurrently because there is no ordering
|
|
163
|
-
// dependency between CVE ID detail requests.
|
|
174
|
+
const nowMs = Date.now();
|
|
164
175
|
const uncachedIds = [];
|
|
165
176
|
for (const id of ids) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (cached)
|
|
169
|
-
vulnMap.set(id, cached);
|
|
177
|
+
const cached = cache.entries[id];
|
|
178
|
+
if (cached && !isEntryStale(cached, nowMs)) {
|
|
179
|
+
if (cached.vuln) {
|
|
180
|
+
vulnMap.set(id, cached.vuln);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// Negative cache hit: the record was confirmed missing earlier.
|
|
184
|
+
// The detail is still unresolved, so the scan stays incomplete.
|
|
185
|
+
confirmedMissingDetailIds.add(id);
|
|
186
|
+
}
|
|
170
187
|
}
|
|
171
188
|
else {
|
|
172
189
|
uncachedIds.push(id);
|
|
173
190
|
}
|
|
174
191
|
}
|
|
175
|
-
// Fetch all uncached IDs concurrently
|
|
176
192
|
if (uncachedIds.length > 0) {
|
|
177
193
|
detailSpinner.update(`Fetching ${uncachedIds.length} vulnerability details...`);
|
|
194
|
+
const cachedAt = new Date().toISOString();
|
|
178
195
|
await runWithConcurrency(uncachedIds, 10, async (id) => {
|
|
179
196
|
try {
|
|
180
197
|
const detail = await advisorySource.getVuln(id);
|
|
181
198
|
vulnMap.set(id, detail);
|
|
182
|
-
cache.entries[id] = detail;
|
|
199
|
+
cache.entries[id] = { vuln: detail, cachedAt };
|
|
183
200
|
}
|
|
184
|
-
catch {
|
|
185
|
-
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (isTransientFailure(error)) {
|
|
203
|
+
transientDetailIds.add(id);
|
|
204
|
+
log("OSV detail transient failure", {
|
|
205
|
+
advisoryId: id,
|
|
206
|
+
error: extractErrorMessage(error),
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
confirmedMissingDetailIds.add(id);
|
|
211
|
+
cache.entries[id] = { vuln: null, cachedAt };
|
|
212
|
+
log("OSV detail confirmed missing", { advisoryId: id });
|
|
213
|
+
}
|
|
186
214
|
}
|
|
187
215
|
});
|
|
188
216
|
}
|
|
189
|
-
|
|
217
|
+
const successCount = ids.filter(id => vulnMap.has(id)).length;
|
|
218
|
+
const failureCount = ids.length - successCount;
|
|
219
|
+
if (failureCount > 0) {
|
|
220
|
+
detailSpinner.warn(`Loaded ${successCount}/${ids.length} vulnerability detail ${pluralize(ids.length, "record")} (${failureCount} ${pluralize(failureCount, "failure")})`);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
detailSpinner.succeed(`Loaded ${ids.length} vulnerability detail ${pluralize(ids.length, "record")}`);
|
|
224
|
+
}
|
|
190
225
|
}
|
|
191
226
|
catch (error) {
|
|
192
227
|
detailSpinner.fail("Failed while fetching vulnerability details");
|
|
@@ -203,10 +238,17 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
203
238
|
vulnMap.set(id, detail);
|
|
204
239
|
}
|
|
205
240
|
catch {
|
|
206
|
-
|
|
241
|
+
offlineMissingDetailIds.add(id);
|
|
207
242
|
}
|
|
208
243
|
});
|
|
209
|
-
|
|
244
|
+
const successCount = ids.filter(id => vulnMap.has(id)).length;
|
|
245
|
+
const failureCount = ids.length - successCount;
|
|
246
|
+
if (failureCount > 0) {
|
|
247
|
+
detailSpinner.warn(`Loaded ${successCount}/${ids.length} local advisory detail ${pluralize(ids.length, "record")} (${failureCount} ${pluralize(failureCount, "missing")})`);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
detailSpinner.succeed(`Loaded ${ids.length} local advisory detail ${pluralize(ids.length, "record")}`);
|
|
251
|
+
}
|
|
210
252
|
}
|
|
211
253
|
catch (error) {
|
|
212
254
|
detailSpinner.fail("Failed while loading local advisory details");
|
|
@@ -220,8 +262,9 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
220
262
|
const vulnerabilities = result.vulnIds
|
|
221
263
|
.map(id => vulnMap.get(id))
|
|
222
264
|
.filter((v) => Boolean(v));
|
|
265
|
+
const unresolvedIds = result.vulnIds.filter(id => !vulnMap.has(id));
|
|
223
266
|
const severity = maxSeverity(vulnerabilities);
|
|
224
|
-
const cveAliases =
|
|
267
|
+
const cveAliases = extractCveAliases(vulnerabilities);
|
|
225
268
|
const dependencyPaths = result.pkg.paths ?? [];
|
|
226
269
|
const relationship = classifyRelationship(dependencyPaths, result.pkg.name, context?.directDependencyNames);
|
|
227
270
|
const firstFixedVersion = findFirstFixedVersion(vulnerabilities);
|
|
@@ -240,10 +283,34 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
240
283
|
validatedTargetKnownVulnerableVersions: null,
|
|
241
284
|
recommendedParentUpgrade: undefined,
|
|
242
285
|
recommendedNpmTransitiveRemediation: undefined,
|
|
286
|
+
...(unresolvedIds.length > 0 ? { unresolvedAdvisoryIds: unresolvedIds } : {}),
|
|
243
287
|
};
|
|
244
288
|
});
|
|
289
|
+
const unresolvedDetailIds = idSet.size > 0
|
|
290
|
+
? [...idSet].filter(id => !vulnMap.has(id))
|
|
291
|
+
: [];
|
|
292
|
+
if (unresolvedDetailIds.length > 0) {
|
|
293
|
+
const transientCount = unresolvedDetailIds.filter(id => transientDetailIds.has(id)).length;
|
|
294
|
+
const offlineCount = unresolvedDetailIds.filter(id => offlineMissingDetailIds.has(id)).length;
|
|
295
|
+
const confirmedCount = unresolvedDetailIds.filter(id => confirmedMissingDetailIds.has(id)).length;
|
|
296
|
+
const otherCount = unresolvedDetailIds.length - transientCount - offlineCount - confirmedCount;
|
|
297
|
+
const parts = [];
|
|
298
|
+
if (transientCount > 0) {
|
|
299
|
+
parts.push(`${transientCount} from transient failures — re-run to retry`);
|
|
300
|
+
}
|
|
301
|
+
if (offlineCount > 0) {
|
|
302
|
+
parts.push(`${offlineCount} missing from local advisory database — refresh to sync`);
|
|
303
|
+
}
|
|
304
|
+
if (confirmedCount > 0) {
|
|
305
|
+
parts.push(`${confirmedCount} confirmed missing from the OSV API`);
|
|
306
|
+
}
|
|
307
|
+
if (otherCount > 0) {
|
|
308
|
+
parts.push(`${otherCount} could not be resolved`);
|
|
309
|
+
}
|
|
310
|
+
logWarn(`⚠ ${unresolvedDetailIds.length} advisory detail ${pluralize(unresolvedDetailIds.length, "lookup")} missing from findings. ${parts.join("; ")}.`, { json: options.json });
|
|
311
|
+
}
|
|
245
312
|
for (const finding of findings) {
|
|
246
|
-
if (finding.vulnerabilities
|
|
313
|
+
if (hasMaliciousAdvisory(finding.vulnerabilities)) {
|
|
247
314
|
if (isGitSource(finding.pkg)) {
|
|
248
315
|
finding.maliciousGitSource = true;
|
|
249
316
|
finding.maliciousGitSourcePinned = hasCommitShaPinning(finding.pkg);
|
|
@@ -308,167 +375,184 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
308
375
|
log("Workspace map", { type: "bun", workspaces: bunWorkspaceMap.size });
|
|
309
376
|
}
|
|
310
377
|
const lockfileWorkspaceMap = pnpmWorkspaceMap ?? bunWorkspaceMap ?? null;
|
|
311
|
-
const
|
|
312
|
-
const
|
|
313
|
-
|
|
378
|
+
const packumentFailures = new Set();
|
|
379
|
+
const remediationFailures = new Map();
|
|
380
|
+
let chainResolutionFailureCount = 0;
|
|
314
381
|
let directCount = 0;
|
|
315
382
|
let transitiveCount = 0;
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
383
|
+
await runWithObserver({
|
|
384
|
+
onTransientFailure(name) { packumentFailures.add(name); },
|
|
385
|
+
}, async () => {
|
|
386
|
+
const npmRemediationCache = new Map();
|
|
387
|
+
const parentUpgradeCache = new Map();
|
|
388
|
+
const directValidationCount = offline ? 0 : findings.length;
|
|
389
|
+
for (const finding of findings) {
|
|
390
|
+
if (finding.relationship === "direct")
|
|
391
|
+
directCount++;
|
|
392
|
+
else if (finding.relationship === "transitive")
|
|
393
|
+
transitiveCount++;
|
|
394
|
+
}
|
|
395
|
+
const transitiveRemediationCount = transitiveCount;
|
|
396
|
+
const analysisStepCount = directValidationCount + transitiveRemediationCount;
|
|
397
|
+
if (analysisStepCount > 0) {
|
|
398
|
+
const analysisSpinner = createSpinner("Analyzing vulnerability findings...", options);
|
|
399
|
+
let completedSteps = 0;
|
|
400
|
+
const updateAnalysisProgress = (phase, subject) => {
|
|
401
|
+
completedSteps += 1;
|
|
402
|
+
analysisSpinner.update(`Analyzing vulnerability findings ${completedSteps}/${analysisStepCount}: ${phase} ${subject}...`);
|
|
403
|
+
};
|
|
404
|
+
try {
|
|
405
|
+
if (!offline) {
|
|
406
|
+
const npmVersionCacheUpdated = await validateDirectFixTargets(findings, (finding) => {
|
|
407
|
+
updateAnalysisProgress("validating fix target for", `${finding.pkg.name}@${finding.pkg.version}`);
|
|
408
|
+
}, { cache, noCache: options.noCache, debugLog: log });
|
|
409
|
+
if (npmVersionCacheUpdated) {
|
|
410
|
+
saveCache(cache, cacheDirOverride, options.debug ? log : undefined);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
// Pre-warm packument cache for all packages needed in the remediation loop.
|
|
414
|
+
// This converts N sequential registry round-trips into one concurrent burst,
|
|
415
|
+
// after which the loop runs entirely from the in-memory packument cache.
|
|
416
|
+
if (!offline) {
|
|
417
|
+
const packumentsToPrewarm = new Set();
|
|
418
|
+
for (const finding of findings) {
|
|
419
|
+
if (finding.relationship !== "transitive")
|
|
420
|
+
continue;
|
|
421
|
+
packumentsToPrewarm.add(finding.pkg.name);
|
|
422
|
+
const paths = finding.dependencyPaths;
|
|
423
|
+
if (paths.length > 0 && paths[0].length >= 2) {
|
|
424
|
+
packumentsToPrewarm.add(paths[0][paths[0].length - 2]);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (packumentsToPrewarm.size > 0) {
|
|
428
|
+
await runWithConcurrency([...packumentsToPrewarm], 8, async (name) => {
|
|
429
|
+
await fetchPackument(name);
|
|
430
|
+
});
|
|
431
|
+
}
|
|
338
432
|
}
|
|
339
|
-
}
|
|
340
|
-
// Pre-warm packument cache for all packages needed in the remediation loop.
|
|
341
|
-
// This converts N sequential registry round-trips into one concurrent burst,
|
|
342
|
-
// after which the loop runs entirely from the in-memory packument cache.
|
|
343
|
-
if (!offline) {
|
|
344
|
-
const packumentsToPrewarm = new Set();
|
|
345
433
|
for (const finding of findings) {
|
|
346
434
|
if (finding.relationship !== "transitive")
|
|
347
435
|
continue;
|
|
348
|
-
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
await runWithConcurrency([...packumentsToPrewarm], 8, async (name) => {
|
|
356
|
-
try {
|
|
357
|
-
await fetchPackument(name);
|
|
358
|
-
}
|
|
359
|
-
catch { /* loop will handle missing packuments */ }
|
|
436
|
+
updateAnalysisProgress("resolving remediation for", `${finding.pkg.name}@${finding.pkg.version}`);
|
|
437
|
+
const remediationCacheKey = JSON.stringify({
|
|
438
|
+
package: finding.pkg.name,
|
|
439
|
+
version: finding.pkg.version,
|
|
440
|
+
dependencyPaths: finding.dependencyPaths,
|
|
441
|
+
firstFixedVersion: finding.firstFixedVersion,
|
|
442
|
+
validatedFirstFixedVersion: finding.validatedFirstFixedVersion ?? null,
|
|
360
443
|
});
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
395
|
-
targetVersion: finding.recommendedNpmTransitiveRemediation.targetVersion ?? "",
|
|
396
|
-
viaPath: finding.recommendedNpmTransitiveRemediation.viaPath,
|
|
397
|
-
vulnerablePackage: finding.pkg.name,
|
|
398
|
-
confidence: "exact-direct-child",
|
|
399
|
-
reason: finding.recommendedNpmTransitiveRemediation.reason,
|
|
400
|
-
};
|
|
401
|
-
continue;
|
|
444
|
+
try {
|
|
445
|
+
if (npmTransitiveGraph) {
|
|
446
|
+
if (npmRemediationCache.has(remediationCacheKey)) {
|
|
447
|
+
finding.recommendedNpmTransitiveRemediation =
|
|
448
|
+
npmRemediationCache.get(remediationCacheKey) ?? undefined;
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
finding.recommendedNpmTransitiveRemediation = await resolveNpmTransitiveRemediation({
|
|
452
|
+
finding,
|
|
453
|
+
graph: npmTransitiveGraph,
|
|
454
|
+
packages,
|
|
455
|
+
directDependencyNames: context?.directDependencyNames,
|
|
456
|
+
offline,
|
|
457
|
+
workspaceMap: npmWorkspaceMap,
|
|
458
|
+
});
|
|
459
|
+
npmRemediationCache.set(remediationCacheKey, finding.recommendedNpmTransitiveRemediation ?? null);
|
|
460
|
+
}
|
|
461
|
+
if (finding.recommendedNpmTransitiveRemediation?.kind === "upgrade-parent-to-version") {
|
|
462
|
+
finding.recommendedParentUpgrade = {
|
|
463
|
+
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
464
|
+
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
465
|
+
targetVersion: finding.recommendedNpmTransitiveRemediation.targetVersion ?? "",
|
|
466
|
+
viaPath: finding.recommendedNpmTransitiveRemediation.viaPath,
|
|
467
|
+
vulnerablePackage: finding.pkg.name,
|
|
468
|
+
confidence: "verified",
|
|
469
|
+
reason: finding.recommendedNpmTransitiveRemediation.reason,
|
|
470
|
+
};
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
474
|
+
finding.recommendedParentUpgrade = undefined;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
402
477
|
}
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
|
|
478
|
+
if (!offline && !npmTransitiveGraph) {
|
|
479
|
+
if (npmRemediationCache.has(remediationCacheKey)) {
|
|
480
|
+
finding.recommendedNpmTransitiveRemediation =
|
|
481
|
+
npmRemediationCache.get(remediationCacheKey) ?? undefined;
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
finding.recommendedNpmTransitiveRemediation = await resolveTransitiveRemediationViaRegistry({
|
|
485
|
+
finding,
|
|
486
|
+
packages,
|
|
487
|
+
directDependencyNames: context?.directDependencyNames,
|
|
488
|
+
workspaceMap: lockfileWorkspaceMap,
|
|
489
|
+
});
|
|
490
|
+
npmRemediationCache.set(remediationCacheKey, finding.recommendedNpmTransitiveRemediation ?? null);
|
|
491
|
+
}
|
|
492
|
+
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
493
|
+
finding.recommendedParentUpgrade = undefined;
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
406
496
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
if (npmRemediationCache.has(remediationCacheKey)) {
|
|
410
|
-
finding.recommendedNpmTransitiveRemediation =
|
|
411
|
-
npmRemediationCache.get(remediationCacheKey) ?? undefined;
|
|
497
|
+
if (parentUpgradeCache.has(remediationCacheKey)) {
|
|
498
|
+
finding.recommendedParentUpgrade = parentUpgradeCache.get(remediationCacheKey) ?? undefined;
|
|
412
499
|
}
|
|
413
500
|
else {
|
|
414
|
-
finding.
|
|
415
|
-
|
|
416
|
-
packages,
|
|
417
|
-
directDependencyNames: context?.directDependencyNames,
|
|
418
|
-
workspaceMap: lockfileWorkspaceMap,
|
|
419
|
-
});
|
|
420
|
-
npmRemediationCache.set(remediationCacheKey, finding.recommendedNpmTransitiveRemediation ?? null);
|
|
501
|
+
finding.recommendedParentUpgrade = await resolveRecommendedParentUpgrade(finding, packages, context?.directDependencyNames, { offline });
|
|
502
|
+
parentUpgradeCache.set(remediationCacheKey, finding.recommendedParentUpgrade ?? null);
|
|
421
503
|
}
|
|
422
|
-
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
423
|
-
finding.recommendedParentUpgrade = undefined;
|
|
424
|
-
continue;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
if (parentUpgradeCache.has(remediationCacheKey)) {
|
|
428
|
-
finding.recommendedParentUpgrade = parentUpgradeCache.get(remediationCacheKey) ?? undefined;
|
|
429
504
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
505
|
+
catch (error) {
|
|
506
|
+
const packageName = finding.pkg.name;
|
|
507
|
+
remediationFailures.set(packageName, (remediationFailures.get(packageName) ?? 0) + 1);
|
|
508
|
+
log("Remediation failed", {
|
|
509
|
+
package: packageName,
|
|
510
|
+
version: finding.pkg.version,
|
|
511
|
+
error: error instanceof Error ? error.message : String(error),
|
|
512
|
+
});
|
|
513
|
+
finding.recommendedNpmTransitiveRemediation = undefined;
|
|
514
|
+
finding.recommendedParentUpgrade = undefined;
|
|
433
515
|
}
|
|
434
516
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
517
|
+
analysisSpinner.succeed("Analyzed vulnerability findings");
|
|
518
|
+
// Chain fix resolution: pre-compute validated chain for transitive findings
|
|
519
|
+
const chainPm = inferPackageManagerForChain(context?.scanSource);
|
|
520
|
+
if (chainPm) {
|
|
521
|
+
const installedVersions = new Map(packages.map(p => [p.name, p.version]));
|
|
522
|
+
await Promise.all(findings
|
|
523
|
+
.filter(f => f.relationship === "transitive" && f.dependencyPaths?.length)
|
|
524
|
+
.map(async (finding) => {
|
|
525
|
+
try {
|
|
526
|
+
finding.chainResolution = await resolveChainFix(finding, installedVersions, chainPm, { offline });
|
|
527
|
+
}
|
|
528
|
+
catch (error) {
|
|
529
|
+
chainResolutionFailureCount += 1;
|
|
530
|
+
log("Chain resolution failed", {
|
|
531
|
+
package: finding.pkg.name,
|
|
532
|
+
version: finding.pkg.version,
|
|
533
|
+
error: error instanceof Error ? error.message : String(error),
|
|
534
|
+
});
|
|
535
|
+
finding.chainResolution = null;
|
|
536
|
+
}
|
|
537
|
+
}));
|
|
438
538
|
}
|
|
439
539
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (chainPm) {
|
|
444
|
-
const installedVersions = new Map(packages.map(p => [p.name, p.version]));
|
|
445
|
-
await Promise.all(findings
|
|
446
|
-
.filter(f => f.relationship === "transitive" && f.dependencyPaths?.length)
|
|
447
|
-
.map(async (finding) => {
|
|
448
|
-
try {
|
|
449
|
-
finding.chainResolution = await resolveChainFix(finding, installedVersions, chainPm, { offline });
|
|
450
|
-
}
|
|
451
|
-
catch {
|
|
452
|
-
finding.chainResolution = null;
|
|
453
|
-
}
|
|
454
|
-
}));
|
|
540
|
+
catch (error) {
|
|
541
|
+
analysisSpinner.fail("Failed while analyzing vulnerability findings");
|
|
542
|
+
throw error;
|
|
455
543
|
}
|
|
456
544
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
debugLog: log,
|
|
467
|
-
});
|
|
468
|
-
if (npmVersionCacheUpdated) {
|
|
469
|
-
saveCache(cache, cacheDirOverride, options.debug ? log : undefined);
|
|
545
|
+
else if (!offline) {
|
|
546
|
+
const npmVersionCacheUpdated = await validateDirectFixTargets(findings, undefined, {
|
|
547
|
+
cache,
|
|
548
|
+
noCache: options.noCache,
|
|
549
|
+
debugLog: log,
|
|
550
|
+
});
|
|
551
|
+
if (npmVersionCacheUpdated) {
|
|
552
|
+
saveCache(cache, cacheDirOverride, options.debug ? log : undefined);
|
|
553
|
+
}
|
|
470
554
|
}
|
|
471
|
-
}
|
|
555
|
+
});
|
|
472
556
|
const severityCounts = countBySeverity(findings);
|
|
473
557
|
log("Findings classified", {
|
|
474
558
|
total: findings.length,
|
|
@@ -480,7 +564,19 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
480
564
|
low: severityCounts.low,
|
|
481
565
|
unknown: severityCounts.unknown,
|
|
482
566
|
});
|
|
483
|
-
|
|
567
|
+
const diagnostics = buildCompletenessDiagnostics({
|
|
568
|
+
transientDetailIds,
|
|
569
|
+
offlineMissingDetailIds,
|
|
570
|
+
confirmedMissingDetailIds,
|
|
571
|
+
packumentFailures,
|
|
572
|
+
remediationFailures,
|
|
573
|
+
chainResolutionFailureCount,
|
|
574
|
+
});
|
|
575
|
+
const completeness = {
|
|
576
|
+
complete: diagnostics.length === 0,
|
|
577
|
+
diagnostics,
|
|
578
|
+
};
|
|
579
|
+
return { findings, completeness };
|
|
484
580
|
}
|
|
485
581
|
catch (error) {
|
|
486
582
|
spinner.fail("Scan failed");
|
|
@@ -649,6 +745,29 @@ function findFirstFixedVersion(vulns) {
|
|
|
649
745
|
return null;
|
|
650
746
|
return fixedVersions.sort(compareVersions)[0];
|
|
651
747
|
}
|
|
748
|
+
function buildCompletenessDiagnostics(params) {
|
|
749
|
+
const diagnostics = [];
|
|
750
|
+
function addDiagnostic(code, count, impact, affectedPackageCount) {
|
|
751
|
+
if (count === 0)
|
|
752
|
+
return;
|
|
753
|
+
diagnostics.push({
|
|
754
|
+
code,
|
|
755
|
+
severity: "warning",
|
|
756
|
+
message: formatDiagnosticMessage(code, count, affectedPackageCount),
|
|
757
|
+
impact,
|
|
758
|
+
count,
|
|
759
|
+
...(affectedPackageCount === undefined ? {} : { affectedPackageCount }),
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
const remediationTotal = [...params.remediationFailures.values()].reduce((sum, c) => sum + c, 0);
|
|
763
|
+
addDiagnostic("OSV_DETAIL_TRANSIENT_FAILURE", params.transientDetailIds.size, "detection");
|
|
764
|
+
addDiagnostic("OSV_DETAIL_OFFLINE_MISSING", params.offlineMissingDetailIds.size, "detection");
|
|
765
|
+
addDiagnostic("OSV_DETAIL_CONFIRMED_MISSING", params.confirmedMissingDetailIds.size, "detection");
|
|
766
|
+
addDiagnostic("PACKUMENT_FETCH_FAILURE", params.packumentFailures.size, "remediation");
|
|
767
|
+
addDiagnostic("REMEDIATION_FAILURE", remediationTotal, "remediation", params.remediationFailures.size);
|
|
768
|
+
addDiagnostic("CHAIN_RESOLUTION_FAILURE", params.chainResolutionFailureCount, "remediation");
|
|
769
|
+
return diagnostics;
|
|
770
|
+
}
|
|
652
771
|
export function buildCoverageNotes(scanInput, offline) {
|
|
653
772
|
const notes = [
|
|
654
773
|
"CVE Lite CLI checks package versions against OSV advisories. It does not prove exploitability or runtime reachability.",
|
package/dist/usage/scanner.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
// Shared with lockfile scanning in utils/file.ts; additions affect both code paths.
|
|
4
3
|
import { EXCLUDED_DIRS } from "../constants.js";
|
|
5
4
|
const ALLOWED_EXTS = new Set([".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"]);
|
|
6
5
|
const MAX_FILES_TO_SCAN = 5000;
|
|
6
|
+
const ALL_IMPORTS_EXCLUDED_DIRS = new Set([
|
|
7
|
+
...EXCLUDED_DIRS,
|
|
8
|
+
"__fixtures__",
|
|
9
|
+
"__tests__",
|
|
10
|
+
"example",
|
|
11
|
+
"examples",
|
|
12
|
+
"fixture",
|
|
13
|
+
"fixtures",
|
|
14
|
+
"test",
|
|
15
|
+
"tests",
|
|
16
|
+
]);
|
|
7
17
|
// Matches:
|
|
8
18
|
// import { foo } from 'pkg'
|
|
9
19
|
// import * as foo from "pkg"
|
|
@@ -116,7 +126,7 @@ export function scanAllImports(projectPath) {
|
|
|
116
126
|
return;
|
|
117
127
|
const fullPath = path.join(dir, entry.name);
|
|
118
128
|
if (entry.isDirectory()) {
|
|
119
|
-
if (!
|
|
129
|
+
if (!ALL_IMPORTS_EXCLUDED_DIRS.has(entry.name) && !entry.name.startsWith(".")) {
|
|
120
130
|
walk(fullPath);
|
|
121
131
|
}
|
|
122
132
|
}
|