cve-lite-cli 1.28.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 +28 -3
- package/dist/cli/validate.js +6 -0
- package/dist/index.js +21 -5
- package/dist/maintenance/dm001-maintenance-risk.js +74 -15
- package/dist/maintenance/score.js +51 -0
- package/dist/output/formatters.js +2 -1
- package/dist/output/html-reporter.js +115 -2
- package/dist/output/maintenance-findings-html.js +4 -0
- package/dist/output/maintenance-findings-sarif.js +58 -0
- package/dist/output/maintenance-terminal.js +63 -5
- package/dist/output/multi-folder-html-reporter.js +61 -5
- package/dist/output/multi-folder-printer.js +11 -2
- package/dist/output/printers.js +76 -16
- package/dist/output/sarif.js +23 -7
- package/dist/output/write-outputs.js +4 -1
- 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/npm-registry.js +69 -52
- package/dist/scan/completeness.js +49 -0
- package/dist/scan/multi-folder-scan.js +167 -14
- package/dist/scanner.js +210 -155
- package/dist/usage/scanner.js +12 -2
- 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";
|
|
@@ -20,6 +21,7 @@ import { buildBunWorkspaceMap } from "./parsers/bun-lock.js";
|
|
|
20
21
|
import { pluralize } from "./utils/string.js";
|
|
21
22
|
import { extractErrorMessage } from "./utils/network.js";
|
|
22
23
|
import { logWarn } from "./output/formatters.js";
|
|
24
|
+
import { formatDiagnosticMessage } from "./scan/completeness.js";
|
|
23
25
|
export function createAdvisorySource(options) {
|
|
24
26
|
const offline = !!options?.offline || !!options?.offlineDb;
|
|
25
27
|
if (offline) {
|
|
@@ -164,6 +166,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
164
166
|
const vulnMap = new Map();
|
|
165
167
|
const transientDetailIds = new Set();
|
|
166
168
|
const offlineMissingDetailIds = new Set();
|
|
169
|
+
const confirmedMissingDetailIds = new Set();
|
|
167
170
|
if (idSet.size > 0 && !offline) {
|
|
168
171
|
const ids = [...idSet];
|
|
169
172
|
const detailSpinner = createSpinner("Fetching vulnerability details...", options);
|
|
@@ -176,6 +179,11 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
176
179
|
if (cached.vuln) {
|
|
177
180
|
vulnMap.set(id, cached.vuln);
|
|
178
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
|
+
}
|
|
179
187
|
}
|
|
180
188
|
else {
|
|
181
189
|
uncachedIds.push(id);
|
|
@@ -199,6 +207,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
199
207
|
});
|
|
200
208
|
}
|
|
201
209
|
else {
|
|
210
|
+
confirmedMissingDetailIds.add(id);
|
|
202
211
|
cache.entries[id] = { vuln: null, cachedAt };
|
|
203
212
|
log("OSV detail confirmed missing", { advisoryId: id });
|
|
204
213
|
}
|
|
@@ -255,7 +264,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
255
264
|
.filter((v) => Boolean(v));
|
|
256
265
|
const unresolvedIds = result.vulnIds.filter(id => !vulnMap.has(id));
|
|
257
266
|
const severity = maxSeverity(vulnerabilities);
|
|
258
|
-
const cveAliases =
|
|
267
|
+
const cveAliases = extractCveAliases(vulnerabilities);
|
|
259
268
|
const dependencyPaths = result.pkg.paths ?? [];
|
|
260
269
|
const relationship = classifyRelationship(dependencyPaths, result.pkg.name, context?.directDependencyNames);
|
|
261
270
|
const firstFixedVersion = findFirstFixedVersion(vulnerabilities);
|
|
@@ -283,7 +292,8 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
283
292
|
if (unresolvedDetailIds.length > 0) {
|
|
284
293
|
const transientCount = unresolvedDetailIds.filter(id => transientDetailIds.has(id)).length;
|
|
285
294
|
const offlineCount = unresolvedDetailIds.filter(id => offlineMissingDetailIds.has(id)).length;
|
|
286
|
-
const
|
|
295
|
+
const confirmedCount = unresolvedDetailIds.filter(id => confirmedMissingDetailIds.has(id)).length;
|
|
296
|
+
const otherCount = unresolvedDetailIds.length - transientCount - offlineCount - confirmedCount;
|
|
287
297
|
const parts = [];
|
|
288
298
|
if (transientCount > 0) {
|
|
289
299
|
parts.push(`${transientCount} from transient failures — re-run to retry`);
|
|
@@ -291,13 +301,16 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
291
301
|
if (offlineCount > 0) {
|
|
292
302
|
parts.push(`${offlineCount} missing from local advisory database — refresh to sync`);
|
|
293
303
|
}
|
|
304
|
+
if (confirmedCount > 0) {
|
|
305
|
+
parts.push(`${confirmedCount} confirmed missing from the OSV API`);
|
|
306
|
+
}
|
|
294
307
|
if (otherCount > 0) {
|
|
295
308
|
parts.push(`${otherCount} could not be resolved`);
|
|
296
309
|
}
|
|
297
310
|
logWarn(`⚠ ${unresolvedDetailIds.length} advisory detail ${pluralize(unresolvedDetailIds.length, "lookup")} missing from findings. ${parts.join("; ")}.`, { json: options.json });
|
|
298
311
|
}
|
|
299
312
|
for (const finding of findings) {
|
|
300
|
-
if (finding.vulnerabilities
|
|
313
|
+
if (hasMaliciousAdvisory(finding.vulnerabilities)) {
|
|
301
314
|
if (isGitSource(finding.pkg)) {
|
|
302
315
|
finding.maliciousGitSource = true;
|
|
303
316
|
finding.maliciousGitSourcePinned = hasCommitShaPinning(finding.pkg);
|
|
@@ -362,177 +375,184 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
362
375
|
log("Workspace map", { type: "bun", workspaces: bunWorkspaceMap.size });
|
|
363
376
|
}
|
|
364
377
|
const lockfileWorkspaceMap = pnpmWorkspaceMap ?? bunWorkspaceMap ?? null;
|
|
365
|
-
const
|
|
366
|
-
const
|
|
367
|
-
|
|
378
|
+
const packumentFailures = new Set();
|
|
379
|
+
const remediationFailures = new Map();
|
|
380
|
+
let chainResolutionFailureCount = 0;
|
|
368
381
|
let directCount = 0;
|
|
369
382
|
let transitiveCount = 0;
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
const packumentsToPrewarm = new Set();
|
|
399
|
-
for (const finding of findings) {
|
|
400
|
-
if (finding.relationship !== "transitive")
|
|
401
|
-
continue;
|
|
402
|
-
packumentsToPrewarm.add(finding.pkg.name);
|
|
403
|
-
const paths = finding.dependencyPaths;
|
|
404
|
-
if (paths.length > 0 && paths[0].length >= 2) {
|
|
405
|
-
packumentsToPrewarm.add(paths[0][paths[0].length - 2]);
|
|
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);
|
|
406
411
|
}
|
|
407
412
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
for (const finding of findings) {
|
|
418
|
-
if (finding.relationship !== "transitive")
|
|
419
|
-
continue;
|
|
420
|
-
updateAnalysisProgress("resolving remediation for", `${finding.pkg.name}@${finding.pkg.version}`);
|
|
421
|
-
const remediationCacheKey = JSON.stringify({
|
|
422
|
-
package: finding.pkg.name,
|
|
423
|
-
version: finding.pkg.version,
|
|
424
|
-
dependencyPaths: finding.dependencyPaths,
|
|
425
|
-
firstFixedVersion: finding.firstFixedVersion,
|
|
426
|
-
validatedFirstFixedVersion: finding.validatedFirstFixedVersion ?? null,
|
|
427
|
-
});
|
|
428
|
-
try {
|
|
429
|
-
if (npmTransitiveGraph) {
|
|
430
|
-
if (npmRemediationCache.has(remediationCacheKey)) {
|
|
431
|
-
finding.recommendedNpmTransitiveRemediation =
|
|
432
|
-
npmRemediationCache.get(remediationCacheKey) ?? undefined;
|
|
433
|
-
}
|
|
434
|
-
else {
|
|
435
|
-
finding.recommendedNpmTransitiveRemediation = await resolveNpmTransitiveRemediation({
|
|
436
|
-
finding,
|
|
437
|
-
graph: npmTransitiveGraph,
|
|
438
|
-
packages,
|
|
439
|
-
directDependencyNames: context?.directDependencyNames,
|
|
440
|
-
offline,
|
|
441
|
-
workspaceMap: npmWorkspaceMap,
|
|
442
|
-
});
|
|
443
|
-
npmRemediationCache.set(remediationCacheKey, finding.recommendedNpmTransitiveRemediation ?? null);
|
|
444
|
-
}
|
|
445
|
-
if (finding.recommendedNpmTransitiveRemediation?.kind === "upgrade-parent-to-version") {
|
|
446
|
-
finding.recommendedParentUpgrade = {
|
|
447
|
-
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
448
|
-
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
449
|
-
targetVersion: finding.recommendedNpmTransitiveRemediation.targetVersion ?? "",
|
|
450
|
-
viaPath: finding.recommendedNpmTransitiveRemediation.viaPath,
|
|
451
|
-
vulnerablePackage: finding.pkg.name,
|
|
452
|
-
confidence: "verified",
|
|
453
|
-
reason: finding.recommendedNpmTransitiveRemediation.reason,
|
|
454
|
-
};
|
|
455
|
-
continue;
|
|
456
|
-
}
|
|
457
|
-
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
458
|
-
finding.recommendedParentUpgrade = undefined;
|
|
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")
|
|
459
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]);
|
|
460
425
|
}
|
|
461
426
|
}
|
|
462
|
-
if (
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
}
|
|
467
|
-
else {
|
|
468
|
-
finding.recommendedNpmTransitiveRemediation = await resolveTransitiveRemediationViaRegistry({
|
|
469
|
-
finding,
|
|
470
|
-
packages,
|
|
471
|
-
directDependencyNames: context?.directDependencyNames,
|
|
472
|
-
workspaceMap: lockfileWorkspaceMap,
|
|
473
|
-
});
|
|
474
|
-
npmRemediationCache.set(remediationCacheKey, finding.recommendedNpmTransitiveRemediation ?? null);
|
|
475
|
-
}
|
|
476
|
-
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
477
|
-
finding.recommendedParentUpgrade = undefined;
|
|
478
|
-
continue;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
if (parentUpgradeCache.has(remediationCacheKey)) {
|
|
482
|
-
finding.recommendedParentUpgrade = parentUpgradeCache.get(remediationCacheKey) ?? undefined;
|
|
483
|
-
}
|
|
484
|
-
else {
|
|
485
|
-
finding.recommendedParentUpgrade = await resolveRecommendedParentUpgrade(finding, packages, context?.directDependencyNames, { offline });
|
|
486
|
-
parentUpgradeCache.set(remediationCacheKey, finding.recommendedParentUpgrade ?? null);
|
|
427
|
+
if (packumentsToPrewarm.size > 0) {
|
|
428
|
+
await runWithConcurrency([...packumentsToPrewarm], 8, async (name) => {
|
|
429
|
+
await fetchPackument(name);
|
|
430
|
+
});
|
|
487
431
|
}
|
|
488
432
|
}
|
|
489
|
-
|
|
490
|
-
|
|
433
|
+
for (const finding of findings) {
|
|
434
|
+
if (finding.relationship !== "transitive")
|
|
435
|
+
continue;
|
|
436
|
+
updateAnalysisProgress("resolving remediation for", `${finding.pkg.name}@${finding.pkg.version}`);
|
|
437
|
+
const remediationCacheKey = JSON.stringify({
|
|
491
438
|
package: finding.pkg.name,
|
|
492
439
|
version: finding.pkg.version,
|
|
493
|
-
|
|
440
|
+
dependencyPaths: finding.dependencyPaths,
|
|
441
|
+
firstFixedVersion: finding.firstFixedVersion,
|
|
442
|
+
validatedFirstFixedVersion: finding.validatedFirstFixedVersion ?? null,
|
|
494
443
|
});
|
|
495
|
-
finding.recommendedNpmTransitiveRemediation = undefined;
|
|
496
|
-
finding.recommendedParentUpgrade = undefined;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
analysisSpinner.succeed("Analyzed vulnerability findings");
|
|
500
|
-
// Chain fix resolution: pre-compute validated chain for transitive findings
|
|
501
|
-
const chainPm = inferPackageManagerForChain(context?.scanSource);
|
|
502
|
-
if (chainPm) {
|
|
503
|
-
const installedVersions = new Map(packages.map(p => [p.name, p.version]));
|
|
504
|
-
await Promise.all(findings
|
|
505
|
-
.filter(f => f.relationship === "transitive" && f.dependencyPaths?.length)
|
|
506
|
-
.map(async (finding) => {
|
|
507
444
|
try {
|
|
508
|
-
|
|
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
|
+
}
|
|
477
|
+
}
|
|
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
|
+
}
|
|
496
|
+
}
|
|
497
|
+
if (parentUpgradeCache.has(remediationCacheKey)) {
|
|
498
|
+
finding.recommendedParentUpgrade = parentUpgradeCache.get(remediationCacheKey) ?? undefined;
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
finding.recommendedParentUpgrade = await resolveRecommendedParentUpgrade(finding, packages, context?.directDependencyNames, { offline });
|
|
502
|
+
parentUpgradeCache.set(remediationCacheKey, finding.recommendedParentUpgrade ?? null);
|
|
503
|
+
}
|
|
509
504
|
}
|
|
510
505
|
catch (error) {
|
|
511
|
-
|
|
512
|
-
|
|
506
|
+
const packageName = finding.pkg.name;
|
|
507
|
+
remediationFailures.set(packageName, (remediationFailures.get(packageName) ?? 0) + 1);
|
|
508
|
+
log("Remediation failed", {
|
|
509
|
+
package: packageName,
|
|
513
510
|
version: finding.pkg.version,
|
|
514
511
|
error: error instanceof Error ? error.message : String(error),
|
|
515
512
|
});
|
|
516
|
-
finding.
|
|
513
|
+
finding.recommendedNpmTransitiveRemediation = undefined;
|
|
514
|
+
finding.recommendedParentUpgrade = undefined;
|
|
517
515
|
}
|
|
518
|
-
}
|
|
516
|
+
}
|
|
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
|
+
}));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
analysisSpinner.fail("Failed while analyzing vulnerability findings");
|
|
542
|
+
throw error;
|
|
519
543
|
}
|
|
520
544
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
debugLog: log,
|
|
531
|
-
});
|
|
532
|
-
if (npmVersionCacheUpdated) {
|
|
533
|
-
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
|
+
}
|
|
534
554
|
}
|
|
535
|
-
}
|
|
555
|
+
});
|
|
536
556
|
const severityCounts = countBySeverity(findings);
|
|
537
557
|
log("Findings classified", {
|
|
538
558
|
total: findings.length,
|
|
@@ -544,7 +564,19 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
544
564
|
low: severityCounts.low,
|
|
545
565
|
unknown: severityCounts.unknown,
|
|
546
566
|
});
|
|
547
|
-
|
|
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 };
|
|
548
580
|
}
|
|
549
581
|
catch (error) {
|
|
550
582
|
spinner.fail("Scan failed");
|
|
@@ -713,6 +745,29 @@ function findFirstFixedVersion(vulns) {
|
|
|
713
745
|
return null;
|
|
714
746
|
return fixedVersions.sort(compareVersions)[0];
|
|
715
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
|
+
}
|
|
716
771
|
export function buildCoverageNotes(scanInput, offline) {
|
|
717
772
|
const notes = [
|
|
718
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
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { unique } from "./array.js";
|
|
2
|
+
// MAL-* is the OSV prefix for malicious code advisories. Guarded because OSV
|
|
3
|
+
// records are external data - the declared `string` type on OsvVuln.id does
|
|
4
|
+
// not guarantee a malformed advisory record cannot have a missing/non-string id.
|
|
5
|
+
export function isMaliciousVulnId(id) {
|
|
6
|
+
return typeof id === "string" && id.startsWith("MAL-");
|
|
7
|
+
}
|
|
8
|
+
export function hasMaliciousAdvisory(vulns) {
|
|
9
|
+
return vulns.some(v => isMaliciousVulnId(v.id));
|
|
10
|
+
}
|
|
11
|
+
// Guards against non-string alias elements from malformed OSV records - a
|
|
12
|
+
// malformed record with a null/undefined/non-string entry in `aliases` must
|
|
13
|
+
// not abort the whole scan.
|
|
14
|
+
export function extractCveAliases(vulns) {
|
|
15
|
+
return unique(vulns.flatMap(v => (v.aliases ?? []).filter((a) => typeof a === "string" && a.startsWith("CVE-"))));
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cve-lite-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.29.0",
|
|
4
4
|
"description": "Developer-friendly CLI for scanning JS/TS projects for dependency vulnerabilities using local lockfiles and OSV",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@types/better-sqlite3": "^7.6.13",
|
|
29
29
|
"@types/jest": "^30.0.0",
|
|
30
30
|
"@types/node": "^24.0.0",
|
|
31
|
-
"jest": "^30.4.
|
|
31
|
+
"jest": "^30.4.2",
|
|
32
32
|
"ts-jest": "^29.4.9",
|
|
33
33
|
"tsx": "^4.22.0",
|
|
34
34
|
"typescript": "^5.8.2"
|