cve-lite-cli 1.6.0 → 1.7.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 +1 -0
- package/dist/parsers/pnpm-lock.js +107 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -216,6 +216,7 @@ CVE Lite CLI complements these tools by serving a practical developer workflow c
|
|
|
216
216
|
|
|
217
217
|
- [OWASP Juice Shop](docs/case-studies/owasp-juice-shop.md) — scanning a deliberately vulnerable application with known dependency issues
|
|
218
218
|
- [NestJS](docs/case-studies/nestjs.md) — working through a real transitive dependency remediation sequence
|
|
219
|
+
- [Analog](docs/case-studies/analog.md) — scanning a modern pnpm v9 Angular monorepo (3,367 packages) with unexpected toolchain vulnerabilities
|
|
219
220
|
|
|
220
221
|
If you maintain an open-source JavaScript or TypeScript project and want CVE Lite CLI evaluated on it, open an issue and share the repository. Strong candidates may be turned into future public case studies.
|
|
221
222
|
|
|
@@ -6,6 +6,10 @@ import { uniquePathArrays } from "../utils/array.js";
|
|
|
6
6
|
export function loadFromPnpmLock(filePath, prodOnly) {
|
|
7
7
|
const content = fs.readFileSync(filePath, "utf8");
|
|
8
8
|
const parsed = YAML.parse(content);
|
|
9
|
+
const majorVersion = parseInt(String(parsed?.lockfileVersion ?? "0"), 10);
|
|
10
|
+
return majorVersion >= 9 ? loadV9(parsed, prodOnly) : loadLegacy(parsed, prodOnly);
|
|
11
|
+
}
|
|
12
|
+
function loadLegacy(parsed, prodOnly) {
|
|
9
13
|
const packagesSection = parsed?.packages ?? {};
|
|
10
14
|
const importers = parsed?.importers ?? {};
|
|
11
15
|
const graph = new Map();
|
|
@@ -58,17 +62,91 @@ export function loadFromPnpmLock(filePath, prodOnly) {
|
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
const queue = rootDeps.map(dep => ({ key: dep, path: ["project"] }));
|
|
61
|
-
const
|
|
65
|
+
const seenKeys = new Set();
|
|
62
66
|
while (queue.length > 0) {
|
|
63
67
|
const current = queue.shift();
|
|
68
|
+
if (seenKeys.has(current.key))
|
|
69
|
+
continue;
|
|
70
|
+
seenKeys.add(current.key);
|
|
64
71
|
const ref = parsePnpmPackageKey(current.key);
|
|
65
72
|
if (!ref)
|
|
66
73
|
continue;
|
|
67
74
|
const nextPath = [...current.path, ref.name];
|
|
68
|
-
const
|
|
69
|
-
|
|
75
|
+
const pkgKey = `${ref.name}@${ref.version}`;
|
|
76
|
+
const pkg = map.get(pkgKey);
|
|
77
|
+
if (pkg) {
|
|
78
|
+
pkg.paths = uniquePathArrays([...(pkg.paths ?? []), nextPath]).slice(0, 5);
|
|
79
|
+
}
|
|
80
|
+
const children = graph.get(current.key) ?? [];
|
|
81
|
+
for (const child of children) {
|
|
82
|
+
queue.push({ key: child, path: nextPath });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return [...map.values()];
|
|
86
|
+
}
|
|
87
|
+
function loadV9(parsed, prodOnly) {
|
|
88
|
+
const snapshotsSection = parsed?.snapshots ?? {};
|
|
89
|
+
const importers = parsed?.importers ?? {};
|
|
90
|
+
const graph = new Map();
|
|
91
|
+
const map = new Map();
|
|
92
|
+
for (const [key, meta] of Object.entries(snapshotsSection)) {
|
|
93
|
+
const ref = parsePnpmPackageKeyV9(String(key));
|
|
94
|
+
if (!ref)
|
|
95
|
+
continue;
|
|
96
|
+
const depKeys = new Set();
|
|
97
|
+
for (const depMap of [meta?.dependencies, meta?.optionalDependencies]) {
|
|
98
|
+
if (!depMap || typeof depMap !== "object")
|
|
99
|
+
continue;
|
|
100
|
+
for (const [depName, depRef] of Object.entries(depMap)) {
|
|
101
|
+
const resolved = normalizePnpmDepRefV9(String(depName), depRef);
|
|
102
|
+
if (resolved)
|
|
103
|
+
depKeys.add(resolved);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
graph.set(ref.key, [...depKeys]);
|
|
107
|
+
const dev = !!meta?.dev;
|
|
108
|
+
if (prodOnly && dev)
|
|
109
|
+
continue;
|
|
110
|
+
upsertPackage(map, { name: ref.name, version: ref.version, ecosystem: "npm", dev, paths: [] });
|
|
111
|
+
}
|
|
112
|
+
const rootDeps = [];
|
|
113
|
+
for (const importer of Object.values(importers)) {
|
|
114
|
+
for (const depSectionName of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
115
|
+
if (prodOnly && depSectionName === "devDependencies")
|
|
116
|
+
continue;
|
|
117
|
+
const depSection = importer?.[depSectionName];
|
|
118
|
+
if (!depSection || typeof depSection !== "object")
|
|
119
|
+
continue;
|
|
120
|
+
for (const [depName, depRef] of Object.entries(depSection)) {
|
|
121
|
+
const resolved = normalizePnpmDepRefV9(String(depName), depRef);
|
|
122
|
+
if (resolved) {
|
|
123
|
+
rootDeps.push(resolved);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const fallbackVersion = normalizeRawVersion(depRef);
|
|
127
|
+
if (fallbackVersion) {
|
|
128
|
+
upsertPackage(map, {
|
|
129
|
+
name: String(depName),
|
|
130
|
+
version: fallbackVersion,
|
|
131
|
+
ecosystem: "npm",
|
|
132
|
+
paths: [["project", String(depName)]]
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const queue = rootDeps.map(dep => ({ key: dep, path: ["project"] }));
|
|
140
|
+
const seenKeys = new Set();
|
|
141
|
+
while (queue.length > 0) {
|
|
142
|
+
const current = queue.shift();
|
|
143
|
+
if (seenKeys.has(current.key))
|
|
144
|
+
continue;
|
|
145
|
+
seenKeys.add(current.key);
|
|
146
|
+
const ref = parsePnpmPackageKeyV9(current.key);
|
|
147
|
+
if (!ref)
|
|
70
148
|
continue;
|
|
71
|
-
|
|
149
|
+
const nextPath = [...current.path, ref.name];
|
|
72
150
|
const pkgKey = `${ref.name}@${ref.version}`;
|
|
73
151
|
const pkg = map.get(pkgKey);
|
|
74
152
|
if (pkg) {
|
|
@@ -89,6 +167,17 @@ function parsePnpmPackageKey(key) {
|
|
|
89
167
|
const [, name, version] = match;
|
|
90
168
|
return { key, name, version };
|
|
91
169
|
}
|
|
170
|
+
function parsePnpmPackageKeyV9(key) {
|
|
171
|
+
const cleaned = key.split("(")[0]; // strip peer-dep suffix e.g. handlebars@4.7.8(foo@1.0.0)
|
|
172
|
+
const idx = cleaned.lastIndexOf("@");
|
|
173
|
+
if (idx <= 0)
|
|
174
|
+
return null; // no @ or @ is the first char
|
|
175
|
+
const name = cleaned.slice(0, idx);
|
|
176
|
+
const version = cleaned.slice(idx + 1);
|
|
177
|
+
if (!name || !version)
|
|
178
|
+
return null;
|
|
179
|
+
return { key: cleaned, name, version };
|
|
180
|
+
}
|
|
92
181
|
function normalizePnpmDepRef(depName, depRef) {
|
|
93
182
|
if (typeof depRef === "string") {
|
|
94
183
|
const cleaned = depRef.replace(/^link:/, "").replace(/^workspace:/, "").split("(")[0];
|
|
@@ -107,3 +196,17 @@ function normalizePnpmDepRef(depName, depRef) {
|
|
|
107
196
|
}
|
|
108
197
|
return null;
|
|
109
198
|
}
|
|
199
|
+
function normalizePnpmDepRefV9(depName, depRef) {
|
|
200
|
+
if (typeof depRef === "string") {
|
|
201
|
+
const cleaned = depRef.replace(/^link:/, "").replace(/^workspace:/, "").split("(")[0];
|
|
202
|
+
if (!cleaned || cleaned.startsWith(".") || cleaned.startsWith(".."))
|
|
203
|
+
return null;
|
|
204
|
+
if (looksLikeVersion(cleaned))
|
|
205
|
+
return `${depName}@${cleaned}`;
|
|
206
|
+
}
|
|
207
|
+
if (depRef && typeof depRef === "object") {
|
|
208
|
+
const version = depRef.version ?? depRef.specifier;
|
|
209
|
+
return normalizePnpmDepRefV9(depName, version);
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|