cve-lite-cli 1.39.0 → 1.41.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 -22
- package/dist/advisory/local-advisory-source.js +9 -5
- package/dist/advisory/local-db.js +91 -13
- package/dist/advisory/osv-sync.js +187 -56
- package/dist/advisory/staging-directory.js +112 -0
- package/dist/cli/advisories-sync.js +16 -2
- package/dist/cli/args.js +46 -35
- package/dist/cli/config.js +4 -1
- package/dist/cli/help.js +5 -3
- package/dist/cli/validate.js +23 -1
- package/dist/constants.js +15 -28
- package/dist/index.js +8 -3
- package/dist/osv/severity.js +1 -1
- package/dist/output/cyclonedx.js +24 -15
- package/dist/output/debug.js +68 -18
- package/dist/output/formatters.js +35 -7
- package/dist/output/html-reporter.js +68 -12
- package/dist/output/multi-folder-html-reporter.js +71 -11
- package/dist/output/output-dir.js +193 -7
- package/dist/output/override-findings-html.js +3 -6
- package/dist/output/override-findings-terminal.js +7 -12
- package/dist/output/override-fix-command.js +13 -0
- package/dist/output/printers.js +27 -12
- package/dist/output/sarif.js +168 -57
- package/dist/output/sbom-dependency-edges.js +16 -10
- package/dist/output/sbom-file.js +14 -6
- package/dist/output/scan-json.js +46 -3
- package/dist/output/spdx.js +61 -23
- package/dist/output/spinner.js +2 -1
- package/dist/output/write-outputs.js +143 -41
- package/dist/overrides/context-builder.js +23 -70
- package/dist/overrides/parsing/registry.js +1 -1
- package/dist/parsers/bun-lock.js +1 -2
- package/dist/parsers/index.js +22 -1
- package/dist/parsers/npm-lock-graph.js +39 -1
- package/dist/parsers/package-lock.js +25 -5
- package/dist/parsers/pnpm-lock.js +26 -12
- package/dist/parsers/utils.js +5 -3
- package/dist/parsers/yarn-lock-graph.js +5 -2
- package/dist/parsers/yarn-lock.js +1 -2
- package/dist/remediation/fix-commands.js +140 -50
- package/dist/remediation/npm-registry.js +56 -7
- package/dist/remediation/npm-transitive-graph.js +30 -72
- package/dist/remediation/npm-transitive-resolution.js +35 -107
- package/dist/remediation/parent-candidate-resolver.js +65 -0
- package/dist/remediation/parent-upgrade-blockers.js +51 -0
- package/dist/remediation/parent-upgrade.js +11 -116
- package/dist/remediation/registry-parent-ranges.js +21 -0
- package/dist/remediation/transitive-chain-resolver.js +3 -3
- package/dist/scan/completeness.js +17 -11
- package/dist/scan/multi-folder-scan.js +154 -59
- package/dist/scan/override-audit.js +11 -1
- package/dist/scan/single-scan.js +123 -67
- package/dist/scanner.js +288 -66
- package/dist/skills/content.js +12 -12
- package/dist/usage/scanner.js +19 -8
- package/dist/utils/array.js +11 -3
- package/dist/utils/contextual-signals.js +1 -1
- package/dist/utils/debug-bundle.js +118 -0
- package/dist/utils/debug-project.js +102 -0
- package/dist/utils/debug-redaction.js +117 -0
- package/dist/utils/effective-options.js +55 -0
- package/dist/utils/file.js +2 -1
- package/dist/utils/finding.js +1 -1
- package/dist/utils/fix-runner.js +98 -15
- package/dist/utils/import-type-queries.js +322 -0
- package/dist/utils/network.js +14 -10
- package/dist/utils/npm-lockfile.js +12 -0
- package/dist/utils/osv-fetch.js +70 -0
- package/dist/utils/package-identity.js +43 -0
- package/dist/utils/package-manager-source.js +24 -0
- package/dist/utils/purl.js +37 -0
- package/dist/utils/registry-config.js +129 -0
- package/dist/utils/severity.js +8 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/validate-url.js +4 -4
- package/dist/utils/version.js +47 -8
- package/dist/utils/versions/osv-range.js +191 -0
- package/dist/utils/versions/pep440.js +246 -0
- package/dist/utils/versions/scheme.js +10 -0
- package/dist/utils/vuln.js +75 -0
- package/package.json +3 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { unique } from "../utils/array.js";
|
|
3
|
+
import { npmAliasRegistryName } from "../utils/package-identity.js";
|
|
3
4
|
export function loadNpmLockGraph(filePath, options) {
|
|
4
5
|
const raw = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
5
6
|
const packages = raw?.packages;
|
|
@@ -67,7 +68,8 @@ export function loadNpmLockGraph(filePath, options) {
|
|
|
67
68
|
workspaceEntryNodeIds.push(id);
|
|
68
69
|
}
|
|
69
70
|
const rootMeta = isRecord(rawPackages[""]) ? rawPackages[""] : null;
|
|
70
|
-
const
|
|
71
|
+
const rootRanges = collectRootDependencyRanges(rootMeta);
|
|
72
|
+
const entryPackages = resolveEdgesForParent("", rootRanges, [""], nodeIdByPackagePath, childNodeIdsByParentNodeId, parentNodeIdsByChildNodeId, rangeByParentNodeId);
|
|
71
73
|
for (const node of nodesById.values()) {
|
|
72
74
|
resolveEdgesForParent(node.packagePath, dependencyRangesByNodeId.get(node.id) ?? {}, resolutionBasePathsByNodeId.get(node.id) ?? [node.packagePath], nodeIdByPackagePath, childNodeIdsByParentNodeId, parentNodeIdsByChildNodeId, rangeByParentNodeId);
|
|
73
75
|
}
|
|
@@ -82,6 +84,21 @@ export function loadNpmLockGraph(filePath, options) {
|
|
|
82
84
|
childNodeIdsByParentNodeId,
|
|
83
85
|
rangeByParentNodeId,
|
|
84
86
|
});
|
|
87
|
+
// A different manifest name also occurs for git/tarball installs. Only an
|
|
88
|
+
// npm: declaration establishes a registry alias for the resolved graph slot.
|
|
89
|
+
const rootEntryNodeIds = new Set(entryPackages);
|
|
90
|
+
for (const node of nodesById.values()) {
|
|
91
|
+
const declaredRanges = [
|
|
92
|
+
rootEntryNodeIds.has(node.id) ? rootRanges[node.name] : undefined,
|
|
93
|
+
...[...(parentNodeIdsByChildNodeId.get(node.id) ?? [])]
|
|
94
|
+
.map(parentId => rangeByParentNodeId.get(parentId)?.get(node.name)),
|
|
95
|
+
];
|
|
96
|
+
const registryName = declaredRanges.map(npmAliasRegistryName)
|
|
97
|
+
.find(name => name && name !== node.name);
|
|
98
|
+
if (registryName) {
|
|
99
|
+
node.registryName = registryName;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
85
102
|
if (options?.includePaths !== false) {
|
|
86
103
|
const MAX_PATHS_PER_NODE = 5;
|
|
87
104
|
const MAX_PATH_DEPTH = 10;
|
|
@@ -119,6 +136,7 @@ export function loadNpmLockGraph(filePath, options) {
|
|
|
119
136
|
childNodeIdsByParentNodeId: setsToArrays(childNodeIdsByParentNodeId),
|
|
120
137
|
rangeByParentNodeId,
|
|
121
138
|
pathSetByNodeId,
|
|
139
|
+
peerRangesByChildNodeId: collectPeerRangesByChild(nodesById, peerRangesByNodeId, resolutionBasePathsByNodeId, nodeIdByPackagePath),
|
|
122
140
|
});
|
|
123
141
|
}
|
|
124
142
|
function createGraph(args) {
|
|
@@ -165,8 +183,28 @@ function createGraph(args) {
|
|
|
165
183
|
return [...(args.pathSetByNodeId.get(nodeId) ?? new Set())]
|
|
166
184
|
.map((item) => item.split(">"));
|
|
167
185
|
},
|
|
186
|
+
peerRangesFor(nodeId) {
|
|
187
|
+
return args.peerRangesByChildNodeId?.get(nodeId) ?? EMPTY_ARRAY;
|
|
188
|
+
},
|
|
168
189
|
};
|
|
169
190
|
}
|
|
191
|
+
// npm refuses an install whose version breaks a peer requirement, so every
|
|
192
|
+
// peer range on an installed copy limits what it can be moved to, whether or
|
|
193
|
+
// not the peer fallback below turned that requirement into an edge.
|
|
194
|
+
function collectPeerRangesByChild(nodesById, peerRangesByNodeId, resolutionBasePathsByNodeId, nodeIdByPackagePath) {
|
|
195
|
+
const rangesByChild = new Map();
|
|
196
|
+
for (const [nodeId, peerRanges] of peerRangesByNodeId) {
|
|
197
|
+
const basePaths = resolutionBasePathsByNodeId.get(nodeId) ?? [nodesById.get(nodeId)?.packagePath ?? nodeId];
|
|
198
|
+
for (const [peerName, range] of Object.entries(peerRanges)) {
|
|
199
|
+
const childPackagePath = resolveDependencyPackagePath(basePaths, peerName, nodeIdByPackagePath);
|
|
200
|
+
const childNodeId = childPackagePath ? nodeIdByPackagePath.get(childPackagePath) : undefined;
|
|
201
|
+
if (!childNodeId)
|
|
202
|
+
continue;
|
|
203
|
+
rangesByChild.set(childNodeId, [...(rangesByChild.get(childNodeId) ?? []), range]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return rangesByChild;
|
|
207
|
+
}
|
|
170
208
|
function resolveEdgesForParent(parentPackagePath, dependencyRanges, resolutionBasePaths, nodeIdByPackagePath, childNodeIdsByParentNodeId, parentNodeIdsByChildNodeId, rangeByParentNodeId) {
|
|
171
209
|
const resolvedChildNodeIds = [];
|
|
172
210
|
for (const [dependencyName, range] of Object.entries(dependencyRanges)) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { upsertPackage, normalizeNodeModulesPath } from "./utils.js";
|
|
3
3
|
import { loadNpmLockGraph } from "./npm-lock-graph.js";
|
|
4
|
-
|
|
4
|
+
import { npmAliasRegistryName, packageNameKey, parseNpmAliasVersion, registryPackageName } from "../utils/package-identity.js";
|
|
5
|
+
export function buildNpmWorkspaceMap(filePath, options) {
|
|
5
6
|
const raw = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
6
7
|
const map = new Map();
|
|
7
8
|
if (!raw.packages || typeof raw.packages !== "object")
|
|
@@ -19,6 +20,14 @@ export function buildNpmWorkspaceMap(filePath) {
|
|
|
19
20
|
if (!existing.includes(workspacePath)) {
|
|
20
21
|
map.set(depName, [...existing, workspacePath]);
|
|
21
22
|
}
|
|
23
|
+
const registryName = options?.includeAliasIdentities ? npmAliasRegistryName(depSection[depName]) : null;
|
|
24
|
+
if (registryName) {
|
|
25
|
+
const key = packageNameKey({ name: depName, registryName });
|
|
26
|
+
const members = map.get(key) ?? [];
|
|
27
|
+
if (!members.includes(workspacePath)) {
|
|
28
|
+
map.set(key, [...members, workspacePath]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
22
31
|
}
|
|
23
32
|
}
|
|
24
33
|
}
|
|
@@ -50,12 +59,19 @@ export function loadFromPackageLock(filePath, prodOnly) {
|
|
|
50
59
|
continue;
|
|
51
60
|
if (prodOnly && dev)
|
|
52
61
|
continue;
|
|
53
|
-
const
|
|
62
|
+
const registryName = graph.getNode(pkgPath)?.registryName;
|
|
63
|
+
const nodeIds = graph.nodeIdsFor(name, version).filter(id => {
|
|
64
|
+
const node = graph.getNode(id);
|
|
65
|
+
return node && registryPackageName(node) === registryPackageName({ name, registryName });
|
|
66
|
+
});
|
|
54
67
|
const graphPaths = nodeIds.flatMap(id => graph.pathsFor(id));
|
|
55
68
|
const paths = graphPaths.length > 0 ? graphPaths : [normalizeNodeModulesPath(pkgPath)];
|
|
56
69
|
const resolvedUrl = meta?.resolved;
|
|
57
70
|
const license = readLockfileLicense(meta?.license);
|
|
58
|
-
upsertPackage(map, {
|
|
71
|
+
upsertPackage(map, {
|
|
72
|
+
name, version, ecosystem: "npm", dev, paths, resolvedUrl, license,
|
|
73
|
+
...(registryName ? { registryName } : {}),
|
|
74
|
+
});
|
|
59
75
|
}
|
|
60
76
|
}
|
|
61
77
|
if (map.size === 0 && raw.dependencies && typeof raw.dependencies === "object") {
|
|
@@ -65,11 +81,15 @@ export function loadFromPackageLock(filePath, prodOnly) {
|
|
|
65
81
|
}
|
|
66
82
|
function walkLegacyDeps(deps, map, prodOnly, currentPath) {
|
|
67
83
|
for (const [name, meta] of Object.entries(deps)) {
|
|
68
|
-
const
|
|
84
|
+
const alias = parseNpmAliasVersion(meta?.version);
|
|
85
|
+
const version = alias?.version ?? meta?.version;
|
|
69
86
|
const dev = !!meta?.dev;
|
|
70
87
|
const nextPath = [...currentPath, name];
|
|
71
88
|
if (name && version && !(prodOnly && dev)) {
|
|
72
|
-
upsertPackage(map, {
|
|
89
|
+
upsertPackage(map, {
|
|
90
|
+
name, version, ecosystem: "npm", dev, paths: [nextPath],
|
|
91
|
+
...(alias ? { registryName: alias.registryName } : {}),
|
|
92
|
+
});
|
|
73
93
|
}
|
|
74
94
|
if (meta?.dependencies) {
|
|
75
95
|
walkLegacyDeps(meta.dependencies, map, prodOnly, nextPath);
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import YAML, { YAMLParseError } from "yaml";
|
|
3
3
|
import { looksLikeVersion, normalizeRawVersion } from "../utils/version.js";
|
|
4
|
-
import { upsertPackage } from "./utils.js";
|
|
4
|
+
import { upsertPackage, MAX_PATHS_PER_PACKAGE } from "./utils.js";
|
|
5
5
|
import { uniquePathArrays } from "../utils/array.js";
|
|
6
|
-
const MAX_PATHS_PER_PACKAGE = 5;
|
|
7
6
|
const MAX_PATH_DEPTH = 10;
|
|
8
7
|
function parsePnpmLockContent(content) {
|
|
9
8
|
try {
|
|
@@ -90,7 +89,9 @@ export function loadFromPnpmLock(filePath, prodOnly) {
|
|
|
90
89
|
}
|
|
91
90
|
function loadLegacy(parsed, prodOnly) {
|
|
92
91
|
const packagesSection = parsed?.packages ?? {};
|
|
93
|
-
|
|
92
|
+
// A single-project v5/v6 lockfile has no `importers`; the root's dependency
|
|
93
|
+
// sections sit at the top level instead.
|
|
94
|
+
const importers = parsed?.importers ?? { ".": parsed ?? {} };
|
|
94
95
|
const graph = new Map();
|
|
95
96
|
const map = new Map();
|
|
96
97
|
for (const [key, meta] of Object.entries(packagesSection)) {
|
|
@@ -134,6 +135,7 @@ function loadLegacy(parsed, prodOnly) {
|
|
|
134
135
|
name: String(depName),
|
|
135
136
|
version: fallbackVersion,
|
|
136
137
|
ecosystem: "npm",
|
|
138
|
+
dev: depSectionName === "devDependencies",
|
|
137
139
|
paths: [["project", String(depName)]]
|
|
138
140
|
});
|
|
139
141
|
}
|
|
@@ -204,6 +206,7 @@ function loadV9(parsed, prodOnly) {
|
|
|
204
206
|
name: String(depName),
|
|
205
207
|
version: fallbackVersion,
|
|
206
208
|
ecosystem: "npm",
|
|
209
|
+
dev: depSectionName === "devDependencies",
|
|
207
210
|
paths: [["project", String(depName)]]
|
|
208
211
|
});
|
|
209
212
|
// Unresolved fallback deps are not in the snapshot graph, so record their key
|
|
@@ -285,13 +288,22 @@ function pathsEqual(left, right) {
|
|
|
285
288
|
return false;
|
|
286
289
|
return left.every((value, index) => value === right[index]);
|
|
287
290
|
}
|
|
291
|
+
// Pre-v9 package keys come in two shapes. Lockfile v6 (pnpm 8) writes
|
|
292
|
+
// `/name@version` with peers in parentheses: `/react-dom@16.0.0(react@16.0.0)`.
|
|
293
|
+
// Lockfile v5 (pnpm 6 and 7) writes `/name/version` with peers after an
|
|
294
|
+
// underscore: `/react-dom/16.0.0_react@16.0.0`. Both are reduced to one
|
|
295
|
+
// canonical `/name/version` key so package entries and dependency refs meet.
|
|
288
296
|
export function parsePnpmPackageKey(key) {
|
|
289
297
|
const cleaned = key.replace(/^\//, "").split("(")[0];
|
|
290
|
-
const match = cleaned.match(/^(
|
|
298
|
+
const match = cleaned.match(/^(@[^/@]+\/[^/@]+|[^/@]+)@([^/]+)$/) ??
|
|
299
|
+
cleaned.match(/^(@?[^/]+(?:\/[^/]+)?)\/([^/]+)$/);
|
|
291
300
|
if (!match)
|
|
292
301
|
return null;
|
|
293
|
-
const
|
|
294
|
-
|
|
302
|
+
const name = match[1];
|
|
303
|
+
const version = match[2].replace(/_.*$/, "");
|
|
304
|
+
if (!version)
|
|
305
|
+
return null;
|
|
306
|
+
return { key: `/${name}/${version}`, name, version };
|
|
295
307
|
}
|
|
296
308
|
export function parsePnpmPackageKeyV9(key) {
|
|
297
309
|
// strip leading slash (pnpm v9 can emit /@babel/core@7.20.0) then peer-dep suffix (pkg@1.0.0(peer@2.0.0))
|
|
@@ -310,12 +322,14 @@ export function normalizePnpmDepRef(depName, depRef) {
|
|
|
310
322
|
const cleaned = depRef.replace(/^link:/, "").replace(/^workspace:/, "").split("(")[0];
|
|
311
323
|
if (!cleaned || cleaned.startsWith(".") || cleaned.startsWith(".."))
|
|
312
324
|
return null;
|
|
313
|
-
if (cleaned.
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
325
|
+
if (cleaned.includes("/")) {
|
|
326
|
+
const key = "/" + cleaned.replace(/^\//, "");
|
|
327
|
+
return parsePnpmPackageKey(key)?.key ?? null;
|
|
328
|
+
}
|
|
329
|
+
// Lockfile v5 appends resolved peers to the version: `16.0.0_react@16.0.0`.
|
|
330
|
+
const version = cleaned.replace(/_.*$/, "");
|
|
331
|
+
if (looksLikeVersion(version))
|
|
332
|
+
return `/${depName}/${version}`;
|
|
319
333
|
}
|
|
320
334
|
if (depRef && typeof depRef === "object") {
|
|
321
335
|
const version = depRef.version ?? depRef.specifier;
|
package/dist/parsers/utils.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { uniquePathArrays } from "../utils/array.js";
|
|
2
|
+
import { packageInstanceKey } from "../utils/package-identity.js";
|
|
3
|
+
export const MAX_PATHS_PER_PACKAGE = 5;
|
|
2
4
|
export function upsertPackage(map, candidate) {
|
|
3
|
-
const key =
|
|
5
|
+
const key = packageInstanceKey(candidate);
|
|
4
6
|
const existing = map.get(key);
|
|
5
7
|
if (!existing) {
|
|
6
|
-
map.set(key, { ...candidate, paths: uniquePathArrays(candidate.paths ?? []).slice(0,
|
|
8
|
+
map.set(key, { ...candidate, paths: uniquePathArrays(candidate.paths ?? []).slice(0, MAX_PATHS_PER_PACKAGE) });
|
|
7
9
|
return;
|
|
8
10
|
}
|
|
9
11
|
existing.dev = existing.dev && candidate.dev;
|
|
10
|
-
existing.paths = uniquePathArrays([...(existing.paths ?? []), ...(candidate.paths ?? [])]).slice(0,
|
|
12
|
+
existing.paths = uniquePathArrays([...(existing.paths ?? []), ...(candidate.paths ?? [])]).slice(0, MAX_PATHS_PER_PACKAGE);
|
|
11
13
|
// The same name@version can appear at several lockfile paths; keep the first
|
|
12
14
|
// license we see rather than losing it if a later entry omits the field.
|
|
13
15
|
existing.license ??= candidate.license;
|
|
@@ -83,8 +83,11 @@ function buildClassicIndex(parsed) {
|
|
|
83
83
|
continue;
|
|
84
84
|
const canonicalKey = `${selectors[0].slice(0, atIndex)}@${version}`;
|
|
85
85
|
const children = new Set();
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
// An optional dependency is installed whenever it can be, so its parent
|
|
87
|
+
// constrains the installed copy as much as a regular one does.
|
|
88
|
+
for (const deps of [meta?.dependencies, meta?.optionalDependencies]) {
|
|
89
|
+
if (!deps || typeof deps !== "object")
|
|
90
|
+
continue;
|
|
88
91
|
for (const [depName, depRange] of Object.entries(deps)) {
|
|
89
92
|
const childKey = selectorToKey.get(`${depName}@${depRange}`);
|
|
90
93
|
if (childKey)
|
|
@@ -2,8 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { parse as parseYarnLock } from "yarn-lockfile";
|
|
4
4
|
import { normalizeRawVersion } from "../utils/version.js";
|
|
5
|
-
import { upsertPackage } from "./utils.js";
|
|
6
|
-
const MAX_PATHS_PER_PACKAGE = 5;
|
|
5
|
+
import { upsertPackage, MAX_PATHS_PER_PACKAGE } from "./utils.js";
|
|
7
6
|
const MAX_PATH_DEPTH = 10;
|
|
8
7
|
// Record a display path for a package, matching the existing de-dup + cap behavior (keep the
|
|
9
8
|
// first MAX_PATHS_PER_PACKAGE unique paths, in insertion order).
|