cve-lite-cli 1.36.0 → 1.37.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 +6 -3
- package/dist/advisory/local-db.js +22 -3
- package/dist/advisory/npm-advisory-source.js +70 -13
- package/dist/audit-log/events.js +14 -0
- package/dist/cli/args.js +8 -2
- package/dist/cli/help.js +2 -0
- package/dist/cli/validate.js +3 -0
- package/dist/epss/client.js +20 -9
- package/dist/output/cyclonedx.js +6 -3
- package/dist/output/html-reporter.js +7 -3
- package/dist/output/output-dir.js +20 -0
- package/dist/output/printers.js +18 -4
- package/dist/output/sarif.js +10 -4
- package/dist/output/sbom-file.js +6 -4
- package/dist/output/spdx.js +2 -2
- package/dist/output/write-outputs.js +7 -5
- package/dist/overrides/detectors/oa008-materialized.js +3 -2
- package/dist/remediation/fix-commands.js +89 -31
- package/dist/remediation/npm-registry.js +108 -1
- package/dist/remediation/parent-update-child-note.js +11 -0
- package/dist/scan/multi-folder-scan.js +3 -2
- package/dist/scan/single-scan.js +7 -11
- package/dist/scanner.js +89 -45
- package/dist/utils/create-pr.js +21 -2
- package/dist/utils/fix-runner.js +15 -2
- package/dist/utils/version.js +68 -78
- package/package.json +3 -1
- package/scripts/pr-scan-delta.mjs +7 -4
package/dist/utils/fix-runner.js
CHANGED
|
@@ -6,6 +6,7 @@ import { chalk } from "./chalk.js";
|
|
|
6
6
|
import { pluralize } from "./string.js";
|
|
7
7
|
import { isBreakingUpgrade } from "./version.js";
|
|
8
8
|
import { buildTargetCommand } from "../remediation/fix-commands.js";
|
|
9
|
+
import { formatParentUpdateChildNote } from "../remediation/parent-update-child-note.js";
|
|
9
10
|
export async function runInstallCommand(command, args, cwd, debugLog) {
|
|
10
11
|
const commandLine = [command, ...args].join(" ");
|
|
11
12
|
debugLog?.("Fix command", { command: commandLine, cwd });
|
|
@@ -109,10 +110,18 @@ export async function applyFixesIfRequested(params) {
|
|
|
109
110
|
const total = applyTargets.length;
|
|
110
111
|
const spinner = createSpinner(`Applying safe package fixes with ${commandLabel}... 0/${total}`, params.options);
|
|
111
112
|
const fixHint = `\nHint: Check that \`${params.plan.packageManager}\` is available and you have write access to node_modules.\nIf running in CI, ensure the install step has already run before cve-lite --fix.`;
|
|
113
|
+
// parent-update is keyed per child, so two children behind one parent produce
|
|
114
|
+
// two targets with the same `npm update <parent>` command. Spawn each command
|
|
115
|
+
// once; the displayed plan already dedupes the same way.
|
|
116
|
+
const seenCommands = new Set();
|
|
112
117
|
for (let i = 0; i < applyTargets.length; i++) {
|
|
113
118
|
const target = applyTargets[i];
|
|
114
119
|
for (const commandParts of buildApplyCommands(params.plan.packageManager, target)) {
|
|
115
|
-
|
|
120
|
+
const commandLine = commandParts.join(" ");
|
|
121
|
+
if (seenCommands.has(commandLine))
|
|
122
|
+
continue;
|
|
123
|
+
seenCommands.add(commandLine);
|
|
124
|
+
spinner.update(`Applying fix ${i + 1}/${total}: ${commandLine}`);
|
|
116
125
|
const run = await runCommand(commandParts[0], commandParts.slice(1), params.projectPath, params.debugLog);
|
|
117
126
|
if (run.error) {
|
|
118
127
|
spinner.fail("Failed to apply fixes");
|
|
@@ -133,6 +142,8 @@ export async function applyFixesIfRequested(params) {
|
|
|
133
142
|
package: target.package,
|
|
134
143
|
from: target.currentVersion ?? "unknown",
|
|
135
144
|
to: target.targetVersion,
|
|
145
|
+
...(target.childPackage ? { childPackage: target.childPackage } : {}),
|
|
146
|
+
...(target.childTargetVersion ? { childTargetVersion: target.childTargetVersion } : {}),
|
|
136
147
|
})),
|
|
137
148
|
note: null,
|
|
138
149
|
};
|
|
@@ -148,7 +159,9 @@ export function printFixModeSummary(params) {
|
|
|
148
159
|
console.log("");
|
|
149
160
|
console.log(chalk.bold.cyan("Applied fixes"));
|
|
150
161
|
for (const item of result.applied) {
|
|
151
|
-
|
|
162
|
+
const childNote = formatParentUpdateChildNote(item);
|
|
163
|
+
const line = `- ${chalk.white(item.package)}: ${chalk.gray(item.from)} ${chalk.cyan("->")} ${chalk.green(item.to)}`;
|
|
164
|
+
console.log(childNote ? `${line} (${childNote})` : line);
|
|
152
165
|
}
|
|
153
166
|
}
|
|
154
167
|
console.log("");
|
package/dist/utils/version.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import semver from "semver";
|
|
1
2
|
export function looksLikeVersion(value) {
|
|
2
3
|
return /^[0-9]+\.[0-9]+\.[0-9]+(?:[-+][^/]+)?$/.test(value);
|
|
3
4
|
}
|
|
@@ -172,92 +173,81 @@ export function coerceVersion(input) {
|
|
|
172
173
|
return `${major}.${minor}.${patch}`;
|
|
173
174
|
}
|
|
174
175
|
/**
|
|
175
|
-
* Does the string parse as a version range
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
176
|
+
* Does the string parse as a version range?
|
|
177
|
+
*
|
|
178
|
+
* Delegates to semver so the full grammar is accepted: comparators, compound
|
|
179
|
+
* (`>=1.2.3 <2`), unions (`^1 || ^2`), wildcards (`1.x`), hyphen ranges and
|
|
180
|
+
* partials. The previous hand-rolled regex accepted a single comparator only,
|
|
181
|
+
* so every bounded range read as invalid. OA002 treats "not a valid range" as
|
|
182
|
+
* a floating tag, which made correct bounded overrides look like `latest`
|
|
183
|
+
* (#1216).
|
|
184
|
+
*
|
|
185
|
+
* Empty input stays `false`: callers treat the empty string as a floating tag,
|
|
186
|
+
* whereas semver reads it as `*`.
|
|
187
|
+
*/
|
|
188
|
+
/**
|
|
189
|
+
* Normalize a version as it appears in an OSV advisory event to `X.Y.Z`.
|
|
190
|
+
*
|
|
191
|
+
* Advisories declare fix and introduced boundaries as exact versions, and those
|
|
192
|
+
* are routinely written with fewer than three components: `fixed: "1.22"` means
|
|
193
|
+
* 1.22.0. `looksLikeVersion` demands a strict `X.Y.Z`, so `collectAdvisoryFixes`
|
|
194
|
+
* discarded such an event and the finding then reported "no fix available",
|
|
195
|
+
* which is an instruction to stop looking (#1192).
|
|
196
|
+
*
|
|
197
|
+
* Deliberately a strict whole-string match rather than `semver.coerce`. Coercion
|
|
198
|
+
* reads leading digits out of anything, so a GIT range's commit hash becomes a
|
|
199
|
+
* plausible version:
|
|
200
|
+
*
|
|
201
|
+
* semver.coerce("74ea7cf4d1b1...") -> "74.0.0"
|
|
202
|
+
*
|
|
203
|
+
* which is the defect in #1191 rather than a fix for it. Anything this cannot
|
|
204
|
+
* read in full is rejected, so a non-version boundary never reaches a
|
|
205
|
+
* comparison.
|
|
206
|
+
*
|
|
207
|
+
* Note this is for ADVISORY versions only. It must not be used on manifest or
|
|
208
|
+
* override specs, where a bare `1.22` is the range `1.22.x` rather than 1.22.0.
|
|
179
209
|
*/
|
|
210
|
+
const ADVISORY_VERSION = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$/;
|
|
211
|
+
export function normalizeAdvisoryVersion(value) {
|
|
212
|
+
if (!value)
|
|
213
|
+
return null;
|
|
214
|
+
const match = ADVISORY_VERSION.exec(value.trim());
|
|
215
|
+
if (!match)
|
|
216
|
+
return null;
|
|
217
|
+
const [, major, minor = "0", patch = "0", prerelease = "", build = ""] = match;
|
|
218
|
+
return `${major}.${minor}.${patch}${prerelease}${build}`;
|
|
219
|
+
}
|
|
180
220
|
export function isValidRange(input) {
|
|
181
|
-
if (!input)
|
|
221
|
+
if (!input || !input.trim())
|
|
182
222
|
return false;
|
|
183
|
-
|
|
184
|
-
if (!/^(?:\^|~|>=|<=|>|<|=)?\s*\d+(?:\.\d+)?(?:\.\d+)?(?:[-+][^\s]+)?$/.test(trimmed)) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
return coerceVersion(trimmed) !== null;
|
|
223
|
+
return semver.validRange(input.trim(), { loose: true }) !== null;
|
|
188
224
|
}
|
|
189
225
|
/**
|
|
190
|
-
* Does `version` satisfy `range`?
|
|
191
|
-
* what the OA detectors need: exact, `^`, `~`, `>=`, `<=`, `>`, `<`, `=`.
|
|
226
|
+
* Does `version` satisfy `range`?
|
|
192
227
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
228
|
+
* `includePrerelease` is deliberate. A pre-release install must still match an
|
|
229
|
+
* advisory range that covers it, otherwise a vulnerable `1.2.3-beta.1` is
|
|
230
|
+
* cleared by a `<1.2.3` advisory. That is the defect v1.34.0 fixed on the OSV
|
|
231
|
+
* path, and it survived here because the old implementation ran the version
|
|
232
|
+
* through `coerceVersion` first, which strips the pre-release tag and made the
|
|
233
|
+
* beta compare equal to the release.
|
|
234
|
+
*
|
|
235
|
+
* Messy inputs (`v1.2.3`, `2.0`) fall back to `coerceVersion`, which is kept
|
|
236
|
+
* for exactly that: lockfiles and manifests carry version strings semver will
|
|
237
|
+
* not parse.
|
|
196
238
|
*/
|
|
197
239
|
export function satisfiesRange(version, range) {
|
|
198
|
-
|
|
199
|
-
|
|
240
|
+
if (!version || !range)
|
|
241
|
+
return false;
|
|
242
|
+
const parsed = semver.parse(version.trim(), { loose: true });
|
|
243
|
+
const normalizedVersion = parsed ? parsed.version : coerceVersion(version);
|
|
244
|
+
if (!normalizedVersion)
|
|
200
245
|
return false;
|
|
201
246
|
const trimmedRange = range.trim();
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (/\s/.test(glued)) {
|
|
209
|
-
const parts = glued.split(/\s+/).filter(Boolean);
|
|
210
|
-
return parts.every((part) => satisfiesRange(version, part));
|
|
211
|
-
}
|
|
212
|
-
// Exact match (no operator)
|
|
213
|
-
if (/^\d/.test(trimmedRange)) {
|
|
214
|
-
return compareVersions(v, coerceVersion(trimmedRange) ?? "") === 0;
|
|
215
|
-
}
|
|
216
|
-
// `=` operator
|
|
217
|
-
if (trimmedRange.startsWith("=")) {
|
|
218
|
-
const target = coerceVersion(trimmedRange.slice(1));
|
|
219
|
-
return target !== null && compareVersions(v, target) === 0;
|
|
220
|
-
}
|
|
221
|
-
// `^` caret: same major, >= specified, < next major
|
|
222
|
-
if (trimmedRange.startsWith("^")) {
|
|
223
|
-
const target = coerceVersion(trimmedRange.slice(1));
|
|
224
|
-
if (!target)
|
|
225
|
-
return false;
|
|
226
|
-
if (compareVersions(v, target) < 0)
|
|
227
|
-
return false;
|
|
228
|
-
const tMajor = majorVersion(target);
|
|
229
|
-
const vMajor = majorVersion(v);
|
|
230
|
-
if (tMajor === null || vMajor === null)
|
|
231
|
-
return false;
|
|
232
|
-
return vMajor === tMajor;
|
|
233
|
-
}
|
|
234
|
-
// `~` tilde: same major.minor, >= specified
|
|
235
|
-
if (trimmedRange.startsWith("~")) {
|
|
236
|
-
const target = coerceVersion(trimmedRange.slice(1));
|
|
237
|
-
if (!target)
|
|
238
|
-
return false;
|
|
239
|
-
if (compareVersions(v, target) < 0)
|
|
240
|
-
return false;
|
|
241
|
-
const [vMaj, vMin] = v.split(".").map(Number);
|
|
242
|
-
const [tMaj, tMin] = target.split(".").map(Number);
|
|
243
|
-
return vMaj === tMaj && vMin === tMin;
|
|
244
|
-
}
|
|
245
|
-
// Comparators
|
|
246
|
-
for (const op of [">=", "<=", ">", "<"]) {
|
|
247
|
-
if (trimmedRange.startsWith(op)) {
|
|
248
|
-
const target = coerceVersion(trimmedRange.slice(op.length));
|
|
249
|
-
if (!target)
|
|
250
|
-
return false;
|
|
251
|
-
const cmp = compareVersions(v, target);
|
|
252
|
-
if (op === ">=")
|
|
253
|
-
return cmp >= 0;
|
|
254
|
-
if (op === "<=")
|
|
255
|
-
return cmp <= 0;
|
|
256
|
-
if (op === ">")
|
|
257
|
-
return cmp > 0;
|
|
258
|
-
if (op === "<")
|
|
259
|
-
return cmp < 0;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return false;
|
|
247
|
+
if (!semver.validRange(trimmedRange, { loose: true }))
|
|
248
|
+
return false;
|
|
249
|
+
return semver.satisfies(normalizedVersion, trimmedRange, {
|
|
250
|
+
loose: true,
|
|
251
|
+
includePrerelease: true,
|
|
252
|
+
});
|
|
263
253
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cve-lite-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.37.0",
|
|
4
4
|
"description": "Developer-friendly CLI for scanning JS/TS projects for dependency vulnerabilities using local lockfiles and OSV",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"better-sqlite3": "^12.8.0",
|
|
23
23
|
"fflate": "^0.8.3",
|
|
24
|
+
"semver": "^7.8.5",
|
|
24
25
|
"yaml": "^2.7.1",
|
|
25
26
|
"yarn-lockfile": "^1.1.0"
|
|
26
27
|
},
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"@types/better-sqlite3": "^7.6.13",
|
|
29
30
|
"@types/jest": "^30.0.0",
|
|
30
31
|
"@types/node": "^24.0.0",
|
|
32
|
+
"@types/semver": "^7.8.0",
|
|
31
33
|
"jest": "^30.4.2",
|
|
32
34
|
"ts-jest": "^29.4.9",
|
|
33
35
|
"tsx": "^4.22.0",
|
|
@@ -208,10 +208,13 @@ function countPhrase(rows, { adjective } = {}) {
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
/**
|
|
211
|
-
* "
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
211
|
+
* "CVE-2026-84375", or the GHSA id when the finding carries no CVE alias.
|
|
212
|
+
*
|
|
213
|
+
* Capped, because a single package can carry dozens of advisories (tar@6.1.0
|
|
214
|
+
* has 36) and listing them all produces a line nobody can read. CVEs are shown
|
|
215
|
+
* in preference to GHSA ids, not alongside them, because they are what a
|
|
216
|
+
* reviewer recognises. That does mean this comment and the CLI's own findings
|
|
217
|
+
* table can name the same advisory differently.
|
|
215
218
|
*/
|
|
216
219
|
const MAX_IDS = 3;
|
|
217
220
|
|