cve-lite-cli 1.19.1 → 1.20.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 -1
- package/dist/cli/args.js +18 -0
- package/dist/cli/help.js +13 -7
- package/dist/cli/validate.js +9 -0
- package/dist/constants.js +4 -0
- package/dist/index.js +35 -4
- package/dist/output/formatters.js +8 -1
- package/dist/output/html-reporter.js +45 -26
- package/dist/output/printers.js +48 -12
- package/dist/parsers/bun-lock.js +75 -5
- package/dist/parsers/index.js +17 -12
- package/dist/parsers/package-lock.js +2 -1
- package/dist/parsers/yarn-lock.js +174 -15
- package/dist/remediation/fix-commands.js +3 -2
- package/dist/remediation/npm-transitive-resolution.js +43 -4
- package/dist/scanner.js +19 -3
- package/dist/utils/advisory.js +6 -0
- package/dist/utils/create-pr.js +212 -0
- package/package.json +1 -1
package/dist/parsers/bun-lock.js
CHANGED
|
@@ -1,9 +1,58 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import { uniquePathArrays } from "../utils/array.js";
|
|
2
3
|
import { upsertPackage } from "./utils.js";
|
|
4
|
+
const MAX_PATHS_PER_PACKAGE = 5;
|
|
5
|
+
const MAX_PATH_DEPTH = 10;
|
|
3
6
|
function parseJsonc(text) {
|
|
4
7
|
// bun.lock uses JSONC (trailing commas). Strip them before parsing.
|
|
5
8
|
return JSON.parse(text.replace(/,(\s*[}\]])/g, "$1"));
|
|
6
9
|
}
|
|
10
|
+
function extractChildDependencyNames(depMeta) {
|
|
11
|
+
if (!depMeta || typeof depMeta !== "object")
|
|
12
|
+
return [];
|
|
13
|
+
const names = new Set();
|
|
14
|
+
const meta = depMeta;
|
|
15
|
+
for (const section of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
16
|
+
const sectionObj = meta[section];
|
|
17
|
+
if (!sectionObj || typeof sectionObj !== "object")
|
|
18
|
+
continue;
|
|
19
|
+
for (const name of Object.keys(sectionObj)) {
|
|
20
|
+
names.add(name);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
for (const [key, value] of Object.entries(meta)) {
|
|
24
|
+
if (key === "dependencies" || key === "optionalDependencies" || key === "devDependencies")
|
|
25
|
+
continue;
|
|
26
|
+
if (typeof value === "string") {
|
|
27
|
+
names.add(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return [...names];
|
|
31
|
+
}
|
|
32
|
+
function collectBunPaths(rootDepNames, childDepsByPackageName, map, packageNameToVersion) {
|
|
33
|
+
const queue = rootDepNames.map(name => ({ name, path: ["project"] }));
|
|
34
|
+
const visitedStates = new Set();
|
|
35
|
+
while (queue.length > 0) {
|
|
36
|
+
const current = queue.shift();
|
|
37
|
+
const nextPath = [...current.path, current.name];
|
|
38
|
+
const version = packageNameToVersion.get(current.name);
|
|
39
|
+
const stateKey = `${current.name}@${version ?? ""}>${nextPath.join(">")}`;
|
|
40
|
+
if (visitedStates.has(stateKey))
|
|
41
|
+
continue;
|
|
42
|
+
visitedStates.add(stateKey);
|
|
43
|
+
if (version) {
|
|
44
|
+
const pkg = map.get(`${current.name}@${version}`);
|
|
45
|
+
if (pkg) {
|
|
46
|
+
pkg.paths = uniquePathArrays([...(pkg.paths ?? []), nextPath]).slice(0, MAX_PATHS_PER_PACKAGE);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (nextPath.length >= MAX_PATH_DEPTH)
|
|
50
|
+
continue;
|
|
51
|
+
for (const child of childDepsByPackageName.get(current.name) ?? []) {
|
|
52
|
+
queue.push({ name: child, path: nextPath });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
7
56
|
export function buildBunWorkspaceMap(filePath) {
|
|
8
57
|
const raw = parseJsonc(fs.readFileSync(filePath, "utf8"));
|
|
9
58
|
const workspaces = raw?.workspaces ?? {};
|
|
@@ -28,9 +77,11 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
28
77
|
const packages = raw?.packages ?? {};
|
|
29
78
|
const workspaces = raw?.workspaces ?? {};
|
|
30
79
|
const map = new Map();
|
|
31
|
-
|
|
80
|
+
const childDepsByPackageName = new Map();
|
|
81
|
+
const packageNameToVersion = new Map();
|
|
32
82
|
const prodNames = new Set();
|
|
33
83
|
const devNames = new Set();
|
|
84
|
+
const rootDepNames = [];
|
|
34
85
|
for (const workspace of Object.values(workspaces)) {
|
|
35
86
|
for (const name of Object.keys(workspace?.dependencies ?? {})) {
|
|
36
87
|
prodNames.add(name);
|
|
@@ -39,11 +90,24 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
39
90
|
devNames.add(name);
|
|
40
91
|
}
|
|
41
92
|
}
|
|
93
|
+
for (const [workspacePath, workspace] of Object.entries(workspaces)) {
|
|
94
|
+
if (workspacePath !== "")
|
|
95
|
+
continue;
|
|
96
|
+
for (const depSectionName of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
97
|
+
if (prodOnly && depSectionName === "devDependencies")
|
|
98
|
+
continue;
|
|
99
|
+
const depSection = workspace?.[depSectionName];
|
|
100
|
+
if (!depSection || typeof depSection !== "object")
|
|
101
|
+
continue;
|
|
102
|
+
for (const depName of Object.keys(depSection)) {
|
|
103
|
+
rootDepNames.push(depName);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
42
107
|
for (const [pkgName, entry] of Object.entries(packages)) {
|
|
43
108
|
if (!Array.isArray(entry) || entry.length < 1)
|
|
44
109
|
continue;
|
|
45
110
|
const nameAtVersion = String(entry[0] ?? "");
|
|
46
|
-
// Split on last @ to handle scoped packages (e.g. @babel/core@7.0.0)
|
|
47
111
|
const atIndex = nameAtVersion.lastIndexOf("@");
|
|
48
112
|
if (atIndex <= 0)
|
|
49
113
|
continue;
|
|
@@ -51,8 +115,8 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
51
115
|
const version = nameAtVersion.slice(atIndex + 1);
|
|
52
116
|
if (!name || !version)
|
|
53
117
|
continue;
|
|
54
|
-
|
|
55
|
-
|
|
118
|
+
packageNameToVersion.set(pkgName, version);
|
|
119
|
+
childDepsByPackageName.set(pkgName, extractChildDependencyNames(entry[2]));
|
|
56
120
|
const dev = devNames.has(pkgName) && !prodNames.has(pkgName);
|
|
57
121
|
if (prodOnly && dev)
|
|
58
122
|
continue;
|
|
@@ -61,8 +125,14 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
61
125
|
version,
|
|
62
126
|
ecosystem: "npm",
|
|
63
127
|
dev,
|
|
64
|
-
paths: [
|
|
128
|
+
paths: [],
|
|
65
129
|
});
|
|
66
130
|
}
|
|
131
|
+
collectBunPaths(rootDepNames, childDepsByPackageName, map, packageNameToVersion);
|
|
132
|
+
for (const [pkgKey, pkg] of map.entries()) {
|
|
133
|
+
if ((pkg.paths?.length ?? 0) === 0) {
|
|
134
|
+
pkg.paths = [["project", pkg.name]];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
67
137
|
return [...map.values()];
|
|
68
138
|
}
|
package/dist/parsers/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
20
20
|
packages: loadFromBunLock(rootBunLock, prodOnly),
|
|
21
21
|
notes: [
|
|
22
22
|
"Scanned resolved dependency versions from bun.lock.",
|
|
23
|
-
"Dependency paths are
|
|
23
|
+
"Dependency paths are derived from bun.lock package relationships."
|
|
24
24
|
],
|
|
25
25
|
warnings: [],
|
|
26
26
|
skippedDependencies: []
|
|
@@ -76,7 +76,7 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
76
76
|
packages: loadFromYarnLock(rootYarnLock),
|
|
77
77
|
notes: [
|
|
78
78
|
"Scanned resolved dependency versions from yarn.lock.",
|
|
79
|
-
"Dependency
|
|
79
|
+
"Dependency paths are derived from yarn.lock package relationships."
|
|
80
80
|
],
|
|
81
81
|
warnings: [],
|
|
82
82
|
skippedDependencies: []
|
|
@@ -94,9 +94,10 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
94
94
|
packages: loadFromBunLock(selected, prodOnly),
|
|
95
95
|
notes: [
|
|
96
96
|
`Scanned resolved dependency versions from ${relativeOrName(projectRoot, selected)}.`,
|
|
97
|
-
"Dependency paths are
|
|
97
|
+
"Dependency paths are derived from bun.lock package relationships.",
|
|
98
|
+
"No supported lockfile was found at the repo root — a nested lockfile was used instead."
|
|
98
99
|
],
|
|
99
|
-
warnings: [
|
|
100
|
+
warnings: [],
|
|
100
101
|
skippedDependencies: []
|
|
101
102
|
};
|
|
102
103
|
}
|
|
@@ -108,9 +109,10 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
108
109
|
packages: loadFromPackageLock(selected, prodOnly),
|
|
109
110
|
notes: [
|
|
110
111
|
`Scanned resolved dependency versions from ${relativeOrName(projectRoot, selected)}.`,
|
|
111
|
-
"Dependency paths are derived from lockfile package locations."
|
|
112
|
+
"Dependency paths are derived from lockfile package locations.",
|
|
113
|
+
"No supported lockfile was found at the repo root — a nested lockfile was used instead."
|
|
112
114
|
],
|
|
113
|
-
warnings: [
|
|
115
|
+
warnings: [],
|
|
114
116
|
skippedDependencies: []
|
|
115
117
|
};
|
|
116
118
|
}
|
|
@@ -122,9 +124,10 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
122
124
|
packages: loadFromPackageLock(selected, prodOnly),
|
|
123
125
|
notes: [
|
|
124
126
|
`Scanned resolved dependency versions from ${relativeOrName(projectRoot, selected)}.`,
|
|
125
|
-
"Dependency paths are derived from lockfile package locations."
|
|
127
|
+
"Dependency paths are derived from lockfile package locations.",
|
|
128
|
+
"No supported lockfile was found at the repo root — a nested lockfile was used instead."
|
|
126
129
|
],
|
|
127
|
-
warnings: [
|
|
130
|
+
warnings: [],
|
|
128
131
|
skippedDependencies: []
|
|
129
132
|
};
|
|
130
133
|
}
|
|
@@ -136,9 +139,10 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
136
139
|
packages: loadFromPnpmLock(selected, prodOnly),
|
|
137
140
|
notes: [
|
|
138
141
|
`Scanned resolved dependency versions from ${relativeOrName(projectRoot, selected)}.`,
|
|
139
|
-
"Dependency paths are approximated from importer relationships and package snapshots."
|
|
142
|
+
"Dependency paths are approximated from importer relationships and package snapshots.",
|
|
143
|
+
"No supported lockfile was found at the repo root — a nested lockfile was used instead."
|
|
140
144
|
],
|
|
141
|
-
warnings: [
|
|
145
|
+
warnings: [],
|
|
142
146
|
skippedDependencies: []
|
|
143
147
|
};
|
|
144
148
|
}
|
|
@@ -149,9 +153,10 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
149
153
|
packages: loadFromYarnLock(selected),
|
|
150
154
|
notes: [
|
|
151
155
|
`Scanned resolved dependency versions from ${relativeOrName(projectRoot, selected)}.`,
|
|
152
|
-
"Dependency
|
|
156
|
+
"Dependency paths are derived from yarn.lock package relationships.",
|
|
157
|
+
"No supported lockfile was found at the repo root — a nested lockfile was used instead."
|
|
153
158
|
],
|
|
154
|
-
warnings: [
|
|
159
|
+
warnings: [],
|
|
155
160
|
skippedDependencies: []
|
|
156
161
|
};
|
|
157
162
|
}
|
|
@@ -44,7 +44,8 @@ export function loadFromPackageLock(filePath, prodOnly) {
|
|
|
44
44
|
const nodeIds = graph.nodeIdsFor(name, version);
|
|
45
45
|
const graphPaths = nodeIds.flatMap(id => graph.pathsFor(id));
|
|
46
46
|
const paths = graphPaths.length > 0 ? graphPaths : [normalizeNodeModulesPath(pkgPath)];
|
|
47
|
-
|
|
47
|
+
const resolvedUrl = meta?.resolved;
|
|
48
|
+
upsertPackage(map, { name, version, ecosystem: "npm", dev, paths, resolvedUrl });
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
if (map.size === 0 && raw.dependencies && typeof raw.dependencies === "object") {
|
|
@@ -1,7 +1,11 @@
|
|
|
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 { uniquePathArrays } from "../utils/array.js";
|
|
5
|
+
import { normalizeRawVersion } from "../utils/version.js";
|
|
4
6
|
import { upsertPackage } from "./utils.js";
|
|
7
|
+
const MAX_PATHS_PER_PACKAGE = 5;
|
|
8
|
+
const MAX_PATH_DEPTH = 10;
|
|
5
9
|
export function buildYarnWorkspaceMap(filePath) {
|
|
6
10
|
const dir = path.dirname(filePath);
|
|
7
11
|
const map = new Map();
|
|
@@ -64,13 +68,113 @@ export function buildYarnWorkspaceMap(filePath) {
|
|
|
64
68
|
function isYarnBerry(content) {
|
|
65
69
|
return content.startsWith('__metadata:') || content.includes('\n__metadata:');
|
|
66
70
|
}
|
|
67
|
-
function
|
|
71
|
+
function pathsEqual(left, right) {
|
|
72
|
+
if (left.length !== right.length)
|
|
73
|
+
return false;
|
|
74
|
+
return left.every((value, index) => value === right[index]);
|
|
75
|
+
}
|
|
76
|
+
function parseYarnPackageKey(key) {
|
|
77
|
+
const idx = key.lastIndexOf("@");
|
|
78
|
+
if (idx <= 0)
|
|
79
|
+
return null;
|
|
80
|
+
const name = key.slice(0, idx);
|
|
81
|
+
const version = key.slice(idx + 1);
|
|
82
|
+
if (!name || !version)
|
|
83
|
+
return null;
|
|
84
|
+
return { key, name, version };
|
|
85
|
+
}
|
|
86
|
+
function collectYarnPaths(rootDepKeys, graph, map) {
|
|
87
|
+
const queue = rootDepKeys.map(key => ({ key, path: ["project"] }));
|
|
88
|
+
const visitedStates = new Set();
|
|
89
|
+
while (queue.length > 0) {
|
|
90
|
+
const current = queue.shift();
|
|
91
|
+
const ref = parseYarnPackageKey(current.key);
|
|
92
|
+
if (!ref)
|
|
93
|
+
continue;
|
|
94
|
+
const nextPath = [...current.path, ref.name];
|
|
95
|
+
const stateKey = `${ref.key}>${nextPath.join(">")}`;
|
|
96
|
+
if (visitedStates.has(stateKey))
|
|
97
|
+
continue;
|
|
98
|
+
visitedStates.add(stateKey);
|
|
99
|
+
const pkg = map.get(ref.key);
|
|
100
|
+
if (pkg) {
|
|
101
|
+
pkg.paths = uniquePathArrays([...(pkg.paths ?? []), nextPath]).slice(0, MAX_PATHS_PER_PACKAGE);
|
|
102
|
+
}
|
|
103
|
+
if (nextPath.length >= MAX_PATH_DEPTH)
|
|
104
|
+
continue;
|
|
105
|
+
if ((pkg?.paths?.length ?? 0) >= MAX_PATHS_PER_PACKAGE && !(pkg?.paths ?? []).some(path => pathsEqual(path, nextPath))) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
for (const child of graph.get(ref.key) ?? []) {
|
|
109
|
+
queue.push({ key: child, path: nextPath });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function loadRootDepKeys(filePath, selectorToKey, map) {
|
|
114
|
+
const dir = path.dirname(filePath);
|
|
115
|
+
let rootPkg;
|
|
116
|
+
try {
|
|
117
|
+
rootPkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
const rootDepKeys = [];
|
|
123
|
+
for (const depSection of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
124
|
+
const deps = rootPkg[depSection];
|
|
125
|
+
if (!deps || typeof deps !== "object")
|
|
126
|
+
continue;
|
|
127
|
+
for (const [depName, depRange] of Object.entries(deps)) {
|
|
128
|
+
const resolved = selectorToKey.get(`${depName}@${depRange}`) ??
|
|
129
|
+
selectorToKey.get(`${depName}@npm:${depRange}`);
|
|
130
|
+
if (resolved) {
|
|
131
|
+
rootDepKeys.push(resolved);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const fallbackVersion = normalizeRawVersion(depRange);
|
|
135
|
+
if (fallbackVersion) {
|
|
136
|
+
upsertPackage(map, {
|
|
137
|
+
name: String(depName),
|
|
138
|
+
version: fallbackVersion,
|
|
139
|
+
ecosystem: "npm",
|
|
140
|
+
paths: [["project", String(depName)]],
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return rootDepKeys;
|
|
146
|
+
}
|
|
147
|
+
function parseBerryDependencies(block) {
|
|
148
|
+
const dependencies = {};
|
|
149
|
+
const lines = block.split("\n");
|
|
150
|
+
let inDependencies = false;
|
|
151
|
+
for (const line of lines) {
|
|
152
|
+
if (/^\s*dependencies:\s*$/.test(line)) {
|
|
153
|
+
inDependencies = true;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (!inDependencies)
|
|
157
|
+
continue;
|
|
158
|
+
const depMatch = line.match(/^\s{2,}([^:]+):\s*(.+)$/);
|
|
159
|
+
if (!depMatch) {
|
|
160
|
+
if (!/^\s/.test(line))
|
|
161
|
+
inDependencies = false;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
dependencies[depMatch[1].trim().replace(/^"|"$/g, "")] = depMatch[2].trim().replace(/^"|"$/g, "");
|
|
165
|
+
}
|
|
166
|
+
return dependencies;
|
|
167
|
+
}
|
|
168
|
+
function loadFromYarnBerryLock(content, filePath) {
|
|
68
169
|
const map = new Map();
|
|
170
|
+
const graph = new Map();
|
|
171
|
+
const selectorToKey = new Map();
|
|
69
172
|
const blocks = content.split(/\n\n+/);
|
|
70
173
|
for (const block of blocks) {
|
|
71
174
|
const lines = block.trim().split('\n');
|
|
72
175
|
if (!lines[0] || lines[0].startsWith('__metadata'))
|
|
73
176
|
continue;
|
|
177
|
+
const selectorLine = lines[0].trim().replace(/:$/, "").replace(/^"|"$/g, "");
|
|
74
178
|
const resolutionLine = lines.find((l) => l.trim().startsWith('resolution:'));
|
|
75
179
|
if (!resolutionLine)
|
|
76
180
|
continue;
|
|
@@ -85,32 +189,87 @@ function loadFromYarnBerryLock(content) {
|
|
|
85
189
|
const version = resolution.slice(npmIdx + 5);
|
|
86
190
|
if (!name || !version)
|
|
87
191
|
continue;
|
|
88
|
-
|
|
192
|
+
const canonicalKey = `${name}@${version}`;
|
|
193
|
+
for (const selector of selectorLine.split(",").map(part => part.trim()).filter(Boolean)) {
|
|
194
|
+
selectorToKey.set(selector, canonicalKey);
|
|
195
|
+
}
|
|
196
|
+
upsertPackage(map, { name, version, ecosystem: 'npm', paths: [] });
|
|
197
|
+
}
|
|
198
|
+
for (const block of blocks) {
|
|
199
|
+
const lines = block.trim().split('\n');
|
|
200
|
+
if (!lines[0] || lines[0].startsWith('__metadata'))
|
|
201
|
+
continue;
|
|
202
|
+
const selectorLine = lines[0].trim().replace(/:$/, "").replace(/^"|"$/g, "");
|
|
203
|
+
const canonicalKey = selectorToKey.get(selectorLine.split(",").map(part => part.trim()).find(part => selectorToKey.has(part)) ?? selectorLine) ?? selectorToKey.get(selectorLine);
|
|
204
|
+
if (!canonicalKey)
|
|
205
|
+
continue;
|
|
206
|
+
const depKeys = new Set();
|
|
207
|
+
for (const [depName, depRef] of Object.entries(parseBerryDependencies(block))) {
|
|
208
|
+
const childSelector = depRef.startsWith("npm:") ? `${depName}@${depRef}` : `${depName}@${depRef}`;
|
|
209
|
+
const childKey = selectorToKey.get(childSelector);
|
|
210
|
+
if (childKey)
|
|
211
|
+
depKeys.add(childKey);
|
|
212
|
+
}
|
|
213
|
+
graph.set(canonicalKey, [...depKeys]);
|
|
89
214
|
}
|
|
215
|
+
const rootDepKeys = loadRootDepKeys(filePath, selectorToKey, map);
|
|
216
|
+
collectYarnPaths(rootDepKeys, graph, map);
|
|
90
217
|
return [...map.values()];
|
|
91
218
|
}
|
|
92
|
-
|
|
93
|
-
const content = fs.readFileSync(filePath, "utf8");
|
|
94
|
-
if (isYarnBerry(content)) {
|
|
95
|
-
return loadFromYarnBerryLock(content);
|
|
96
|
-
}
|
|
97
|
-
const parsed = parseYarnLock(content);
|
|
98
|
-
if (parsed.type !== "success" || !parsed.object) {
|
|
99
|
-
throw new Error("Could not parse yarn.lock");
|
|
100
|
-
}
|
|
219
|
+
function loadFromYarnClassicLock(parsed, filePath) {
|
|
101
220
|
const map = new Map();
|
|
102
|
-
|
|
221
|
+
const graph = new Map();
|
|
222
|
+
const selectorToKey = new Map();
|
|
223
|
+
for (const [selectorKey, meta] of Object.entries(parsed.object)) {
|
|
103
224
|
const version = meta?.version;
|
|
104
225
|
if (!version)
|
|
105
226
|
continue;
|
|
106
|
-
const
|
|
227
|
+
const selectors = String(selectorKey).split(",").map(selector => selector.trim()).filter(Boolean);
|
|
228
|
+
const firstSelector = selectors[0];
|
|
107
229
|
const atIndex = firstSelector.lastIndexOf("@");
|
|
108
230
|
if (atIndex <= 0)
|
|
109
231
|
continue;
|
|
110
232
|
const name = firstSelector.slice(0, atIndex);
|
|
111
|
-
|
|
233
|
+
const canonicalKey = `${name}@${version}`;
|
|
234
|
+
for (const selector of selectors) {
|
|
235
|
+
selectorToKey.set(selector, canonicalKey);
|
|
236
|
+
}
|
|
237
|
+
upsertPackage(map, { name, version, ecosystem: "npm", paths: [] });
|
|
238
|
+
}
|
|
239
|
+
for (const [selectorKey, meta] of Object.entries(parsed.object)) {
|
|
240
|
+
const version = meta?.version;
|
|
241
|
+
if (!version)
|
|
242
|
+
continue;
|
|
243
|
+
const selectors = String(selectorKey).split(",").map(selector => selector.trim()).filter(Boolean);
|
|
244
|
+
const firstSelector = selectors[0];
|
|
245
|
+
const atIndex = firstSelector.lastIndexOf("@");
|
|
246
|
+
if (atIndex <= 0)
|
|
112
247
|
continue;
|
|
113
|
-
|
|
248
|
+
const name = firstSelector.slice(0, atIndex);
|
|
249
|
+
const canonicalKey = `${name}@${version}`;
|
|
250
|
+
const depKeys = new Set();
|
|
251
|
+
const deps = meta?.dependencies;
|
|
252
|
+
if (deps && typeof deps === "object") {
|
|
253
|
+
for (const [depName, depRange] of Object.entries(deps)) {
|
|
254
|
+
const childKey = selectorToKey.get(`${depName}@${depRange}`);
|
|
255
|
+
if (childKey)
|
|
256
|
+
depKeys.add(childKey);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
graph.set(canonicalKey, [...depKeys]);
|
|
114
260
|
}
|
|
261
|
+
const rootDepKeys = loadRootDepKeys(filePath, selectorToKey, map);
|
|
262
|
+
collectYarnPaths(rootDepKeys, graph, map);
|
|
115
263
|
return [...map.values()];
|
|
116
264
|
}
|
|
265
|
+
export function loadFromYarnLock(filePath) {
|
|
266
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
267
|
+
if (isYarnBerry(content)) {
|
|
268
|
+
return loadFromYarnBerryLock(content, filePath);
|
|
269
|
+
}
|
|
270
|
+
const parsed = parseYarnLock(content);
|
|
271
|
+
if (parsed.type !== "success" || !parsed.object) {
|
|
272
|
+
throw new Error("Could not parse yarn.lock");
|
|
273
|
+
}
|
|
274
|
+
return loadFromYarnClassicLock(parsed, filePath);
|
|
275
|
+
}
|
|
@@ -260,8 +260,9 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
260
260
|
}
|
|
261
261
|
const primaryParent = getPrimaryParent(finding);
|
|
262
262
|
if (finding.relationship === "transitive" && primaryParent) {
|
|
263
|
-
const
|
|
264
|
-
|
|
263
|
+
const fixHint = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
264
|
+
const fixClause = fixHint
|
|
265
|
+
? ` — check for a release that resolves ${finding.pkg.name} to ${fixHint}+`
|
|
265
266
|
: "";
|
|
266
267
|
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
267
268
|
package: finding.pkg.name,
|
|
@@ -11,12 +11,21 @@ export async function resolveTransitiveRemediationViaRegistry(args) {
|
|
|
11
11
|
if (!directParentContext)
|
|
12
12
|
return null;
|
|
13
13
|
const { directParentName, immediateParentName, directParent } = directParentContext;
|
|
14
|
-
if (directParentName !== immediateParentName)
|
|
15
|
-
return null;
|
|
16
|
-
if (!looksLikeVersion(directParent.version))
|
|
17
|
-
return null;
|
|
18
14
|
const vulnerableName = args.finding.pkg.name;
|
|
19
15
|
const fixHint = args.finding.validatedFirstFixedVersion ?? args.finding.firstFixedVersion;
|
|
16
|
+
if (directParentName !== immediateParentName) {
|
|
17
|
+
return resolveWithinRangeForDeepChainViaRegistry({
|
|
18
|
+
immediateParentName,
|
|
19
|
+
vulnerableName,
|
|
20
|
+
installedVersion: args.finding.pkg.version,
|
|
21
|
+
fixHint,
|
|
22
|
+
viaPath,
|
|
23
|
+
packages: args.packages,
|
|
24
|
+
workspaceMap: args.workspaceMap,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (!looksLikeVersion(directParent.version))
|
|
28
|
+
return null;
|
|
20
29
|
const safeCandidates = await findSafeChildCandidates(vulnerableName, args.finding.pkg.version, fixHint);
|
|
21
30
|
if (safeCandidates.length === 0)
|
|
22
31
|
return null;
|
|
@@ -291,6 +300,36 @@ function parseCoreVersion(version) {
|
|
|
291
300
|
const [major = "0", minor = "0", patch = "0"] = version.split(/[+-]/)[0].split(".");
|
|
292
301
|
return [Number(major), Number(minor), Number(patch)];
|
|
293
302
|
}
|
|
303
|
+
async function resolveWithinRangeForDeepChainViaRegistry(args) {
|
|
304
|
+
const immediateParent = args.packages.find(pkg => pkg.name === args.immediateParentName);
|
|
305
|
+
if (!immediateParent || !looksLikeVersion(immediateParent.version))
|
|
306
|
+
return null;
|
|
307
|
+
const safeCandidates = await findSafeChildCandidates(args.vulnerableName, args.installedVersion, args.fixHint);
|
|
308
|
+
if (safeCandidates.length === 0)
|
|
309
|
+
return null;
|
|
310
|
+
const packument = await fetchPackument(args.immediateParentName);
|
|
311
|
+
const parentManifest = packument?.versions?.[immediateParent.version];
|
|
312
|
+
const depRange = parentManifest?.dependencies?.[args.vulnerableName] ??
|
|
313
|
+
parentManifest?.optionalDependencies?.[args.vulnerableName];
|
|
314
|
+
if (!depRange)
|
|
315
|
+
return null;
|
|
316
|
+
const inRangeTarget = [...safeCandidates]
|
|
317
|
+
.sort(compareVersions)
|
|
318
|
+
.filter(version => versionSatisfiesRange(version, depRange))
|
|
319
|
+
.at(-1);
|
|
320
|
+
if (!inRangeTarget)
|
|
321
|
+
return null;
|
|
322
|
+
const workspaces = collectWorkspacesFromAllPaths([args.viaPath], args.workspaceMap);
|
|
323
|
+
return {
|
|
324
|
+
kind: "update-parent-within-range",
|
|
325
|
+
package: args.vulnerableName,
|
|
326
|
+
currentVersion: args.installedVersion,
|
|
327
|
+
targetChildVersion: inRangeTarget,
|
|
328
|
+
viaPath: args.viaPath,
|
|
329
|
+
reason: `${args.immediateParentName}@${immediateParent.version} already allows ${args.vulnerableName}@${inRangeTarget} within the current dependency range`,
|
|
330
|
+
workspaces,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
294
333
|
async function resolveWithinRangeForDeepChain(args) {
|
|
295
334
|
const immediateParent = args.packages.find(p => p.name === args.immediateParentName);
|
|
296
335
|
if (!immediateParent || !looksLikeVersion(immediateParent.version))
|
package/dist/scanner.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chunk, unique, runWithConcurrency } from "./utils/array.js";
|
|
2
|
+
import { isPrivateRegistrySource } from "./utils/advisory.js";
|
|
2
3
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "./utils/version.js";
|
|
3
4
|
import { loadCache, saveCache, isEntryStale } from "./osv/cache.js";
|
|
4
5
|
import { maxSeverity } from "./osv/severity.js";
|
|
@@ -217,6 +218,12 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
217
218
|
recommendedNpmTransitiveRemediation: undefined,
|
|
218
219
|
};
|
|
219
220
|
});
|
|
221
|
+
for (const finding of findings) {
|
|
222
|
+
if (finding.vulnerabilities.some(v => v.id.startsWith("MAL-")) &&
|
|
223
|
+
isPrivateRegistrySource(finding.pkg)) {
|
|
224
|
+
finding.maliciousUnverifiable = true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
220
227
|
const npmTransitiveGraph = context?.scanSource === "package-lock" && context.scanFilePath
|
|
221
228
|
? createNpmTransitiveGraphFromLockfile(context.scanFilePath, log, packages.length)
|
|
222
229
|
: null;
|
|
@@ -490,8 +497,17 @@ function isAdvisoryDbStale(metadata) {
|
|
|
490
497
|
return Date.now() - timestamp > ADVISORY_DB_STALE_AFTER_MS;
|
|
491
498
|
}
|
|
492
499
|
function classifyRelationship(paths, packageName, directDependencyNames) {
|
|
493
|
-
if (packageName && directDependencyNames?.has(packageName))
|
|
494
|
-
|
|
500
|
+
if (packageName && directDependencyNames?.has(packageName)) {
|
|
501
|
+
// The package name is declared as a direct dependency. But when multiple versions
|
|
502
|
+
// of the same package are installed (one direct, one transitive), the name alone
|
|
503
|
+
// is not enough — we need to verify this specific installed version is the direct
|
|
504
|
+
// one. A direct install always has at least one path of length 2 (["project", name]).
|
|
505
|
+
// If all paths are longer, this is a different (transitive) version of the package.
|
|
506
|
+
if (paths.length === 0)
|
|
507
|
+
return "direct"; // no path data — trust the name
|
|
508
|
+
const hasDirectPath = paths.some(p => p.length <= 2);
|
|
509
|
+
return hasDirectPath ? "direct" : "transitive";
|
|
510
|
+
}
|
|
495
511
|
if (paths.length === 0)
|
|
496
512
|
return "unknown";
|
|
497
513
|
if (directDependencyNames)
|
|
@@ -521,7 +537,7 @@ function findFirstFixedVersion(vulns) {
|
|
|
521
537
|
}
|
|
522
538
|
export function buildCoverageNotes(scanInput, offline) {
|
|
523
539
|
const notes = [
|
|
524
|
-
"
|
|
540
|
+
"CVE Lite CLI checks package versions against OSV advisories. It does not prove exploitability or runtime reachability.",
|
|
525
541
|
"Installed node_modules contents are not verified in this scan.",
|
|
526
542
|
"Container images, binaries, secrets, and IaC files are not scanned.",
|
|
527
543
|
"Monorepo workspace boundaries are only partially modeled in this version.",
|