cve-lite-cli 1.38.0 → 1.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/args.js
CHANGED
|
@@ -5,7 +5,7 @@ import { FLAG_ALL, FLAG_ALLOW_PRIVATE_OSV_URL, FLAG_AUDIT_LOG, FLAG_BASE, FLAG_B
|
|
|
5
5
|
* emit today, so a future `spdx3` can be added without changing what a plain
|
|
6
6
|
* `spdx` means for anyone already using it in CI.
|
|
7
7
|
*/
|
|
8
|
-
const SBOM_FORMAT_ALIASES = {
|
|
8
|
+
export const SBOM_FORMAT_ALIASES = {
|
|
9
9
|
cyclonedx: "cyclonedx",
|
|
10
10
|
spdx: "spdx",
|
|
11
11
|
"spdx2.3": "spdx",
|
|
@@ -8,6 +8,7 @@ import { loadFromYarnLock } from "../parsers/yarn-lock.js";
|
|
|
8
8
|
import { loadFromBunLock } from "../parsers/bun-lock.js";
|
|
9
9
|
import { scanAllImports, usageScanTruncationWarning } from "../usage/scanner.js";
|
|
10
10
|
import { readWorkspaceMemberManifests } from "../utils/package-json.js";
|
|
11
|
+
import { isNodeBuiltinSpecifier } from "../utils/node-builtins.js";
|
|
11
12
|
import { getDeclaredPackages } from "./detectors/phantom-utils.js";
|
|
12
13
|
export function buildOverrideContext(projectPath, opts) {
|
|
13
14
|
const pkgJsonPath = join(projectPath, "package.json");
|
|
@@ -20,6 +21,7 @@ export function buildOverrideContext(projectPath, opts) {
|
|
|
20
21
|
const packageManager = detectPackageManager(projectPath);
|
|
21
22
|
const readResult = readLockfileNames(projectPath, packageManager);
|
|
22
23
|
const lockfilePackageNames = readResult.kind === "ok" ? readResult.names : new Set();
|
|
24
|
+
const lockfileVersions = readResult.kind === "ok" ? readResult.versions : new Map();
|
|
23
25
|
const nodeModulesExists = existsSync(join(projectPath, "node_modules"));
|
|
24
26
|
const skipped = [];
|
|
25
27
|
if (lockfilePackageNames.size === 0 && overrideEntries.length > 0) {
|
|
@@ -65,7 +67,11 @@ export function buildOverrideContext(projectPath, opts) {
|
|
|
65
67
|
const admittedVersions = new Map();
|
|
66
68
|
const admittedVulnerable = new Map();
|
|
67
69
|
const importsResult = scanAllImports(projectPath);
|
|
68
|
-
|
|
70
|
+
// A built-in module is not a package, so it must not enter a map the phantom
|
|
71
|
+
// rules read as "packages this project imports". Filtering at construction
|
|
72
|
+
// covers PD001, PD002 and OA009's declaration guard in one place, rather than
|
|
73
|
+
// leaving each detector to remember.
|
|
74
|
+
const importedPackageNames = new Map([...importsResult.imports].filter(([specifier]) => !isNodeBuiltinSpecifier(specifier)));
|
|
69
75
|
if (importsResult.truncated) {
|
|
70
76
|
opts.logger.warn(usageScanTruncationWarning());
|
|
71
77
|
}
|
|
@@ -83,6 +89,7 @@ export function buildOverrideContext(projectPath, opts) {
|
|
|
83
89
|
packageManager,
|
|
84
90
|
overrideEntries,
|
|
85
91
|
lockfilePackageNames,
|
|
92
|
+
lockfileVersions,
|
|
86
93
|
installedVersions,
|
|
87
94
|
installedCopies: tree.installedCopies,
|
|
88
95
|
parentDeclarations: tree.parentDeclarations,
|
|
@@ -108,6 +115,27 @@ function detectPackageManager(projectPath) {
|
|
|
108
115
|
return "npm";
|
|
109
116
|
return "unknown";
|
|
110
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Groups resolved lockfile versions by package name. A package can appear at
|
|
120
|
+
* several versions in one tree, so every one is kept: an override selector only
|
|
121
|
+
* has to match one of them to be live.
|
|
122
|
+
*/
|
|
123
|
+
function versionsByName(refs) {
|
|
124
|
+
const byName = new Map();
|
|
125
|
+
for (const ref of refs) {
|
|
126
|
+
if (!ref.version)
|
|
127
|
+
continue;
|
|
128
|
+
const seen = byName.get(ref.name);
|
|
129
|
+
if (seen) {
|
|
130
|
+
if (!seen.includes(ref.version))
|
|
131
|
+
seen.push(ref.version);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
byName.set(ref.name, [ref.version]);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return byName;
|
|
138
|
+
}
|
|
111
139
|
function readLockfileNames(projectPath, pm) {
|
|
112
140
|
if (pm === "npm") {
|
|
113
141
|
const lockPath = join(projectPath, "package-lock.json");
|
|
@@ -115,7 +143,7 @@ function readLockfileNames(projectPath, pm) {
|
|
|
115
143
|
return { kind: "absent" };
|
|
116
144
|
try {
|
|
117
145
|
const refs = loadFromPackageLock(lockPath, false);
|
|
118
|
-
return { kind: "ok", names: new Set(refs.map((r) => r.name)) };
|
|
146
|
+
return { kind: "ok", names: new Set(refs.map((r) => r.name)), versions: versionsByName(refs) };
|
|
119
147
|
}
|
|
120
148
|
catch (e) {
|
|
121
149
|
const message = e instanceof Error ? e.message : String(e);
|
|
@@ -128,7 +156,7 @@ function readLockfileNames(projectPath, pm) {
|
|
|
128
156
|
return { kind: "absent" };
|
|
129
157
|
try {
|
|
130
158
|
const refs = loadFromPnpmLock(lockPath, false);
|
|
131
|
-
return { kind: "ok", names: new Set(refs.map((r) => r.name)) };
|
|
159
|
+
return { kind: "ok", names: new Set(refs.map((r) => r.name)), versions: versionsByName(refs) };
|
|
132
160
|
}
|
|
133
161
|
catch (e) {
|
|
134
162
|
const message = e instanceof Error ? e.message : String(e);
|
|
@@ -141,7 +169,7 @@ function readLockfileNames(projectPath, pm) {
|
|
|
141
169
|
return { kind: "absent" };
|
|
142
170
|
try {
|
|
143
171
|
const refs = loadFromYarnLock(lockPath);
|
|
144
|
-
return { kind: "ok", names: new Set(refs.map((r) => r.name)) };
|
|
172
|
+
return { kind: "ok", names: new Set(refs.map((r) => r.name)), versions: versionsByName(refs) };
|
|
145
173
|
}
|
|
146
174
|
catch (e) {
|
|
147
175
|
const message = e instanceof Error ? e.message : String(e);
|
|
@@ -154,7 +182,7 @@ function readLockfileNames(projectPath, pm) {
|
|
|
154
182
|
return { kind: "absent" };
|
|
155
183
|
try {
|
|
156
184
|
const refs = loadFromBunLock(lockPath, false);
|
|
157
|
-
return { kind: "ok", names: new Set(refs.map((r) => r.name)) };
|
|
185
|
+
return { kind: "ok", names: new Set(refs.map((r) => r.name)), versions: versionsByName(refs) };
|
|
158
186
|
}
|
|
159
187
|
catch (e) {
|
|
160
188
|
const message = e instanceof Error ? e.message : String(e);
|
|
@@ -60,6 +60,45 @@ export function detect(ctx) {
|
|
|
60
60
|
}
|
|
61
61
|
return findings;
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Splits an override key into the package name and the version selector npm
|
|
65
|
+
* allows after it, so `minimatch@3` and `@scope/pkg@^2` both resolve. A bare
|
|
66
|
+
* name, or a scoped name with no selector, comes back with a null range: the
|
|
67
|
+
* leading `@` of a scope is never a separator.
|
|
68
|
+
*/
|
|
69
|
+
function splitSelector(key) {
|
|
70
|
+
const at = key.lastIndexOf("@");
|
|
71
|
+
if (at <= 0)
|
|
72
|
+
return { name: key, range: null };
|
|
73
|
+
return { name: key.slice(0, at), range: key.slice(at + 1) };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Describes why an override's outer parent cannot be matched in the tree, or
|
|
77
|
+
* null when it can.
|
|
78
|
+
*
|
|
79
|
+
* The key may carry a selector, and npm treats that as a range rather than an
|
|
80
|
+
* exact version, so `minimatch@3` is satisfied by an installed 3.1.2. Comparing
|
|
81
|
+
* the whole key against the set of package names is what made a working
|
|
82
|
+
* override look dead.
|
|
83
|
+
*
|
|
84
|
+
* Every uncertain case resolves to null, meaning no finding. Claiming an
|
|
85
|
+
* override is dead is the expensive direction to be wrong in: it tells someone
|
|
86
|
+
* to delete protection that is working. So an unparseable selector, or a
|
|
87
|
+
* package present with no version data, both stay silent rather than guess.
|
|
88
|
+
*/
|
|
89
|
+
function outerParentProblem(ctx, outerKey) {
|
|
90
|
+
const { name, range } = splitSelector(outerKey);
|
|
91
|
+
if (!ctx.lockfilePackageNames.has(name))
|
|
92
|
+
return "is not in the dependency tree";
|
|
93
|
+
if (!range || !isValidRange(range))
|
|
94
|
+
return null;
|
|
95
|
+
const resolved = ctx.lockfileVersions.get(name) ?? [];
|
|
96
|
+
if (resolved.length === 0)
|
|
97
|
+
return null;
|
|
98
|
+
if (resolved.some((version) => satisfiesRange(version, range)))
|
|
99
|
+
return null;
|
|
100
|
+
return `is in the tree at ${resolved.join(", ")}, and the selector "${range}" matches none of them`;
|
|
101
|
+
}
|
|
63
102
|
function classify(args) {
|
|
64
103
|
const { ctx, outerKey, innerKey, innerValue, entryPath, lookup, form } = args;
|
|
65
104
|
const findingBase = (subId, severity, message, details, action) => ({
|
|
@@ -95,8 +134,9 @@ function classify(args) {
|
|
|
95
134
|
return findingBase("OA005.a", "critical", "Nested override ineffective for this package manager (silently ignored)", formDesc, "remove");
|
|
96
135
|
}
|
|
97
136
|
// .b - outer parent not in resolved tree.
|
|
98
|
-
|
|
99
|
-
|
|
137
|
+
const outerProblem = outerParentProblem(ctx, outerKey);
|
|
138
|
+
if (outerProblem) {
|
|
139
|
+
return findingBase("OA005.b", "high", "Nested override outer parent not in resolved tree", `Outer parent ${outerKey} ${outerProblem}. The nested override "${innerKey}" has no parent to apply to.`, "remove");
|
|
100
140
|
}
|
|
101
141
|
// .c - outer in tree but inner is not declared in parent's manifest deps.
|
|
102
142
|
const parentManifest = lookup(outerKey);
|
|
@@ -125,5 +165,13 @@ function classify(args) {
|
|
|
125
165
|
// override is presumed fine - a hygiene auditor flags proven problems, not maybes.
|
|
126
166
|
if (form === "flat-pnpm")
|
|
127
167
|
return null;
|
|
168
|
+
// Same reasoning for an npm key that carries a version selector. `minimatch@3`
|
|
169
|
+
// is the npm spelling of a scoped override: the selector exists so the pin
|
|
170
|
+
// reaches the minimatch 3.x copy and leaves the others alone. Suggesting a flat
|
|
171
|
+
// form there is the same bad advice, since flattening would apply the pin to
|
|
172
|
+
// every copy in the tree. Only an unselectored key, where the nested and flat
|
|
173
|
+
// forms really are close to equivalent, is worth mentioning.
|
|
174
|
+
if (splitSelector(outerKey).range !== null)
|
|
175
|
+
return null;
|
|
128
176
|
return findingBase("OA005.e", "low", "Nested override could be flattened to top-level", `Nested override ${outerKey}.${innerKey} is valid and effective. A flat top-level "overrides": { "${innerKey}": "${innerValue}" } would apply across the whole tree.`, "suggest");
|
|
129
177
|
}
|
package/dist/scan/single-scan.js
CHANGED
|
@@ -542,8 +542,8 @@ export async function handleSingleFolderScan(params) {
|
|
|
542
542
|
licenseLimitedToDirectOnly: options.checkLicenses ? licenseLimitedToDirectOnly : undefined,
|
|
543
543
|
completeness: scanState.completeness,
|
|
544
544
|
});
|
|
545
|
-
// report.json follows the --json schema, plus scannedAt/cliVersion
|
|
546
|
-
// saved artifact and per-finding riskSummary/nextAction (stdout --json
|
|
545
|
+
// report.json follows the --json schema, plus scannedAt/cliVersion/
|
|
546
|
+
// lockfileSource for a saved artifact and per-finding riskSummary/nextAction (stdout --json
|
|
547
547
|
// stays unchanged via buildScanJson alone).
|
|
548
548
|
const jsonPayload = {
|
|
549
549
|
...buildScanJson({
|
|
@@ -564,6 +564,7 @@ export async function handleSingleFolderScan(params) {
|
|
|
564
564
|
}),
|
|
565
565
|
scannedAt: reportData.scannedAt,
|
|
566
566
|
cliVersion: reportData.cliVersion,
|
|
567
|
+
lockfileSource: reportData.lockfileSource,
|
|
567
568
|
findings: reportData.findings,
|
|
568
569
|
};
|
|
569
570
|
const { reportPath } = await writeHtmlReport({
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { builtinModules } from "node:module";
|
|
2
|
+
/**
|
|
3
|
+
* Identifies import specifiers that resolve to a Node built-in module rather
|
|
4
|
+
* than to an npm package.
|
|
5
|
+
*
|
|
6
|
+
* Phantom-dependency rules compare imported names against declared
|
|
7
|
+
* dependencies, so a built-in has to be excluded before that comparison: it
|
|
8
|
+
* needs no declaration, and telling someone to install it points them at an
|
|
9
|
+
* unrelated npm shim.
|
|
10
|
+
*/
|
|
11
|
+
const NODE_PREFIX = "node:";
|
|
12
|
+
const BUILTIN_NAMES = new Set(builtinModules);
|
|
13
|
+
/**
|
|
14
|
+
* True when the specifier is a Node built-in.
|
|
15
|
+
*
|
|
16
|
+
* Two cases, and both are needed. `builtinModules` lists the bare names
|
|
17
|
+
* (`events`, `string_decoder`), but it deliberately omits the modules that
|
|
18
|
+
* exist only behind the prefix, so `test`, `sea` and `sqlite` are absent from
|
|
19
|
+
* it. Node also rejects any unknown `node:` specifier rather than falling back
|
|
20
|
+
* to the registry, so the prefix alone is proof of intent and nothing on npm
|
|
21
|
+
* can claim it.
|
|
22
|
+
*
|
|
23
|
+
* Subpaths resolve on their first segment, so `node:fs/promises` and
|
|
24
|
+
* `stream/web` are both recognised. A scoped package is unaffected, since
|
|
25
|
+
* `@scope` is never a built-in name.
|
|
26
|
+
*/
|
|
27
|
+
export function isNodeBuiltinSpecifier(specifier) {
|
|
28
|
+
if (specifier.startsWith(NODE_PREFIX))
|
|
29
|
+
return true;
|
|
30
|
+
const firstSegment = specifier.split("/")[0];
|
|
31
|
+
return BUILTIN_NAMES.has(firstSegment);
|
|
32
|
+
}
|
package/dist/utils/version.js
CHANGED
|
@@ -251,6 +251,10 @@ export function positionAgainstRange(version, range) {
|
|
|
251
251
|
// change the classification below, so the comparisons take the raw range.
|
|
252
252
|
if (!normalizedVersion || !semver.validRange(trimmedRange, { loose: true }))
|
|
253
253
|
return null;
|
|
254
|
+
// includePrerelease is deliberate and must not be dropped. Without it semver
|
|
255
|
+
// excludes a prerelease from a range it should satisfy, so a prerelease sitting
|
|
256
|
+
// inside a vulnerable range reads as safe. That was a real false negative, fixed
|
|
257
|
+
// in v1.34.0, and this flag is what keeps it fixed.
|
|
254
258
|
const options = { loose: true, includePrerelease: true };
|
|
255
259
|
try {
|
|
256
260
|
if (semver.satisfies(normalizedVersion, trimmedRange, options))
|