cve-lite-cli 1.40.0 → 1.41.1
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 +17 -11
- 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 +4 -3
- package/dist/cli/validate.js +23 -1
- package/dist/constants.js +11 -25
- package/dist/index.js +8 -3
- package/dist/output/cyclonedx.js +23 -14
- package/dist/output/debug.js +68 -18
- package/dist/output/formatters.js +33 -5
- package/dist/output/html-reporter.js +55 -5
- package/dist/output/multi-folder-html-reporter.js +59 -3
- package/dist/output/output-dir.js +193 -7
- package/dist/output/override-fix-command.js +5 -7
- package/dist/output/printers.js +16 -5
- package/dist/output/sarif.js +131 -48
- package/dist/output/sbom-dependency-edges.js +16 -10
- package/dist/output/sbom-file.js +14 -6
- package/dist/output/scan-json.js +21 -3
- package/dist/output/spdx.js +61 -23
- package/dist/output/spinner.js +2 -1
- package/dist/output/write-outputs.js +142 -52
- package/dist/overrides/context-builder.js +23 -70
- package/dist/overrides/parsing/registry.js +19 -69
- 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 +3 -2
- package/dist/parsers/utils.js +5 -3
- package/dist/parsers/yarn-lock-graph.js +36 -17
- package/dist/parsers/yarn-lock.js +92 -25
- package/dist/remediation/fix-commands.js +101 -45
- package/dist/remediation/npm-registry.js +10 -2
- package/dist/remediation/npm-transitive-graph.js +30 -72
- package/dist/remediation/npm-transitive-resolution.js +24 -77
- package/dist/remediation/parent-upgrade-blockers.js +51 -0
- package/dist/remediation/parent-upgrade.js +5 -79
- package/dist/remediation/registry-parent-ranges.js +21 -0
- package/dist/remediation/transitive-chain-resolver.js +3 -3
- package/dist/scan/completeness.js +10 -4
- package/dist/scan/multi-folder-scan.js +133 -58
- package/dist/scan/override-audit.js +6 -4
- package/dist/scan/single-scan.js +41 -25
- package/dist/scanner.js +263 -58
- package/dist/usage/scanner.js +19 -8
- package/dist/utils/array.js +11 -3
- package/dist/utils/checked-address-policy.js +44 -0
- 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/file.js +2 -1
- package/dist/utils/fix-runner.js +95 -13
- package/dist/utils/import-type-queries.js +322 -0
- package/dist/utils/network.js +14 -9
- package/dist/utils/npm-lockfile.js +12 -0
- package/dist/utils/osv-fetch.js +34 -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 +47 -15
- package/dist/utils/registry-fetch.js +42 -0
- package/dist/utils/shell-quote.js +12 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/validate-url.js +1 -1
- package/dist/utils/version.js +30 -7
- 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/package.json +3 -2
|
@@ -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 {
|
|
@@ -136,6 +135,7 @@ function loadLegacy(parsed, prodOnly) {
|
|
|
136
135
|
name: String(depName),
|
|
137
136
|
version: fallbackVersion,
|
|
138
137
|
ecosystem: "npm",
|
|
138
|
+
dev: depSectionName === "devDependencies",
|
|
139
139
|
paths: [["project", String(depName)]]
|
|
140
140
|
});
|
|
141
141
|
}
|
|
@@ -206,6 +206,7 @@ function loadV9(parsed, prodOnly) {
|
|
|
206
206
|
name: String(depName),
|
|
207
207
|
version: fallbackVersion,
|
|
208
208
|
ecosystem: "npm",
|
|
209
|
+
dev: depSectionName === "devDependencies",
|
|
209
210
|
paths: [["project", String(depName)]]
|
|
210
211
|
});
|
|
211
212
|
// Unresolved fallback deps are not in the snapshot graph, so record their key
|
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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { parse as parseYarnLock } from "yarn-lockfile";
|
|
3
|
-
import { isYarnBerry, parseBerryDependencies, parseYarnPackageKey } from "./yarn-lock.js";
|
|
3
|
+
import { isYarnBerry, parseBerryDependencies, parseYarnClassicSelectorKey, parseYarnPackageKey } from "./yarn-lock.js";
|
|
4
4
|
const EMPTY = Object.freeze([]);
|
|
5
5
|
/**
|
|
6
6
|
* Builds the index for a Berry (v2+) lockfile.
|
|
@@ -51,7 +51,17 @@ function buildBerryIndex(content) {
|
|
|
51
51
|
}
|
|
52
52
|
graph.set(canonicalKey, [...children]);
|
|
53
53
|
}
|
|
54
|
-
return { selectorToKey, graph };
|
|
54
|
+
return { selectorToKey, graph, registryNameByKey: new Map() };
|
|
55
|
+
}
|
|
56
|
+
function classicCanonicalKey(selectorKey, version) {
|
|
57
|
+
const identity = parseYarnClassicSelectorKey(selectorKey);
|
|
58
|
+
if (!identity)
|
|
59
|
+
return null;
|
|
60
|
+
return {
|
|
61
|
+
key: `${identity.name}@${version}`,
|
|
62
|
+
selectors: identity.selectors,
|
|
63
|
+
...(identity.registryName ? { registryName: identity.registryName } : {}),
|
|
64
|
+
};
|
|
55
65
|
}
|
|
56
66
|
/**
|
|
57
67
|
* Builds the index for a classic (v1) lockfile, which the `yarn-lockfile`
|
|
@@ -60,40 +70,42 @@ function buildBerryIndex(content) {
|
|
|
60
70
|
function buildClassicIndex(parsed) {
|
|
61
71
|
const selectorToKey = new Map();
|
|
62
72
|
const graph = new Map();
|
|
73
|
+
const registryNameByKey = new Map();
|
|
63
74
|
const entries = Object.entries(parsed?.object ?? {});
|
|
64
75
|
for (const [selectorKey, meta] of entries) {
|
|
65
76
|
const version = meta?.version;
|
|
66
77
|
if (!version)
|
|
67
78
|
continue;
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
if (atIndex <= 0)
|
|
79
|
+
const entry = classicCanonicalKey(selectorKey, version);
|
|
80
|
+
if (!entry)
|
|
71
81
|
continue;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
if (entry.registryName)
|
|
83
|
+
registryNameByKey.set(entry.key, entry.registryName);
|
|
84
|
+
for (const selector of entry.selectors)
|
|
85
|
+
selectorToKey.set(selector, entry.key);
|
|
75
86
|
}
|
|
76
87
|
for (const [selectorKey, meta] of entries) {
|
|
77
88
|
const version = meta?.version;
|
|
78
89
|
if (!version)
|
|
79
90
|
continue;
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
if (atIndex <= 0)
|
|
91
|
+
const entry = classicCanonicalKey(selectorKey, version);
|
|
92
|
+
if (!entry)
|
|
83
93
|
continue;
|
|
84
|
-
const canonicalKey = `${selectors[0].slice(0, atIndex)}@${version}`;
|
|
85
94
|
const children = new Set();
|
|
86
|
-
|
|
87
|
-
|
|
95
|
+
// An optional dependency is installed whenever it can be, so its parent
|
|
96
|
+
// constrains the installed copy as much as a regular one does.
|
|
97
|
+
for (const deps of [meta?.dependencies, meta?.optionalDependencies]) {
|
|
98
|
+
if (!deps || typeof deps !== "object")
|
|
99
|
+
continue;
|
|
88
100
|
for (const [depName, depRange] of Object.entries(deps)) {
|
|
89
101
|
const childKey = selectorToKey.get(`${depName}@${depRange}`);
|
|
90
102
|
if (childKey)
|
|
91
103
|
children.add(childKey);
|
|
92
104
|
}
|
|
93
105
|
}
|
|
94
|
-
graph.set(
|
|
106
|
+
graph.set(entry.key, [...children]);
|
|
95
107
|
}
|
|
96
|
-
return { selectorToKey, graph };
|
|
108
|
+
return { selectorToKey, graph, registryNameByKey };
|
|
97
109
|
}
|
|
98
110
|
/**
|
|
99
111
|
* Builds the complete child-to-parents map for a `yarn.lock`, covering both the
|
|
@@ -142,7 +154,14 @@ export function loadYarnLockGraph(filePath) {
|
|
|
142
154
|
parentsFor: nodeId => parentsByKey.get(nodeId) ?? EMPTY,
|
|
143
155
|
getNode: nodeId => {
|
|
144
156
|
const parsedKey = parseYarnPackageKey(nodeId);
|
|
145
|
-
|
|
157
|
+
if (!parsedKey)
|
|
158
|
+
return null;
|
|
159
|
+
const registryName = index.registryNameByKey.get(nodeId);
|
|
160
|
+
return {
|
|
161
|
+
name: parsedKey.name,
|
|
162
|
+
version: parsedKey.version,
|
|
163
|
+
...(registryName ? { registryName } : {}),
|
|
164
|
+
};
|
|
146
165
|
},
|
|
147
166
|
};
|
|
148
167
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { parse as parseYarnLock } from "yarn-lockfile";
|
|
4
|
+
import { npmAliasRegistryName, packageInstanceKey } from "../utils/package-identity.js";
|
|
4
5
|
import { normalizeRawVersion } from "../utils/version.js";
|
|
5
|
-
import { upsertPackage } from "./utils.js";
|
|
6
|
-
const MAX_PATHS_PER_PACKAGE = 5;
|
|
6
|
+
import { upsertPackage, MAX_PATHS_PER_PACKAGE } from "./utils.js";
|
|
7
7
|
const MAX_PATH_DEPTH = 10;
|
|
8
8
|
// Record a display path for a package, matching the existing de-dup + cap behavior (keep the
|
|
9
9
|
// first MAX_PATHS_PER_PACKAGE unique paths, in insertion order).
|
|
@@ -145,6 +145,75 @@ export function parseYarnPackageKey(key) {
|
|
|
145
145
|
return null;
|
|
146
146
|
return { key, name, version };
|
|
147
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Yarn v1 records an alias as `<alias>@npm:<package>@<range>`.
|
|
150
|
+
*
|
|
151
|
+
* `yarn 1.22` quotes that key. A scoped target keeps the leading `@` after the
|
|
152
|
+
* protocol (`frames@npm:@babel/code-frame@7.23.5`), and a scoped alias keeps
|
|
153
|
+
* its own (`@my/frames@npm:@babel/code-frame@7.23.5`). The range in the key is
|
|
154
|
+
* what was requested. The installed version is the lockfile `version` field,
|
|
155
|
+
* so this only returns names.
|
|
156
|
+
*
|
|
157
|
+
* A normal key (`lodash@4.17.20`, `@babel/code-frame@^7.23.4`) has no `@npm:`
|
|
158
|
+
* marker. Splitting those on the final `@` is still the package name. Doing
|
|
159
|
+
* that to an alias key yields `util-lib@npm:lodash`, which is not a package
|
|
160
|
+
* OSV knows about.
|
|
161
|
+
*/
|
|
162
|
+
export function parseYarnClassicDescriptor(selector) {
|
|
163
|
+
const marker = "@npm:";
|
|
164
|
+
const markerAt = selector.indexOf(marker);
|
|
165
|
+
if (markerAt > 0) {
|
|
166
|
+
const name = selector.slice(0, markerAt);
|
|
167
|
+
const target = selector.slice(markerAt + marker.length);
|
|
168
|
+
if (!name || !target)
|
|
169
|
+
return null;
|
|
170
|
+
// One definition of an alias target, shared with npm lockfiles: a later `@`
|
|
171
|
+
// starts the requested range, and the leading `@` of `@scope/pkg` does not.
|
|
172
|
+
const registryName = npmAliasRegistryName("npm:" + target);
|
|
173
|
+
if (!registryName)
|
|
174
|
+
return null;
|
|
175
|
+
// `lodash@npm:lodash@4.17.20` is the same package under its own name.
|
|
176
|
+
if (registryName === name)
|
|
177
|
+
return { name };
|
|
178
|
+
return { name, registryName };
|
|
179
|
+
}
|
|
180
|
+
const atIndex = selector.lastIndexOf("@");
|
|
181
|
+
if (atIndex <= 0)
|
|
182
|
+
return null;
|
|
183
|
+
const name = selector.slice(0, atIndex);
|
|
184
|
+
if (!name)
|
|
185
|
+
return null;
|
|
186
|
+
return { name };
|
|
187
|
+
}
|
|
188
|
+
/** Every descriptor in one Yarn v1 entry, and the package the first one names. */
|
|
189
|
+
export function parseYarnClassicSelectorKey(selectorKey) {
|
|
190
|
+
const selectors = String(selectorKey).split(",").map(part => part.trim()).filter(Boolean);
|
|
191
|
+
const identity = selectors[0] ? parseYarnClassicDescriptor(selectors[0]) : null;
|
|
192
|
+
if (!identity)
|
|
193
|
+
return null;
|
|
194
|
+
return {
|
|
195
|
+
name: identity.name,
|
|
196
|
+
...(identity.registryName ? { registryName: identity.registryName } : {}),
|
|
197
|
+
selectors,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function readYarnClassicEntry(selectorKey, meta) {
|
|
201
|
+
const version = meta?.version;
|
|
202
|
+
if (typeof version !== "string" || version.length === 0)
|
|
203
|
+
return null;
|
|
204
|
+
const identity = parseYarnClassicSelectorKey(selectorKey);
|
|
205
|
+
if (!identity)
|
|
206
|
+
return null;
|
|
207
|
+
return {
|
|
208
|
+
...identity,
|
|
209
|
+
version,
|
|
210
|
+
instanceKey: packageInstanceKey({
|
|
211
|
+
name: identity.name,
|
|
212
|
+
registryName: identity.registryName,
|
|
213
|
+
version,
|
|
214
|
+
}),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
148
217
|
function collectYarnPaths(seeds, graph, map, taggedPathsByKey) {
|
|
149
218
|
const queue = seeds.map(seed => ({ key: seed.key, path: seed.path }));
|
|
150
219
|
const visitedStates = new Set();
|
|
@@ -154,7 +223,12 @@ function collectYarnPaths(seeds, graph, map, taggedPathsByKey) {
|
|
|
154
223
|
const ref = parseYarnPackageKey(current.key);
|
|
155
224
|
if (!ref)
|
|
156
225
|
continue;
|
|
157
|
-
|
|
226
|
+
// An aliased entry's canonical key is `alias\0registry@version`. The path
|
|
227
|
+
// shows the name that was installed, which is the part before the NUL.
|
|
228
|
+
const installName = ref.name.split("\0")[0];
|
|
229
|
+
if (!installName)
|
|
230
|
+
continue;
|
|
231
|
+
const nextPath = [...current.path, installName];
|
|
158
232
|
const stateKey = `${ref.key}>${nextPath.join(">")}`;
|
|
159
233
|
if (visitedStates.has(stateKey))
|
|
160
234
|
continue;
|
|
@@ -303,32 +377,25 @@ function loadFromYarnClassicLock(parsed, filePath) {
|
|
|
303
377
|
const graph = new Map();
|
|
304
378
|
const selectorToKey = new Map();
|
|
305
379
|
for (const [selectorKey, meta] of Object.entries(parsed.object)) {
|
|
306
|
-
const
|
|
307
|
-
if (!
|
|
380
|
+
const entry = readYarnClassicEntry(selectorKey, meta);
|
|
381
|
+
if (!entry)
|
|
308
382
|
continue;
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
const atIndex = firstSelector.lastIndexOf("@");
|
|
312
|
-
if (atIndex <= 0)
|
|
313
|
-
continue;
|
|
314
|
-
const name = firstSelector.slice(0, atIndex);
|
|
315
|
-
const canonicalKey = `${name}@${version}`;
|
|
316
|
-
for (const selector of selectors) {
|
|
317
|
-
selectorToKey.set(selector, canonicalKey);
|
|
383
|
+
for (const selector of entry.selectors) {
|
|
384
|
+
selectorToKey.set(selector, entry.instanceKey);
|
|
318
385
|
}
|
|
319
|
-
upsertPackage(map, {
|
|
386
|
+
upsertPackage(map, {
|
|
387
|
+
name: entry.name,
|
|
388
|
+
version: entry.version,
|
|
389
|
+
ecosystem: "npm",
|
|
390
|
+
paths: [],
|
|
391
|
+
resolvedUrl: meta?.resolved,
|
|
392
|
+
...(entry.registryName ? { registryName: entry.registryName } : {}),
|
|
393
|
+
});
|
|
320
394
|
}
|
|
321
395
|
for (const [selectorKey, meta] of Object.entries(parsed.object)) {
|
|
322
|
-
const
|
|
323
|
-
if (!
|
|
324
|
-
continue;
|
|
325
|
-
const selectors = String(selectorKey).split(",").map(selector => selector.trim()).filter(Boolean);
|
|
326
|
-
const firstSelector = selectors[0];
|
|
327
|
-
const atIndex = firstSelector.lastIndexOf("@");
|
|
328
|
-
if (atIndex <= 0)
|
|
396
|
+
const entry = readYarnClassicEntry(selectorKey, meta);
|
|
397
|
+
if (!entry)
|
|
329
398
|
continue;
|
|
330
|
-
const name = firstSelector.slice(0, atIndex);
|
|
331
|
-
const canonicalKey = `${name}@${version}`;
|
|
332
399
|
const depKeys = new Set();
|
|
333
400
|
const deps = meta?.dependencies;
|
|
334
401
|
if (deps && typeof deps === "object") {
|
|
@@ -338,7 +405,7 @@ function loadFromYarnClassicLock(parsed, filePath) {
|
|
|
338
405
|
depKeys.add(childKey);
|
|
339
406
|
}
|
|
340
407
|
}
|
|
341
|
-
graph.set(
|
|
408
|
+
graph.set(entry.instanceKey, [...depKeys]);
|
|
342
409
|
}
|
|
343
410
|
const taggedPathsByKey = new Map();
|
|
344
411
|
const prodFallbackKeys = new Set();
|