cve-lite-cli 1.36.1 → 1.38.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 +25 -3
- package/dist/advisory/local-db.js +22 -3
- package/dist/audit-log/events.js +14 -0
- package/dist/cli/args.js +125 -102
- package/dist/cli/flags.js +39 -0
- package/dist/cli/help.js +8 -3
- package/dist/cli/overrides.js +25 -19
- package/dist/cli/validate.js +34 -9
- package/dist/index.js +6 -1
- package/dist/output/compact-truncation.js +35 -0
- package/dist/output/cyclonedx.js +6 -3
- package/dist/output/formatters.js +10 -2
- package/dist/output/html-reporter.js +31 -15
- package/dist/output/multi-folder-html-reporter.js +26 -7
- package/dist/output/output-dir.js +20 -0
- package/dist/output/override-findings-html.js +24 -3
- package/dist/output/override-findings-json.js +5 -2
- package/dist/output/override-findings-sarif.js +1 -0
- package/dist/output/override-findings-terminal.js +21 -1
- package/dist/output/printers.js +52 -25
- package/dist/output/sarif.js +63 -6
- package/dist/output/sbom-file.js +6 -4
- package/dist/output/scan-json.js +74 -0
- package/dist/output/skipped-override-rules.js +41 -0
- package/dist/output/spdx.js +2 -2
- package/dist/output/write-outputs.js +22 -32
- package/dist/overrides/admitted-scan.js +12 -1
- package/dist/overrides/api.js +75 -21
- package/dist/overrides/context-builder.js +17 -2
- package/dist/overrides/detectors/index.js +2 -0
- package/dist/overrides/detectors/oa008-materialized.js +74 -14
- package/dist/overrides/detectors/oa009-stale-floor.js +12 -15
- package/dist/overrides/detectors/oa010-vulnerable-floor.js +5 -1
- package/dist/overrides/detectors/oa011-exceeds-range.js +128 -0
- package/dist/overrides/detectors/pd001-override-only-phantom.js +5 -4
- package/dist/overrides/detectors/pd002-transitive-only-phantom.js +5 -4
- package/dist/overrides/detectors/phantom-utils.js +29 -0
- package/dist/overrides/parsing/registry.js +79 -10
- package/dist/remediation/fix-commands.js +89 -31
- package/dist/remediation/npm-registry.js +9 -1
- package/dist/remediation/parent-update-child-note.js +11 -0
- package/dist/scan/multi-folder-scan.js +68 -53
- package/dist/scan/override-audit.js +49 -0
- package/dist/scan/single-scan.js +115 -44
- package/dist/scanner.js +35 -11
- package/dist/skills/content.js +4 -2
- package/dist/usage/scanner.js +219 -28
- package/dist/utils/contextual-signals.js +193 -0
- package/dist/utils/create-pr.js +21 -2
- package/dist/utils/finding.js +5 -0
- package/dist/utils/fix-runner.js +15 -2
- package/dist/utils/package-json.js +66 -14
- package/dist/utils/severity.js +22 -0
- package/dist/utils/update-check.js +2 -1
- package/dist/utils/version.js +81 -86
- package/package.json +3 -1
- package/scripts/pr-scan-delta.mjs +7 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getDeclaredPackages, installCmd } from "./phantom-utils.js";
|
|
1
|
+
import { getDeclaredPackages, installCmd, undeclaredImportFiles } from "./phantom-utils.js";
|
|
2
2
|
const RULE_ID = "PD002";
|
|
3
3
|
export function detect(ctx) {
|
|
4
4
|
if (ctx.skippedDetectors.some((s) => s.ruleId === RULE_ID))
|
|
@@ -9,13 +9,14 @@ export function detect(ctx) {
|
|
|
9
9
|
const overrideNames = new Set(ctx.overrideEntries.map((e) => e.packageName));
|
|
10
10
|
const cmd = installCmd(ctx.packageManager);
|
|
11
11
|
const findings = [];
|
|
12
|
-
for (const [pkgName,
|
|
13
|
-
if (declared.has(pkgName))
|
|
14
|
-
continue;
|
|
12
|
+
for (const [pkgName, importedIn] of ctx.importedPackageNames) {
|
|
15
13
|
if (overrideNames.has(pkgName))
|
|
16
14
|
continue; // PD001 owns this
|
|
17
15
|
if (!ctx.lockfilePackageNames.has(pkgName))
|
|
18
16
|
continue; // not in graph
|
|
17
|
+
const files = undeclaredImportFiles(ctx, pkgName, importedIn, declared);
|
|
18
|
+
if (files.length === 0)
|
|
19
|
+
continue;
|
|
19
20
|
const shown = files.slice(0, 3);
|
|
20
21
|
const extra = files.length > 3 ? ` (+${files.length - 3} more)` : "";
|
|
21
22
|
findings.push({
|
|
@@ -10,6 +10,35 @@ export function getDeclaredPackages(packageJson) {
|
|
|
10
10
|
}
|
|
11
11
|
return declared;
|
|
12
12
|
}
|
|
13
|
+
// The importing files for which `pkgName` is genuinely undeclared. A root
|
|
14
|
+
// declaration satisfies every file (root node_modules is on every member's
|
|
15
|
+
// resolution path). Otherwise a file is resolved against the nearest enclosing
|
|
16
|
+
// workspace member: a dependency declared in apps/web/package.json is a real
|
|
17
|
+
// direct dependency for apps/web/src/*, not a phantom. Files outside any member
|
|
18
|
+
// fall back to the root manifest.
|
|
19
|
+
export function undeclaredImportFiles(ctx, pkgName, files, rootDeclared) {
|
|
20
|
+
if (rootDeclared.has(pkgName))
|
|
21
|
+
return [];
|
|
22
|
+
const members = ctx.workspaceMembers ?? [];
|
|
23
|
+
if (members.length === 0)
|
|
24
|
+
return files;
|
|
25
|
+
return files.filter((file) => {
|
|
26
|
+
const owner = owningWorkspaceMember(members, file);
|
|
27
|
+
return !owner || !owner.declared.has(pkgName);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function owningWorkspaceMember(members, file) {
|
|
31
|
+
const normalized = file.replace(/\\/g, "/");
|
|
32
|
+
let best = null;
|
|
33
|
+
for (const member of members) {
|
|
34
|
+
if (!normalized.startsWith(`${member.dir}/`))
|
|
35
|
+
continue;
|
|
36
|
+
// Nested members (packages/a and packages/a/plugins/b): the deepest wins.
|
|
37
|
+
if (!best || member.dir.length > best.dir.length)
|
|
38
|
+
best = member;
|
|
39
|
+
}
|
|
40
|
+
return best;
|
|
41
|
+
}
|
|
13
42
|
export function installCmd(pm) {
|
|
14
43
|
if (pm === "pnpm")
|
|
15
44
|
return "pnpm add";
|
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import { compareVersions, isPreReleaseVersion } from '../../utils/version.js';
|
|
2
|
+
async function classify(attempt, parse) {
|
|
3
|
+
let res;
|
|
4
|
+
try {
|
|
5
|
+
res = await attempt();
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return { kind: "failed" };
|
|
9
|
+
}
|
|
10
|
+
if (res.status === 404 || res.status === 410)
|
|
11
|
+
return { kind: "absent" };
|
|
12
|
+
if (!res.ok)
|
|
13
|
+
return { kind: "failed" };
|
|
14
|
+
try {
|
|
15
|
+
const value = await parse(res);
|
|
16
|
+
return value === null ? { kind: "absent" } : { kind: "ok", value };
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return { kind: "failed" };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
2
22
|
/**
|
|
3
23
|
* Fetch the `dist-tags` map for `pkgName` from the npm registry.
|
|
4
24
|
*
|
|
@@ -10,6 +30,43 @@ import { compareVersions, isPreReleaseVersion } from '../../utils/version.js';
|
|
|
10
30
|
* cache the result on `Context.registryDistTags`. This function is single-shot;
|
|
11
31
|
* caching/batching is the scanner's responsibility.
|
|
12
32
|
*/
|
|
33
|
+
/** Shared request shape for both lookups. */
|
|
34
|
+
async function packumentOutcome(pkgName, opts, parse) {
|
|
35
|
+
const baseUrl = opts.baseUrl ?? 'https://registry.npmjs.org';
|
|
36
|
+
const timeoutMs = opts.timeoutMs ?? 5000;
|
|
37
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
38
|
+
const url = `${baseUrl}/${encodeRegistryPath(pkgName)}`;
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
41
|
+
try {
|
|
42
|
+
return await classify(() => fetchImpl(url, {
|
|
43
|
+
signal: controller.signal,
|
|
44
|
+
headers: {
|
|
45
|
+
Accept: 'application/vnd.npm.install-v1+json',
|
|
46
|
+
'User-Agent': 'override-audit-cli',
|
|
47
|
+
},
|
|
48
|
+
}), parse);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function distTagsOutcome(pkgName, opts) {
|
|
55
|
+
return packumentOutcome(pkgName, opts, async (res) => {
|
|
56
|
+
const body = await res.json();
|
|
57
|
+
return body['dist-tags'] ?? null;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async function versionsOutcome(pkgName, opts) {
|
|
61
|
+
return packumentOutcome(pkgName, opts, async (res) => {
|
|
62
|
+
const body = await res.json();
|
|
63
|
+
if (!body.versions)
|
|
64
|
+
return null;
|
|
65
|
+
return Object.keys(body.versions)
|
|
66
|
+
.filter((v) => !isPreReleaseVersion(v))
|
|
67
|
+
.sort(compareVersions);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
13
70
|
export async function fetchDistTags(pkgName, opts = {}) {
|
|
14
71
|
const baseUrl = opts.baseUrl ?? 'https://registry.npmjs.org';
|
|
15
72
|
const timeoutMs = opts.timeoutMs ?? 5000;
|
|
@@ -42,14 +99,20 @@ export async function fetchDistTags(pkgName, opts = {}) {
|
|
|
42
99
|
* (per-package), so a single 404 doesn't tank the whole batch.
|
|
43
100
|
*/
|
|
44
101
|
export async function fetchDistTagsBatch(pkgNames, opts = {}) {
|
|
45
|
-
const
|
|
102
|
+
const results = new Map();
|
|
103
|
+
const failed = [];
|
|
46
104
|
const unique = Array.from(new Set(pkgNames));
|
|
47
105
|
await Promise.all(unique.map(async (name) => {
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
|
|
106
|
+
const outcome = await distTagsOutcome(name, opts);
|
|
107
|
+
if (outcome.kind === "ok") {
|
|
108
|
+
results.set(name, outcome.value);
|
|
109
|
+
}
|
|
110
|
+
else if (outcome.kind === "failed") {
|
|
111
|
+
failed.push(name);
|
|
112
|
+
}
|
|
113
|
+
// `absent` is deliberately neither: the registry answered and said no such package.
|
|
51
114
|
}));
|
|
52
|
-
return
|
|
115
|
+
return { results, failed };
|
|
53
116
|
}
|
|
54
117
|
/**
|
|
55
118
|
* Fetch every published version of `pkgName`, ascending, excluding prereleases.
|
|
@@ -94,14 +157,20 @@ export async function fetchVersions(pkgName, opts = {}) {
|
|
|
94
157
|
* collapse to an absent entry rather than failing the batch.
|
|
95
158
|
*/
|
|
96
159
|
export async function fetchVersionsBatch(pkgNames, opts = {}) {
|
|
97
|
-
const
|
|
160
|
+
const results = new Map();
|
|
161
|
+
const failed = [];
|
|
98
162
|
const unique = Array.from(new Set(pkgNames));
|
|
99
163
|
await Promise.all(unique.map(async (name) => {
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
102
|
-
|
|
164
|
+
const outcome = await versionsOutcome(name, opts);
|
|
165
|
+
if (outcome.kind === "ok") {
|
|
166
|
+
results.set(name, outcome.value);
|
|
167
|
+
}
|
|
168
|
+
else if (outcome.kind === "failed") {
|
|
169
|
+
failed.push(name);
|
|
170
|
+
}
|
|
171
|
+
// `absent` is deliberately neither, same as the dist-tags batch above.
|
|
103
172
|
}));
|
|
104
|
-
return
|
|
173
|
+
return { results, failed };
|
|
105
174
|
}
|
|
106
175
|
/**
|
|
107
176
|
* Encode a package name for the registry URL.
|
|
@@ -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 = [
|
|
@@ -343,12 +343,20 @@ async function confirmAgainstAdvisorySource(packageName, resolution, advisorySou
|
|
|
343
343
|
// arithmetic, so it confirms the answer even when the range pass could not.
|
|
344
344
|
if (confirmed === proposed && resolution.resolvedVersion)
|
|
345
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);
|
|
346
353
|
return {
|
|
347
354
|
...resolution,
|
|
348
355
|
resolvedVersion: confirmed,
|
|
349
356
|
verified: true,
|
|
350
357
|
note: null,
|
|
351
|
-
|
|
358
|
+
candidatesChecked: resolution.candidatesChecked + confirmedIndex + 1,
|
|
359
|
+
candidatesKnownVulnerable: resolution.candidatesKnownVulnerable + confirmedIndex,
|
|
352
360
|
publishedAt: packument?.time?.[confirmed] ?? null,
|
|
353
361
|
};
|
|
354
362
|
}
|
|
@@ -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
|
+
}
|
|
@@ -4,27 +4,29 @@ import process from "node:process";
|
|
|
4
4
|
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
|
-
import { sortFindingsForOutput,
|
|
7
|
+
import { sortFindingsForOutput, logInfo } from "../output/formatters.js";
|
|
8
|
+
import { buildMultiFolderScanJson } from "../output/scan-json.js";
|
|
9
|
+
import { resolveOutputDir, displayOutputPath } from "../output/output-dir.js";
|
|
8
10
|
import { normalizeSeverity } from "../osv/severity.js";
|
|
9
11
|
import { selectFindingsForTable } from "../output/finding-display.js";
|
|
10
12
|
import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
|
|
11
13
|
import { readDirectDependencyNames, hasOverrideEntries } from "../utils/package-json.js";
|
|
12
|
-
import { DEFAULT_SEARCH_DEPTH,
|
|
14
|
+
import { DEFAULT_SEARCH_DEPTH, OVERRIDES_COMMAND } from "../constants.js";
|
|
13
15
|
import { printMultiFolderResults } from "../output/multi-folder-printer.js";
|
|
14
16
|
import { printOverrideHint } from "../output/printers.js";
|
|
15
17
|
import { writeMultiFolderHtmlReport } from "../output/multi-folder-html-reporter.js";
|
|
16
18
|
import { chalk } from "../utils/chalk.js";
|
|
17
19
|
import { getCliVersion } from "../utils/version-info.js";
|
|
18
|
-
import {
|
|
20
|
+
import { runOverrideAudit } from "./override-audit.js";
|
|
19
21
|
import { NULL_AUDIT_LOG } from "../audit-log/index.js";
|
|
20
22
|
import { detectDM001 } from "../maintenance/dm001-maintenance-risk.js";
|
|
21
23
|
import { detectLicenseIssues } from "../licenses/license-check.js";
|
|
22
24
|
import { renderLicenseFindings } from "../output/license-terminal.js";
|
|
23
|
-
import {
|
|
25
|
+
import { failingGateSummary } from "../utils/severity.js";
|
|
24
26
|
import { readBaseline, writeBaseline, filterNewFindings, ratchetOutcome } from "../utils/baseline.js";
|
|
25
27
|
import { pluralize } from "../utils/string.js";
|
|
26
28
|
import { aggregateMultiFolderCompleteness, formatDiagnosticMessage, getCompletenessImpact, shouldFailForIncompleteScan, } from "./completeness.js";
|
|
27
|
-
import { scanProjectForPackageUsage } from "../usage/scanner.js";
|
|
29
|
+
import { scanProjectForPackageUsage, usageScanTruncationWarning } from "../usage/scanner.js";
|
|
28
30
|
export async function runMultiFolderScan(params) {
|
|
29
31
|
const searchDepth = Math.max(0, Number(params.options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
30
32
|
const folders = loadMultiplePackages(params.projectRoot, !!params.options.prodOnly, searchDepth);
|
|
@@ -44,22 +46,37 @@ export async function runMultiFolderScan(params) {
|
|
|
44
46
|
scanFilePath: scanInput.filePath,
|
|
45
47
|
}, undefined, params.fetchImpl);
|
|
46
48
|
// Mirror single-folder scanProject: annotate / filter by source imports per subfolder.
|
|
49
|
+
let usageTruncated = false;
|
|
47
50
|
if (params.options.usage) {
|
|
48
51
|
logInfo(`Scanning ${subfolder}/ source for usage hints...`, params.options);
|
|
49
52
|
const pkgNames = new Set(findings.map(f => f.pkg.name));
|
|
50
|
-
const
|
|
53
|
+
const usageResult = scanProjectForPackageUsage(subfolderAbs, pkgNames);
|
|
54
|
+
const usageData = usageResult.usage;
|
|
55
|
+
usageTruncated = usageResult.truncated;
|
|
51
56
|
for (const finding of findings) {
|
|
52
57
|
const files = usageData[finding.pkg.name];
|
|
53
|
-
if (files)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
if (!files)
|
|
59
|
+
continue;
|
|
60
|
+
if (files.length > 0) {
|
|
61
|
+
finding.usage = { imported: true, files };
|
|
62
|
+
}
|
|
63
|
+
else if (usageTruncated) {
|
|
64
|
+
// A truncated scan cannot prove a package is unused: unknown, not false.
|
|
65
|
+
finding.usage = { imported: null, files };
|
|
58
66
|
}
|
|
67
|
+
else {
|
|
68
|
+
finding.usage = { imported: false, files };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (usageResult.truncated) {
|
|
72
|
+
// Push into the folder's scan warnings so --json and the HTML report
|
|
73
|
+
// disclose it; printMultiFolderResults prints the same array in terminal mode.
|
|
74
|
+
scanInput.warnings.push(usageScanTruncationWarning({ subfolder, onlyUsed: !!params.options.onlyUsed }));
|
|
59
75
|
}
|
|
60
76
|
}
|
|
61
77
|
let finalFindings = findings;
|
|
62
|
-
if (params.options.onlyUsed) {
|
|
78
|
+
if (params.options.onlyUsed && !usageTruncated) {
|
|
79
|
+
// Truncated: "not scanned" is not "not imported", so don't narrow the gate.
|
|
63
80
|
finalFindings = finalFindings.filter(f => f.usage?.imported);
|
|
64
81
|
}
|
|
65
82
|
let sorted = sortFindingsForOutput(finalFindings);
|
|
@@ -82,14 +99,21 @@ export async function runMultiFolderScan(params) {
|
|
|
82
99
|
// Override hygiene is independent of the CVE ratchet/baseline. A --ratchet
|
|
83
100
|
// run skips the override audit entirely (same boundary as single-folder).
|
|
84
101
|
let overrideFindings = [];
|
|
102
|
+
let overrideSkipped = [];
|
|
85
103
|
if (params.options.checkOverrides && !params.options.ratchet) {
|
|
86
|
-
|
|
104
|
+
// Per folder, through the same helper the single-folder path uses. Building the
|
|
105
|
+
// advisory source here is what lets OA010 run at all; passing only checkNetwork
|
|
106
|
+
// left it recording "no advisory source was available" for every folder.
|
|
107
|
+
const outcome = await runOverrideAudit({
|
|
108
|
+
projectPath: subfolderAbs,
|
|
109
|
+
checkNetwork: !!params.options.checkNetwork,
|
|
110
|
+
osvUrl: params.options.osvUrl,
|
|
87
111
|
auditLog: params.auditLog ?? NULL_AUDIT_LOG,
|
|
88
112
|
logger: { info: () => { }, warn: () => { }, error: () => { }, debug: () => { } },
|
|
89
|
-
|
|
113
|
+
fetchImpl: params.fetchImpl,
|
|
90
114
|
});
|
|
91
|
-
|
|
92
|
-
|
|
115
|
+
overrideFindings = outcome.findings;
|
|
116
|
+
overrideSkipped = outcome.skipped;
|
|
93
117
|
}
|
|
94
118
|
// Maintenance from the baseline-filtered set. Skipped under --ratchet because
|
|
95
119
|
// that path always early-exits on CVE save/gate (same as single-folder).
|
|
@@ -123,6 +147,7 @@ export async function runMultiFolderScan(params) {
|
|
|
123
147
|
allPackages: scanInput.packages,
|
|
124
148
|
completeness,
|
|
125
149
|
overrideFindings,
|
|
150
|
+
overrideSkipped,
|
|
126
151
|
maintenanceFindings,
|
|
127
152
|
licenseFindings,
|
|
128
153
|
licenseLimitedToDirectOnly,
|
|
@@ -140,6 +165,9 @@ function handleMultiFolderRatchet(results, projectRoot, options) {
|
|
|
140
165
|
let anyNewFindings = false;
|
|
141
166
|
let hasDetectionGaps = false;
|
|
142
167
|
for (const r of results) {
|
|
168
|
+
for (const warning of r.scanInput.warnings) {
|
|
169
|
+
console.log(chalk.yellow(warning));
|
|
170
|
+
}
|
|
143
171
|
const { hasDetectionGap } = getCompletenessImpact(r.completeness);
|
|
144
172
|
if (hasDetectionGap) {
|
|
145
173
|
hasDetectionGaps = true;
|
|
@@ -251,46 +279,29 @@ export async function handleMultiFolderScan(params) {
|
|
|
251
279
|
if (params.options.json) {
|
|
252
280
|
// Match single-folder writeOutputs: timestamped file in cwd, not stdout dump.
|
|
253
281
|
// Help text and CI both treat --json as "save a JSON file".
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
multiFolder: true,
|
|
282
|
+
const payload = buildMultiFolderScanJson({
|
|
283
|
+
results,
|
|
257
284
|
projectPath: params.projectRoot,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
diagnostics: aggregatedCompleteness.diagnostics,
|
|
263
|
-
findings: allFindings,
|
|
264
|
-
...(params.options.checkOverrides
|
|
265
|
-
? {
|
|
266
|
-
overrideFindings: results.flatMap(r => r.overrideFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
|
|
267
|
-
}
|
|
268
|
-
: {}),
|
|
269
|
-
...(params.options.checkMaintenance
|
|
270
|
-
? {
|
|
271
|
-
maintenanceFindings: results.flatMap(r => r.maintenanceFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
|
|
272
|
-
}
|
|
273
|
-
: {}),
|
|
274
|
-
...(params.options.checkLicenses
|
|
275
|
-
? {
|
|
276
|
-
licenseFindings: results.flatMap(r => r.licenseFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
|
|
277
|
-
}
|
|
278
|
-
: {}),
|
|
279
|
-
scannedAt: new Date().toISOString(),
|
|
280
|
-
};
|
|
285
|
+
includeOverrides: !!params.options.checkOverrides,
|
|
286
|
+
includeMaintenance: !!params.options.checkMaintenance,
|
|
287
|
+
includeLicenses: !!params.options.checkLicenses,
|
|
288
|
+
});
|
|
281
289
|
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
282
290
|
const jsonFilename = `cve-lite-scan-${ts}.json`;
|
|
283
|
-
const jsonOutputPath = path.join(
|
|
291
|
+
const jsonOutputPath = path.join(resolveOutputDir(params.options.output), jsonFilename);
|
|
284
292
|
fs.writeFileSync(jsonOutputPath, JSON.stringify(payload, null, 2));
|
|
285
|
-
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(
|
|
293
|
+
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(displayOutputPath(jsonOutputPath))}`);
|
|
286
294
|
}
|
|
287
295
|
else {
|
|
288
296
|
printMultiFolderResults(results, params.options);
|
|
289
297
|
if (params.options.checkOverrides) {
|
|
290
|
-
const { renderOverrideFindings } = await import("../output/override-findings-terminal.js");
|
|
298
|
+
const { renderOverrideFindings, renderSkippedOverrideRules } = await import("../output/override-findings-terminal.js");
|
|
291
299
|
for (const r of results) {
|
|
292
300
|
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${r.subfolder}/`)} ${chalk.gray("override hygiene")}\n`);
|
|
293
|
-
console.log(renderOverrideFindings(r.overrideFindings, { verbose: !!params.options.verbose, projectPath: path.join(params.projectRoot, r.subfolder) }));
|
|
301
|
+
console.log(renderOverrideFindings(r.overrideFindings, { verbose: !!params.options.verbose, projectPath: path.join(params.projectRoot, r.subfolder), rulesSkipped: r.overrideSkipped.length > 0 }));
|
|
302
|
+
if (r.overrideSkipped.length > 0) {
|
|
303
|
+
console.log(renderSkippedOverrideRules(r.overrideSkipped));
|
|
304
|
+
}
|
|
294
305
|
}
|
|
295
306
|
}
|
|
296
307
|
if (params.options.checkMaintenance) {
|
|
@@ -333,22 +344,26 @@ export async function handleMultiFolderScan(params) {
|
|
|
333
344
|
});
|
|
334
345
|
console.log(`${chalk.gray("Report:")} ${chalk.cyan(reportPath)}`);
|
|
335
346
|
}
|
|
336
|
-
const failLevel = normalizeSeverity(params.options.failOn);
|
|
337
347
|
const allSorted = results.flatMap(r => r.sorted);
|
|
338
348
|
const allOverrideFindings = results.flatMap(r => r.overrideFindings);
|
|
339
349
|
const allMaintenanceFindings = results.flatMap(r => r.maintenanceFindings);
|
|
340
|
-
// Mirror single-folder exit policy in src/
|
|
341
|
-
// all count toward --fail-on. Without overrides here, multi-folder CI
|
|
342
|
-
// --check-overrides --fail-on high would exit 0 despite high OA findings.
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
350
|
+
// Mirror single-folder exit policy in src/scan/single-scan.ts: CVE + override +
|
|
351
|
+
// maintenance all count toward --fail-on. Without overrides here, multi-folder CI
|
|
352
|
+
// using --check-overrides --fail-on high would exit 0 despite high OA findings.
|
|
353
|
+
const gateLine = failingGateSummary([
|
|
354
|
+
{ label: "vulnerability", findings: allSorted },
|
|
355
|
+
{ label: "override hygiene", findings: allOverrideFindings },
|
|
356
|
+
{ label: "maintenance risk", findings: allMaintenanceFindings },
|
|
357
|
+
], params.options.failOn);
|
|
358
|
+
const shouldFail = gateLine !== null;
|
|
346
359
|
const incompleteFailure = shouldFailForIncompleteScan(aggregatedCompleteness, params.options.incompletePolicy);
|
|
347
360
|
const exitCode = incompleteFailure
|
|
348
361
|
? EXIT_ERROR
|
|
349
362
|
: shouldFail
|
|
350
363
|
? EXIT_FINDINGS
|
|
351
364
|
: EXIT_OK;
|
|
365
|
+
if (gateLine && !params.options.json)
|
|
366
|
+
console.log(chalk.red(gateLine));
|
|
352
367
|
auditLog.emit({
|
|
353
368
|
ts: new Date(scanFinishedAt).toISOString(),
|
|
354
369
|
type: "scan.finished",
|