cve-lite-cli 1.36.0 → 1.37.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 +6 -3
- package/dist/advisory/local-db.js +22 -3
- package/dist/advisory/npm-advisory-source.js +70 -13
- package/dist/audit-log/events.js +14 -0
- package/dist/cli/args.js +8 -2
- package/dist/cli/help.js +2 -0
- package/dist/cli/validate.js +3 -0
- package/dist/epss/client.js +20 -9
- package/dist/output/cyclonedx.js +6 -3
- package/dist/output/html-reporter.js +7 -3
- package/dist/output/output-dir.js +20 -0
- package/dist/output/printers.js +18 -4
- package/dist/output/sarif.js +10 -4
- package/dist/output/sbom-file.js +6 -4
- package/dist/output/spdx.js +2 -2
- package/dist/output/write-outputs.js +7 -5
- package/dist/overrides/detectors/oa008-materialized.js +3 -2
- package/dist/remediation/fix-commands.js +89 -31
- package/dist/remediation/npm-registry.js +108 -1
- package/dist/remediation/parent-update-child-note.js +11 -0
- package/dist/scan/multi-folder-scan.js +3 -2
- package/dist/scan/single-scan.js +7 -11
- package/dist/scanner.js +89 -45
- package/dist/utils/create-pr.js +21 -2
- package/dist/utils/fix-runner.js +15 -2
- package/dist/utils/version.js +68 -78
- package/package.json +3 -1
- package/scripts/pr-scan-delta.mjs +7 -4
|
@@ -89,7 +89,15 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
89
89
|
// validatedFirstFixedVersion is "did not validate" rather than "validation
|
|
90
90
|
// failed" — fall back to the advisory hint instead of dropping the target.
|
|
91
91
|
const validatedFieldOk = offline || !hasValidatedField || finding.validatedFirstFixedVersion !== null;
|
|
92
|
-
|
|
92
|
+
// A confirmed fix version is a direct answer to "is there a safe upgrade",
|
|
93
|
+
// where the counter comparison below is only an inference about one. When
|
|
94
|
+
// the two disagree the confirmed version wins, because reporting a dead
|
|
95
|
+
// end in the same scan that names the fix is the worse failure. This also
|
|
96
|
+
// stops the rule depending on two counters that separate passes maintain
|
|
97
|
+
// (#1213).
|
|
98
|
+
const hasConfirmedFix = finding.validatedFirstFixedVersion != null;
|
|
99
|
+
const allVersionsVulnerable = !hasConfirmedFix &&
|
|
100
|
+
finding.validatedTargetScannedVersions != null &&
|
|
93
101
|
finding.validatedTargetKnownVulnerableVersions != null &&
|
|
94
102
|
finding.validatedTargetScannedVersions > 0 &&
|
|
95
103
|
finding.validatedTargetKnownVulnerableVersions >= finding.validatedTargetScannedVersions;
|
|
@@ -98,7 +106,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
98
106
|
package: finding.pkg.name,
|
|
99
107
|
version: finding.pkg.version,
|
|
100
108
|
relationship: finding.relationship,
|
|
101
|
-
reason: `No safe upgrade: all ${finding.validatedTargetScannedVersions} scanned ${pluralize(finding.validatedTargetScannedVersions ?? 0, "version")} are still known-vulnerable. This package may be unmaintained.`,
|
|
109
|
+
reason: `No safe upgrade: all ${finding.validatedTargetScannedVersions} scanned ${pluralize(finding.validatedTargetScannedVersions ?? 0, "version")} ${pluralize(finding.validatedTargetScannedVersions ?? 0, "is", "are")} still known-vulnerable. This package may be unmaintained.`,
|
|
102
110
|
});
|
|
103
111
|
continue;
|
|
104
112
|
}
|
|
@@ -171,22 +179,14 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
171
179
|
if (packageManager === "npm" &&
|
|
172
180
|
finding.relationship === "transitive" &&
|
|
173
181
|
finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
174
|
-
upsertTarget(targetsByKey, finding, {
|
|
182
|
+
upsertTarget(targetsByKey, finding, parentUpdateTarget(finding, urgent, {
|
|
175
183
|
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
176
184
|
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
177
|
-
|
|
178
|
-
scannedVersions: null,
|
|
179
|
-
knownVulnerableVersions: null,
|
|
180
|
-
kind: "parent-update",
|
|
181
|
-
urgent,
|
|
182
|
-
severity: finding.severity,
|
|
183
|
-
adjusted: false,
|
|
184
|
-
adjustmentNote: null,
|
|
185
|
+
childTargetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
|
|
185
186
|
reason: finding.recommendedNpmTransitiveRemediation.reason,
|
|
186
187
|
command: buildNpmUpdateCommand(finding.recommendedNpmTransitiveRemediation.package, finding.recommendedNpmTransitiveRemediation.workspaces),
|
|
187
|
-
usage: finding.usage ?? null,
|
|
188
188
|
isDev: devLookup.get(`${finding.recommendedNpmTransitiveRemediation.package}@${finding.recommendedNpmTransitiveRemediation.currentVersion}`) ?? false,
|
|
189
|
-
});
|
|
189
|
+
}));
|
|
190
190
|
continue;
|
|
191
191
|
}
|
|
192
192
|
if (packageManager === "npm" &&
|
|
@@ -273,21 +273,13 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
273
273
|
: packageManager === "yarn"
|
|
274
274
|
? `yarn upgrade ${finding.pkg.name}`
|
|
275
275
|
: `bun update ${finding.pkg.name}`;
|
|
276
|
-
upsertTarget(targetsByKey, finding, {
|
|
276
|
+
upsertTarget(targetsByKey, finding, parentUpdateTarget(finding, urgent, {
|
|
277
277
|
package: finding.pkg.name,
|
|
278
278
|
currentVersion: finding.pkg.version,
|
|
279
|
-
|
|
280
|
-
scannedVersions: null,
|
|
281
|
-
knownVulnerableVersions: null,
|
|
282
|
-
kind: "parent-update",
|
|
283
|
-
urgent,
|
|
284
|
-
severity: finding.severity,
|
|
285
|
-
adjusted: false,
|
|
286
|
-
adjustmentNote: null,
|
|
279
|
+
childTargetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
|
|
287
280
|
reason: `${finding.pkg.name}@${finding.pkg.version} can be refreshed to ${finding.recommendedNpmTransitiveRemediation.targetChildVersion}+ — no parent upgrade needed.`,
|
|
288
281
|
command: lockfileRefreshCommand,
|
|
289
|
-
|
|
290
|
-
});
|
|
282
|
+
}));
|
|
291
283
|
continue;
|
|
292
284
|
}
|
|
293
285
|
const primaryParent = getPrimaryParent(finding);
|
|
@@ -456,9 +448,20 @@ function devFlag(packageManager) {
|
|
|
456
448
|
export function findFixTargetForFinding(plan, finding) {
|
|
457
449
|
const target = plan.targets.find(item => {
|
|
458
450
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
451
|
+
const rem = finding.recommendedNpmTransitiveRemediation;
|
|
452
|
+
if (item.kind !== "parent-update")
|
|
453
|
+
return false;
|
|
454
|
+
if (item.package !== rem.package && item.package !== finding.pkg.name)
|
|
455
|
+
return false;
|
|
456
|
+
// Parent-named parent-update: match only on child identity. Falling
|
|
457
|
+
// through to targetVersion compares the parent's version to the child's
|
|
458
|
+
// destination and can attach the wrong sibling.
|
|
459
|
+
if (item.childPackage) {
|
|
460
|
+
return item.childPackage === finding.pkg.name
|
|
461
|
+
&& item.childTargetVersion === rem.targetChildVersion;
|
|
462
|
+
}
|
|
463
|
+
// Self-refresh / lockfile refresh: destination stays on targetVersion.
|
|
464
|
+
return item.targetVersion === rem.targetChildVersion;
|
|
462
465
|
}
|
|
463
466
|
if (finding.recommendedParentUpgrade) {
|
|
464
467
|
if (item.package !== finding.recommendedParentUpgrade.package)
|
|
@@ -535,10 +538,11 @@ function packageManagerSourceLabel(scanInput) {
|
|
|
535
538
|
// Install targets (direct / parent-upgrade) all mean "install <package>@<targetVersion>",
|
|
536
539
|
// so findings that land on the same package merge into one target and the higher
|
|
537
540
|
// version wins. A parent-update target means something else: "refresh <vulnerable
|
|
538
|
-
// child> within <package>'s declared range"
|
|
539
|
-
// version
|
|
540
|
-
//
|
|
541
|
-
//
|
|
541
|
+
// child> within <package>'s declared range". Its targetVersion is <package>'s own
|
|
542
|
+
// version (unchanged); the child's identity lives on childPackage / childTargetVersion
|
|
543
|
+
// when package is the parent. Merging it with an install target for the same package
|
|
544
|
+
// used to compare versions of two different packages, and the child's version could
|
|
545
|
+
// end up pinned onto the parent (`npm install axios@4.0.6`, where 4.0.6 is form-data's
|
|
542
546
|
// version - #1007). Keep parent-update targets in their own keyspace, per child, so
|
|
543
547
|
// they only ever merge with a refresh of the same child through the same package.
|
|
544
548
|
function targetKey(finding, target) {
|
|
@@ -546,6 +550,47 @@ function targetKey(finding, target) {
|
|
|
546
550
|
? `parent-update:${target.package}>${finding.pkg.name}`
|
|
547
551
|
: `install:${target.package}`;
|
|
548
552
|
}
|
|
553
|
+
// Build a parent-update target whose targetVersion always belongs to `package`.
|
|
554
|
+
// When the named package is the parent of the finding, the child's version moves
|
|
555
|
+
// onto childPackage / childTargetVersion so renderers cannot treat it as an
|
|
556
|
+
// upgrade of the parent (#1152). When the named package is the child itself
|
|
557
|
+
// (deep-chain npm update, pnpm/yarn/bun lockfile refresh), targetVersion stays
|
|
558
|
+
// the child's destination.
|
|
559
|
+
function parentUpdateTarget(finding, urgent, args) {
|
|
560
|
+
const namesParent = args.package !== finding.pkg.name;
|
|
561
|
+
return {
|
|
562
|
+
package: args.package,
|
|
563
|
+
currentVersion: args.currentVersion,
|
|
564
|
+
targetVersion: namesParent ? args.currentVersion : args.childTargetVersion,
|
|
565
|
+
childPackage: namesParent ? finding.pkg.name : undefined,
|
|
566
|
+
childTargetVersion: namesParent ? args.childTargetVersion : undefined,
|
|
567
|
+
scannedVersions: null,
|
|
568
|
+
knownVulnerableVersions: null,
|
|
569
|
+
kind: "parent-update",
|
|
570
|
+
urgent,
|
|
571
|
+
severity: finding.severity,
|
|
572
|
+
adjusted: false,
|
|
573
|
+
adjustmentNote: null,
|
|
574
|
+
reason: args.reason,
|
|
575
|
+
command: args.command,
|
|
576
|
+
usage: finding.usage ?? null,
|
|
577
|
+
isDev: args.isDev,
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* The version of finding.pkg that the plan is aiming for.
|
|
582
|
+
* A parent-update that names a different package stores the child's destination
|
|
583
|
+
* on childTargetVersion, not on targetVersion (which is the parent's).
|
|
584
|
+
*/
|
|
585
|
+
export function planVersionForFinding(plan, finding) {
|
|
586
|
+
const target = findFixTargetForFinding(plan, finding);
|
|
587
|
+
if (!target)
|
|
588
|
+
return undefined;
|
|
589
|
+
if (target.childPackage === finding.pkg.name && target.childTargetVersion) {
|
|
590
|
+
return target.childTargetVersion;
|
|
591
|
+
}
|
|
592
|
+
return target.targetVersion;
|
|
593
|
+
}
|
|
549
594
|
function upsertTarget(targetsByKey, finding, next) {
|
|
550
595
|
const key = targetKey(finding, next);
|
|
551
596
|
const existing = targetsByKey.get(key);
|
|
@@ -576,6 +621,10 @@ function upsertTarget(targetsByKey, finding, next) {
|
|
|
576
621
|
chainProof: existing.chainProof ?? next.chainProof,
|
|
577
622
|
chainSafeVersion: existing.chainSafeVersion ?? next.chainSafeVersion,
|
|
578
623
|
chainVulnerablePackage: existing.chainVulnerablePackage ?? next.chainVulnerablePackage,
|
|
624
|
+
childPackage: existing.childPackage ?? next.childPackage,
|
|
625
|
+
childTargetVersion: higherVersion(existing.childTargetVersion, next.childTargetVersion)
|
|
626
|
+
?? existing.childTargetVersion
|
|
627
|
+
?? next.childTargetVersion,
|
|
579
628
|
// Conservative: if either contributing finding's recommendation is unverified,
|
|
580
629
|
// keep the merged target unverified rather than overstate coverage.
|
|
581
630
|
confidence: existing.confidence === "unverified" || next.confidence === "unverified"
|
|
@@ -668,6 +717,15 @@ function isUpgradeTarget(currentVersion, targetVersion) {
|
|
|
668
717
|
}
|
|
669
718
|
return true;
|
|
670
719
|
}
|
|
720
|
+
function higherVersion(a, b) {
|
|
721
|
+
if (!a)
|
|
722
|
+
return b;
|
|
723
|
+
if (!b)
|
|
724
|
+
return a;
|
|
725
|
+
if (looksLikeVersion(a) && looksLikeVersion(b) && compareVersions(b, a) > 0)
|
|
726
|
+
return b;
|
|
727
|
+
return a;
|
|
728
|
+
}
|
|
671
729
|
function buildSections(targets, packageManager) {
|
|
672
730
|
const groups = [];
|
|
673
731
|
const sectionOrder = [
|
|
@@ -159,7 +159,16 @@ export async function resolvePublishedFixVersion(packageName, fixedVersionHint)
|
|
|
159
159
|
publishedAt: null,
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Resolve a fix version from advisory range metadata alone.
|
|
164
|
+
*
|
|
165
|
+
* Correct for the advisories it is handed, and that is the limitation: the
|
|
166
|
+
* caller passes the set that matched the INSTALLED version, so an advisory
|
|
167
|
+
* introduced at or above the fix version is not in it and nothing here can
|
|
168
|
+
* reject a candidate that advisory covers. `confirmAgainstAdvisorySource`
|
|
169
|
+
* closes that gap.
|
|
170
|
+
*/
|
|
171
|
+
async function resolveFromAdvisoryRanges(packageName, installedVersion, vulnerabilities) {
|
|
163
172
|
if (!looksLikeVersion(installedVersion)) {
|
|
164
173
|
return {
|
|
165
174
|
resolvedVersion: null,
|
|
@@ -268,6 +277,104 @@ export async function resolveLowestKnownNonVulnerableVersion(packageName, instal
|
|
|
268
277
|
publishedAt: null,
|
|
269
278
|
};
|
|
270
279
|
}
|
|
280
|
+
/** Candidates queried above the range answer before giving up and saying so. */
|
|
281
|
+
const CONFIRMATION_CANDIDATE_LIMIT = 25;
|
|
282
|
+
/**
|
|
283
|
+
* Re-ask the advisory source about the version we are about to recommend.
|
|
284
|
+
*
|
|
285
|
+
* The question is asked per version rather than by evaluating ranges, the same
|
|
286
|
+
* choice `populateAdmittedVersions` makes for OA010 and for the same reason:
|
|
287
|
+
* advisory ranges arrive in shapes that are not valid semver and one id can
|
|
288
|
+
* carry different ranges per ecosystem, so parsing them fails silently in the
|
|
289
|
+
* unsafe direction. A version-scoped query cannot.
|
|
290
|
+
*
|
|
291
|
+
* Starts at the range answer rather than at the installed version, so the usual
|
|
292
|
+
* case is a single query that confirms it.
|
|
293
|
+
*/
|
|
294
|
+
/** Keep the version we were going to recommend, but say it is not confirmed. */
|
|
295
|
+
function markUnconfirmed(resolution, packageName, proposed, reason) {
|
|
296
|
+
return {
|
|
297
|
+
...resolution,
|
|
298
|
+
verified: false,
|
|
299
|
+
note: `${packageName}@${proposed} could not be confirmed free of later advisories (${reason}).`,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/** Published stable versions from the proposed one upward, capped. */
|
|
303
|
+
function confirmationCandidates(packument, proposed) {
|
|
304
|
+
return Object.keys(packument?.versions ?? {})
|
|
305
|
+
.filter(looksLikeVersion)
|
|
306
|
+
.filter(v => !isPreReleaseVersion(v))
|
|
307
|
+
.filter(v => compareVersions(v, proposed) >= 0)
|
|
308
|
+
.sort(compareVersions)
|
|
309
|
+
.slice(0, CONFIRMATION_CANDIDATE_LIMIT);
|
|
310
|
+
}
|
|
311
|
+
async function confirmAgainstAdvisorySource(packageName, resolution, advisorySource, proposedVersion) {
|
|
312
|
+
// The range pass returns null whenever any advisory lacks usable ranges, which
|
|
313
|
+
// one sparse duplicate record is enough to cause (#1196). The caller's hint is
|
|
314
|
+
// then what gets recommended, so that is what has to be confirmed.
|
|
315
|
+
const proposed = resolution.resolvedVersion ?? proposedVersion;
|
|
316
|
+
if (!proposed)
|
|
317
|
+
return resolution;
|
|
318
|
+
const packument = await fetchPackument(packageName);
|
|
319
|
+
const candidates = confirmationCandidates(packument, proposed);
|
|
320
|
+
if (candidates.length === 0)
|
|
321
|
+
return resolution;
|
|
322
|
+
const unconfirmed = (reason) => markUnconfirmed(resolution, packageName, proposed, reason);
|
|
323
|
+
let results;
|
|
324
|
+
try {
|
|
325
|
+
results = await advisorySource.queryBatch(candidates.map(version => ({ name: packageName, version, ecosystem: "npm" })), { batchId: "fix-version-confirmation" });
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
return unconfirmed("the advisory source was unavailable");
|
|
329
|
+
}
|
|
330
|
+
// An advisory source is an external boundary: it can resolve to undefined or a
|
|
331
|
+
// non-array, and one malformed response must not take the whole scan down the
|
|
332
|
+
// way an unguarded advisory record used to (#917).
|
|
333
|
+
if (!Array.isArray(results))
|
|
334
|
+
return unconfirmed("the advisory source returned no usable result");
|
|
335
|
+
const vulnerableVersions = new Set(results
|
|
336
|
+
.filter((r) => typeof r === "object" && r !== null && typeof r.version === "string")
|
|
337
|
+
.filter(r => (r.vulnerabilities ?? []).length > 0)
|
|
338
|
+
.map(r => r.version));
|
|
339
|
+
const confirmed = candidates.find(v => !vulnerableVersions.has(v));
|
|
340
|
+
if (!confirmed)
|
|
341
|
+
return unconfirmed(`the ${candidates.length} versions above it are also affected`);
|
|
342
|
+
// A version-scoped query returning nothing is a stronger statement than range
|
|
343
|
+
// arithmetic, so it confirms the answer even when the range pass could not.
|
|
344
|
+
if (confirmed === proposed && resolution.resolvedVersion)
|
|
345
|
+
return resolution;
|
|
346
|
+
// Both counters describe the same set, so they have to advance together. The
|
|
347
|
+
// confirmation pass examined every candidate up to and including `confirmed`,
|
|
348
|
+
// which is `index + 1` versions, of which `index` were affected. Advancing
|
|
349
|
+
// only the vulnerable count left the pair equal for a single-version window,
|
|
350
|
+
// and `fix-commands` reads `knownVulnerable >= scanned` as "no safe upgrade",
|
|
351
|
+
// so a confirmed fix was reported as an unmaintained dead end (#1213).
|
|
352
|
+
const confirmedIndex = candidates.indexOf(confirmed);
|
|
353
|
+
return {
|
|
354
|
+
...resolution,
|
|
355
|
+
resolvedVersion: confirmed,
|
|
356
|
+
verified: true,
|
|
357
|
+
note: null,
|
|
358
|
+
candidatesChecked: resolution.candidatesChecked + confirmedIndex + 1,
|
|
359
|
+
candidatesKnownVulnerable: resolution.candidatesKnownVulnerable + confirmedIndex,
|
|
360
|
+
publishedAt: packument?.time?.[confirmed] ?? null,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* The lowest published version above `installedVersion` with no known advisory.
|
|
365
|
+
*
|
|
366
|
+
* Two passes. The first reads the advisory ranges we already hold, which is fast
|
|
367
|
+
* and offline-capable. The second asks the advisory source about the version
|
|
368
|
+
* that produced, because an advisory introduced at or above it was never matched
|
|
369
|
+
* to this finding and is therefore invisible to the first pass.
|
|
370
|
+
*/
|
|
371
|
+
export async function resolveLowestKnownNonVulnerableVersion(packageName, installedVersion, vulnerabilities, options) {
|
|
372
|
+
const resolution = await resolveFromAdvisoryRanges(packageName, installedVersion, vulnerabilities);
|
|
373
|
+
const advisorySource = options?.advisorySource;
|
|
374
|
+
if (!advisorySource)
|
|
375
|
+
return resolution;
|
|
376
|
+
return confirmAgainstAdvisorySource(packageName, resolution, advisorySource, options?.proposedVersion);
|
|
377
|
+
}
|
|
271
378
|
function isVersionAffectedByVulnerability(packageName, version, vuln) {
|
|
272
379
|
const affectedEntries = vuln.affected ?? [];
|
|
273
380
|
if (affectedEntries.length === 0)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context note naming the child a parent-update target refreshes, or null.
|
|
3
|
+
* Leaf module so printers / fix-runner / create-pr can import without cycling through fix-commands.
|
|
4
|
+
*/
|
|
5
|
+
export function formatParentUpdateChildNote(target) {
|
|
6
|
+
if (target.kind && target.kind !== "parent-update")
|
|
7
|
+
return null;
|
|
8
|
+
if (!target.childPackage || !target.childTargetVersion)
|
|
9
|
+
return null;
|
|
10
|
+
return `refresh ${target.childPackage} to ${target.childTargetVersion}`;
|
|
11
|
+
}
|
|
@@ -5,6 +5,7 @@ import { EXIT_OK, EXIT_FINDINGS, EXIT_ERROR } from "../types.js";
|
|
|
5
5
|
import { loadMultiplePackages } from "../parsers/multi-package.js";
|
|
6
6
|
import { scanPackages, buildCoverageNotes } from "../scanner.js";
|
|
7
7
|
import { sortFindingsForOutput, serializeFinding, logInfo } from "../output/formatters.js";
|
|
8
|
+
import { resolveOutputDir, displayOutputPath } from "../output/output-dir.js";
|
|
8
9
|
import { normalizeSeverity } from "../osv/severity.js";
|
|
9
10
|
import { selectFindingsForTable } from "../output/finding-display.js";
|
|
10
11
|
import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
|
|
@@ -280,9 +281,9 @@ export async function handleMultiFolderScan(params) {
|
|
|
280
281
|
};
|
|
281
282
|
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
282
283
|
const jsonFilename = `cve-lite-scan-${ts}.json`;
|
|
283
|
-
const jsonOutputPath = path.join(
|
|
284
|
+
const jsonOutputPath = path.join(resolveOutputDir(params.options.output), jsonFilename);
|
|
284
285
|
fs.writeFileSync(jsonOutputPath, JSON.stringify(payload, null, 2));
|
|
285
|
-
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(
|
|
286
|
+
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(displayOutputPath(jsonOutputPath))}`);
|
|
286
287
|
}
|
|
287
288
|
else {
|
|
288
289
|
printMultiFolderResults(results, params.options);
|
package/dist/scan/single-scan.js
CHANGED
|
@@ -24,7 +24,8 @@ import { renderLicenseFindings } from "../output/license-terminal.js";
|
|
|
24
24
|
import { readDirectDependencyNames, hasOverrideEntries } from "../utils/package-json.js";
|
|
25
25
|
import { applyFixesIfRequested, printFixModeSummary, writeFixResultJson, } from "../utils/fix-runner.js";
|
|
26
26
|
import { audit, buildOverrideContext } from "../overrides/index.js";
|
|
27
|
-
import {
|
|
27
|
+
import { buildFixResultAppliedEntries, createPullRequestForFixes, } from "../utils/create-pr.js";
|
|
28
|
+
import { buildCveFixAppliedEvent } from "../audit-log/events.js";
|
|
28
29
|
import { readBaseline, writeBaseline, filterNewFindings, ratchetOutcome } from "../utils/baseline.js";
|
|
29
30
|
import { formatDiagnosticMessage, getCompletenessImpact, shouldFailForIncompleteScan } from "./completeness.js";
|
|
30
31
|
export async function handleSingleFolderScan(params) {
|
|
@@ -260,15 +261,15 @@ export async function handleSingleFolderScan(params) {
|
|
|
260
261
|
// Emit cve.fix.applied for each target in the fix plan
|
|
261
262
|
if (scanState.suggestedFixCommands?.targets) {
|
|
262
263
|
for (const target of scanState.suggestedFixCommands.targets) {
|
|
263
|
-
auditLog.emit({
|
|
264
|
+
auditLog.emit(buildCveFixAppliedEvent({
|
|
264
265
|
ts: new Date().toISOString(),
|
|
265
|
-
type: "cve.fix.applied",
|
|
266
|
-
schemaVersion: 1,
|
|
267
266
|
package: target.package,
|
|
268
267
|
fromVersion: target.currentVersion ?? "unknown",
|
|
269
268
|
toVersion: target.targetVersion,
|
|
270
269
|
mechanism: target.kind,
|
|
271
|
-
|
|
270
|
+
childPackage: target.childPackage,
|
|
271
|
+
childTargetVersion: target.childTargetVersion,
|
|
272
|
+
}));
|
|
272
273
|
}
|
|
273
274
|
}
|
|
274
275
|
if (options.fix) {
|
|
@@ -286,12 +287,7 @@ export async function handleSingleFolderScan(params) {
|
|
|
286
287
|
appliedWithinRangeRefreshCount: fixResult?.appliedWithinRangeRefreshCount ?? 0,
|
|
287
288
|
findingsBeforeFix,
|
|
288
289
|
findingsAfterFix: scanState.sorted.length,
|
|
289
|
-
applied: (fixResult?.applied ?? [])
|
|
290
|
-
package: entry.package,
|
|
291
|
-
from: entry.from,
|
|
292
|
-
to: entry.to,
|
|
293
|
-
advisories: collectAdvisoryIdsForPackage(findingsBeforeFixList, entry.package),
|
|
294
|
-
})),
|
|
290
|
+
applied: buildFixResultAppliedEntries(fixResult?.applied ?? [], findingsBeforeFixList),
|
|
295
291
|
notAutoApplied: {
|
|
296
292
|
parentUpgradeCount: fixResult?.parentUpgradeCount ?? 0,
|
|
297
293
|
breakingUpgradeCount: fixResult?.breakingUpgradeCount ?? 0,
|
package/dist/scanner.js
CHANGED
|
@@ -2,7 +2,7 @@ import { fetchEpssScores } from "./epss/client.js";
|
|
|
2
2
|
import { chunk, runWithConcurrency } from "./utils/array.js";
|
|
3
3
|
import { isPrivateRegistrySource, isGitSource, hasCommitShaPinning } from "./utils/advisory.js";
|
|
4
4
|
import { extractCveAliases, hasMaliciousAdvisory } from "./utils/vuln.js";
|
|
5
|
-
import { compareVersions, isPreReleaseVersion,
|
|
5
|
+
import { compareVersions, isPreReleaseVersion, normalizeAdvisoryVersion } from "./utils/version.js";
|
|
6
6
|
import { loadCache, saveCache, isEntryStale } from "./osv/cache.js";
|
|
7
7
|
import { maxSeverity } from "./osv/severity.js";
|
|
8
8
|
import { createSpinner } from "./output/spinner.js";
|
|
@@ -201,7 +201,13 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
201
201
|
const uncachedForNpm = [];
|
|
202
202
|
for (const pkg of allNpmPkgs) {
|
|
203
203
|
const key = getPackageCacheKey(pkg);
|
|
204
|
-
|
|
204
|
+
// `--no-cache` was honoured for OSV queries and the registry publish-date
|
|
205
|
+
// lookups but never here, so a flag whose whole purpose is to take the
|
|
206
|
+
// cache out of the picture still served this block from it, and two
|
|
207
|
+
// consecutive --no-cache runs could disagree. Writing back is deliberate
|
|
208
|
+
// and matches the other caches, which a test already pins; only the read
|
|
209
|
+
// is skipped (#1166).
|
|
210
|
+
const cached = options.noCache ? undefined : cache.npmAdvisoryEntries[key];
|
|
205
211
|
if (cached && !isEntryStale(cached, nowMs)) {
|
|
206
212
|
const newCachedVulns = cached.vulns.filter(v => !existingVulnIds.has(v.id));
|
|
207
213
|
if (newCachedVulns.length > 0) {
|
|
@@ -265,7 +271,12 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
265
271
|
const nowMs = Date.now();
|
|
266
272
|
const uncachedIds = [];
|
|
267
273
|
for (const id of ids) {
|
|
268
|
-
|
|
274
|
+
// Same gap as the npm advisory block above: the advisory detail cache
|
|
275
|
+
// was read regardless of the flag, so a --no-cache run could still
|
|
276
|
+
// restore a previously cached detail, including a negative entry that
|
|
277
|
+
// marks the scan incomplete. The write below stays unguarded, as it is
|
|
278
|
+
// for the other caches (#1166).
|
|
279
|
+
const cached = options.noCache ? undefined : cache.entries[id];
|
|
269
280
|
if (cached && !isEntryStale(cached, nowMs)) {
|
|
270
281
|
if (cached.vuln) {
|
|
271
282
|
vulnMap.set(id, cached.vuln);
|
|
@@ -498,7 +509,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
498
509
|
if (!offline) {
|
|
499
510
|
const npmVersionCacheUpdated = await validateDirectFixTargets(findings, (finding) => {
|
|
500
511
|
updateAnalysisProgress("validating fix target for", `${finding.pkg.name}@${finding.pkg.version}`);
|
|
501
|
-
}, { cache, noCache: options.noCache, debugLog: log });
|
|
512
|
+
}, { cache, noCache: options.noCache, debugLog: log, advisorySource });
|
|
502
513
|
if (npmVersionCacheUpdated) {
|
|
503
514
|
saveCache(cache, cacheDirOverride, options.debug ? log : undefined);
|
|
504
515
|
}
|
|
@@ -640,6 +651,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
640
651
|
cache,
|
|
641
652
|
noCache: options.noCache,
|
|
642
653
|
debugLog: log,
|
|
654
|
+
advisorySource,
|
|
643
655
|
});
|
|
644
656
|
if (npmVersionCacheUpdated) {
|
|
645
657
|
saveCache(cache, cacheDirOverride, options.debug ? log : undefined);
|
|
@@ -731,7 +743,9 @@ async function validateOneDirectFixTarget(finding, options) {
|
|
|
731
743
|
verified: Boolean(finding.validatedFirstFixedVersion),
|
|
732
744
|
});
|
|
733
745
|
};
|
|
734
|
-
|
|
746
|
+
// The advisory source re-checks the proposed version for advisories
|
|
747
|
+
// introduced above the installed one, which never matched this finding.
|
|
748
|
+
const lowestKnownResolution = await resolveLowestKnownNonVulnerableVersion(finding.pkg.name, finding.pkg.version, finding.vulnerabilities, { advisorySource: options?.advisorySource, proposedVersion: finding.firstFixedVersion });
|
|
735
749
|
const fixedVersionHint = finding.firstFixedVersion;
|
|
736
750
|
const setPublishedDate = (resolution) => {
|
|
737
751
|
const date = resolution.publishedAt;
|
|
@@ -849,56 +863,86 @@ function affectedEntryMatchesPackage(affected, packageName, ecosystem) {
|
|
|
849
863
|
*/
|
|
850
864
|
function versionWithinAffectedWindow(version, introduced, fixed) {
|
|
851
865
|
if (introduced && introduced !== "0") {
|
|
852
|
-
|
|
866
|
+
// Advisories write boundaries with fewer than three components, so `2` means
|
|
867
|
+
// 2.0.0. Normalizing rather than rejecting keeps the window usable, and a
|
|
868
|
+
// value that is not a version at all still returns null and bails (#1192).
|
|
869
|
+
const normalizedIntroduced = normalizeAdvisoryVersion(introduced);
|
|
870
|
+
if (!normalizedIntroduced)
|
|
853
871
|
return false;
|
|
854
|
-
if (compareVersions(version,
|
|
872
|
+
if (compareVersions(version, normalizedIntroduced) < 0)
|
|
855
873
|
return false;
|
|
856
874
|
}
|
|
857
875
|
return compareVersions(version, fixed) < 0;
|
|
858
876
|
}
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
if (!fixed || !looksLikeVersion(fixed) || isPreReleaseVersion(fixed))
|
|
886
|
-
continue;
|
|
887
|
-
fixedVersions.push(fixed);
|
|
888
|
-
if (installedVersion && versionWithinAffectedWindow(installedVersion, introduced, fixed)) {
|
|
889
|
-
fixesOnInstalledBranch.push(fixed);
|
|
890
|
-
}
|
|
891
|
-
introduced = null;
|
|
877
|
+
/**
|
|
878
|
+
* Every usable fixed version one advisory declares for this package, split into
|
|
879
|
+
* all of them and those whose affected window contains the installed version.
|
|
880
|
+
*/
|
|
881
|
+
function collectAdvisoryFixes(vuln, packageName, ecosystem, installedVersion) {
|
|
882
|
+
const all = [];
|
|
883
|
+
// An advisory that patches two release branches declares a fix per branch, and
|
|
884
|
+
// the other branch's fix is a downgrade across a major boundary rather than a
|
|
885
|
+
// remediation.
|
|
886
|
+
const onInstalledBranch = [];
|
|
887
|
+
for (const affected of vuln.affected ?? []) {
|
|
888
|
+
// An advisory may list several packages with different fix versions.
|
|
889
|
+
// Without this filter the minimum across all of them was returned, so a
|
|
890
|
+
// package inherited another package's (lower) fix and the scan reported a
|
|
891
|
+
// version that does not fix it.
|
|
892
|
+
if (!affectedEntryMatchesPackage(affected, packageName, ecosystem))
|
|
893
|
+
continue;
|
|
894
|
+
for (const range of affected.ranges ?? []) {
|
|
895
|
+
// Events are ordered, and a single range can reintroduce a vulnerability,
|
|
896
|
+
// so `introduced` is tracked as the walk proceeds and reset once its
|
|
897
|
+
// matching `fixed` closes the window.
|
|
898
|
+
let introduced = null;
|
|
899
|
+
for (const event of range.events ?? []) {
|
|
900
|
+
if (event.introduced) {
|
|
901
|
+
introduced = event.introduced;
|
|
902
|
+
continue;
|
|
892
903
|
}
|
|
904
|
+
// `fixed: "1.22"` is 1.22.0. Requiring a strict X.Y.Z here discarded the
|
|
905
|
+
// event, and a finding whose every candidate was discarded reported "no
|
|
906
|
+
// fix available", which tells a developer to stop looking for a fix that
|
|
907
|
+
// exists (#1192). A value that cannot be read in full is still dropped,
|
|
908
|
+
// so a commit hash from a GIT range never becomes a fix version.
|
|
909
|
+
const fixed = normalizeAdvisoryVersion(event.fixed);
|
|
910
|
+
if (!fixed || isPreReleaseVersion(fixed))
|
|
911
|
+
continue;
|
|
912
|
+
all.push(fixed);
|
|
913
|
+
if (installedVersion && versionWithinAffectedWindow(installedVersion, introduced, fixed)) {
|
|
914
|
+
onInstalledBranch.push(fixed);
|
|
915
|
+
}
|
|
916
|
+
introduced = null;
|
|
893
917
|
}
|
|
894
918
|
}
|
|
895
919
|
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
920
|
+
return { all, onInstalledBranch };
|
|
921
|
+
}
|
|
922
|
+
export function findFirstFixedVersion(vulns, packageName, ecosystem, installedVersion) {
|
|
923
|
+
const everyKnownFix = [];
|
|
924
|
+
// One entry per advisory: the earliest version clearing THAT advisory on the
|
|
925
|
+
// branch the install sits on.
|
|
926
|
+
const perAdvisoryFixes = [];
|
|
927
|
+
for (const vuln of vulns) {
|
|
928
|
+
const { all, onInstalledBranch } = collectAdvisoryFixes(vuln, packageName, ecosystem, installedVersion);
|
|
929
|
+
everyKnownFix.push(...all);
|
|
930
|
+
if (onInstalledBranch.length > 0) {
|
|
931
|
+
// Lowest WITHIN one advisory: the branch fix, not the other branch's.
|
|
932
|
+
perAdvisoryFixes.push(onInstalledBranch.sort(compareVersions)[0]);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
// Highest ACROSS advisories: the caller needs a version clear of all of them,
|
|
936
|
+
// and stopping at the lowest leaves every advisory fixed above it still live.
|
|
937
|
+
if (perAdvisoryFixes.length > 0) {
|
|
938
|
+
return perAdvisoryFixes.sort(compareVersions)[perAdvisoryFixes.length - 1];
|
|
939
|
+
}
|
|
940
|
+
// No declared window contains the installed version, so there is no branch to
|
|
941
|
+
// scope to. Falling back to every known fix keeps a finding's remediation
|
|
942
|
+
// visible rather than reporting none.
|
|
943
|
+
if (everyKnownFix.length === 0)
|
|
900
944
|
return null;
|
|
901
|
-
return
|
|
945
|
+
return everyKnownFix.sort(compareVersions)[0];
|
|
902
946
|
}
|
|
903
947
|
function buildCompletenessDiagnostics(params) {
|
|
904
948
|
const diagnostics = [];
|
package/dist/utils/create-pr.js
CHANGED
|
@@ -3,6 +3,7 @@ import fs from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { severityOrder } from "../constants.js";
|
|
5
5
|
import { normalizeSeverity } from "../osv/severity.js";
|
|
6
|
+
import { formatParentUpdateChildNote } from "../remediation/parent-update-child-note.js";
|
|
6
7
|
import { pluralize } from "./string.js";
|
|
7
8
|
const DEPENDENCY_FILES_TO_STAGE = [
|
|
8
9
|
"package.json",
|
|
@@ -51,6 +52,21 @@ export function collectAdvisoryIdsForPackage(findings, packageName) {
|
|
|
51
52
|
}
|
|
52
53
|
return [...ids].sort();
|
|
53
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Build `--fix` result JSON `applied[]` entries for Action/automation consumers.
|
|
57
|
+
* Advisories are looked up on the refreshed child when present (parent-update),
|
|
58
|
+
* otherwise on the named package - same rule as create-pr body lines.
|
|
59
|
+
*/
|
|
60
|
+
export function buildFixResultAppliedEntries(applied, findingsBeforeFix) {
|
|
61
|
+
return applied.map(entry => ({
|
|
62
|
+
package: entry.package,
|
|
63
|
+
from: entry.from,
|
|
64
|
+
to: entry.to,
|
|
65
|
+
advisories: collectAdvisoryIdsForPackage(findingsBeforeFix, entry.childPackage ?? entry.package),
|
|
66
|
+
...(entry.childPackage ? { childPackage: entry.childPackage } : {}),
|
|
67
|
+
...(entry.childTargetVersion ? { childTargetVersion: entry.childTargetVersion } : {}),
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
54
70
|
export function buildPullRequestBody(params) {
|
|
55
71
|
const overrideFixCount = params.overrideFixCount ?? 0;
|
|
56
72
|
const lines = [
|
|
@@ -65,9 +81,12 @@ export function buildPullRequestBody(params) {
|
|
|
65
81
|
lines.push("- _No direct CVE fixes in this PR._");
|
|
66
82
|
}
|
|
67
83
|
for (const item of params.fixResult.applied) {
|
|
68
|
-
const
|
|
84
|
+
const advisoryPackage = item.childPackage ?? item.package;
|
|
85
|
+
const advisoryIds = collectAdvisoryIdsForPackage(params.findingsBeforeFix, advisoryPackage);
|
|
69
86
|
const advisoryText = advisoryIds.length > 0 ? advisoryIds.join(", ") : "n/a";
|
|
70
|
-
|
|
87
|
+
const childNote = formatParentUpdateChildNote(item);
|
|
88
|
+
const versionLine = `- **${item.package}**: \`${item.from}\` → \`${item.to}\``;
|
|
89
|
+
lines.push(childNote ? `${versionLine} (${childNote})` : versionLine);
|
|
71
90
|
lines.push(` - Advisories: ${advisoryText}`);
|
|
72
91
|
}
|
|
73
92
|
if (overrideFixCount > 0) {
|