cve-lite-cli 1.6.0 → 1.7.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
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
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
1
|
+
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
2
|
const packumentCache = new Map();
|
|
3
3
|
const DEFAULT_NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
4
4
|
export function clearPackumentCache() {
|
|
@@ -111,6 +111,7 @@ export async function resolveLowestKnownNonVulnerableVersion(packageName, instal
|
|
|
111
111
|
}
|
|
112
112
|
const candidates = Object.keys(packument.versions ?? {})
|
|
113
113
|
.filter(looksLikeVersion)
|
|
114
|
+
.filter(v => !isPreReleaseVersion(v))
|
|
114
115
|
.filter(version => compareVersions(version, installedVersion) > 0)
|
|
115
116
|
.sort(compareVersions);
|
|
116
117
|
if (candidates.length === 0) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
1
|
+
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
2
|
import { fetchPackument } from "./npm-registry.js";
|
|
3
3
|
export async function resolveRecommendedParentUpgrade(finding, packages) {
|
|
4
4
|
if (finding.relationship !== "transitive")
|
|
@@ -75,6 +75,7 @@ async function findUpgradeForExactDirectChild(args) {
|
|
|
75
75
|
const packument = await fetchPackument(args.directParentName);
|
|
76
76
|
const versions = Object.keys(packument?.versions ?? {})
|
|
77
77
|
.filter(looksLikeVersion)
|
|
78
|
+
.filter(v => !isPreReleaseVersion(v))
|
|
78
79
|
.filter(version => compareVersions(version, args.directParentVersion) > 0)
|
|
79
80
|
.sort(compareVersions);
|
|
80
81
|
for (const version of versions) {
|
|
@@ -108,6 +109,7 @@ async function findUpgradeForImmediateIntermediate(args) {
|
|
|
108
109
|
const packument = await fetchPackument(args.directParentName);
|
|
109
110
|
const versions = Object.keys(packument?.versions ?? {})
|
|
110
111
|
.filter(looksLikeVersion)
|
|
112
|
+
.filter(v => !isPreReleaseVersion(v))
|
|
111
113
|
.filter(version => compareVersions(version, args.directParentVersion) > 0)
|
|
112
114
|
.sort(compareVersions);
|
|
113
115
|
for (const version of versions) {
|
package/dist/scanner.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { chunk, unique } from "./utils/array.js";
|
|
2
|
-
import { compareVersions, looksLikeVersion } from "./utils/version.js";
|
|
2
|
+
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "./utils/version.js";
|
|
3
3
|
import { loadCache, saveCache } from "./osv/cache.js";
|
|
4
4
|
import { maxSeverity } from "./osv/severity.js";
|
|
5
5
|
import { createSpinner } from "./output/spinner.js";
|
|
@@ -271,7 +271,7 @@ function findFirstFixedVersion(vulns) {
|
|
|
271
271
|
for (const range of affected.ranges ?? []) {
|
|
272
272
|
for (const event of range.events ?? []) {
|
|
273
273
|
const fixed = event.fixed;
|
|
274
|
-
if (fixed && looksLikeVersion(fixed)) {
|
|
274
|
+
if (fixed && looksLikeVersion(fixed) && !isPreReleaseVersion(fixed)) {
|
|
275
275
|
fixedVersions.push(fixed);
|
|
276
276
|
}
|
|
277
277
|
}
|
package/dist/utils/version.js
CHANGED
|
@@ -32,6 +32,9 @@ export function isMajorVersionBump(from, to) {
|
|
|
32
32
|
const toMajor = Number(to.split(".")[0]);
|
|
33
33
|
return !Number.isNaN(fromMajor) && !Number.isNaN(toMajor) && toMajor > fromMajor;
|
|
34
34
|
}
|
|
35
|
+
export function isPreReleaseVersion(version) {
|
|
36
|
+
return /^\d+\.\d+\.\d+-[^\s]+$/.test(version);
|
|
37
|
+
}
|
|
35
38
|
export function normalizeRawVersion(value) {
|
|
36
39
|
if (typeof value !== "string")
|
|
37
40
|
return null;
|