cve-lite-cli 1.36.1 → 1.38.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.
Files changed (57) hide show
  1. package/README.md +25 -3
  2. package/dist/advisory/local-db.js +22 -3
  3. package/dist/audit-log/events.js +14 -0
  4. package/dist/cli/args.js +125 -102
  5. package/dist/cli/flags.js +39 -0
  6. package/dist/cli/help.js +8 -3
  7. package/dist/cli/overrides.js +25 -19
  8. package/dist/cli/validate.js +34 -9
  9. package/dist/index.js +6 -1
  10. package/dist/output/compact-truncation.js +35 -0
  11. package/dist/output/cyclonedx.js +6 -3
  12. package/dist/output/formatters.js +10 -2
  13. package/dist/output/html-reporter.js +31 -15
  14. package/dist/output/multi-folder-html-reporter.js +26 -7
  15. package/dist/output/output-dir.js +20 -0
  16. package/dist/output/override-findings-html.js +24 -3
  17. package/dist/output/override-findings-json.js +5 -2
  18. package/dist/output/override-findings-sarif.js +1 -0
  19. package/dist/output/override-findings-terminal.js +21 -1
  20. package/dist/output/printers.js +52 -25
  21. package/dist/output/sarif.js +63 -6
  22. package/dist/output/sbom-file.js +6 -4
  23. package/dist/output/scan-json.js +74 -0
  24. package/dist/output/skipped-override-rules.js +41 -0
  25. package/dist/output/spdx.js +2 -2
  26. package/dist/output/write-outputs.js +22 -32
  27. package/dist/overrides/admitted-scan.js +12 -1
  28. package/dist/overrides/api.js +75 -21
  29. package/dist/overrides/context-builder.js +17 -2
  30. package/dist/overrides/detectors/index.js +2 -0
  31. package/dist/overrides/detectors/oa008-materialized.js +74 -14
  32. package/dist/overrides/detectors/oa009-stale-floor.js +12 -15
  33. package/dist/overrides/detectors/oa010-vulnerable-floor.js +5 -1
  34. package/dist/overrides/detectors/oa011-exceeds-range.js +128 -0
  35. package/dist/overrides/detectors/pd001-override-only-phantom.js +5 -4
  36. package/dist/overrides/detectors/pd002-transitive-only-phantom.js +5 -4
  37. package/dist/overrides/detectors/phantom-utils.js +29 -0
  38. package/dist/overrides/parsing/registry.js +79 -10
  39. package/dist/remediation/fix-commands.js +89 -31
  40. package/dist/remediation/npm-registry.js +9 -1
  41. package/dist/remediation/parent-update-child-note.js +11 -0
  42. package/dist/scan/multi-folder-scan.js +68 -53
  43. package/dist/scan/override-audit.js +49 -0
  44. package/dist/scan/single-scan.js +115 -44
  45. package/dist/scanner.js +35 -11
  46. package/dist/skills/content.js +4 -2
  47. package/dist/usage/scanner.js +219 -28
  48. package/dist/utils/contextual-signals.js +193 -0
  49. package/dist/utils/create-pr.js +21 -2
  50. package/dist/utils/finding.js +5 -0
  51. package/dist/utils/fix-runner.js +15 -2
  52. package/dist/utils/package-json.js +66 -14
  53. package/dist/utils/severity.js +22 -0
  54. package/dist/utils/update-check.js +2 -1
  55. package/dist/utils/version.js +81 -86
  56. package/package.json +3 -1
  57. package/scripts/pr-scan-delta.mjs +7 -4
@@ -26,6 +26,25 @@ export function readDirectDependencyNames(projectPath, prodOnly) {
26
26
  return null;
27
27
  }
28
28
  }
29
+ // Every workspace member declared by the root manifest's `workspaces` field or
30
+ // by pnpm-workspace.yaml, with its parsed package.json. Empty for a
31
+ // single-package project. Best-effort: unreadable members are skipped.
32
+ export function readWorkspaceMemberManifests(projectPath) {
33
+ const rootManifest = readPackageJsonObject(path.join(projectPath, "package.json"));
34
+ if (!rootManifest)
35
+ return [];
36
+ const members = [];
37
+ for (const packageJsonPath of resolveWorkspacePackageJsonPaths(projectPath, readWorkspacePatterns(rootManifest, projectPath))) {
38
+ const manifest = readPackageJsonObject(packageJsonPath);
39
+ if (!manifest)
40
+ continue;
41
+ const dir = path.relative(projectPath, path.dirname(packageJsonPath)).split(path.sep).join("/");
42
+ if (!dir || dir === ".")
43
+ continue;
44
+ members.push({ dir, manifest });
45
+ }
46
+ return members;
47
+ }
29
48
  function readPackageJsonObject(filePath) {
30
49
  try {
31
50
  const raw = JSON.parse(fs.readFileSync(filePath, "utf8"));
@@ -89,26 +108,59 @@ function resolveWorkspacePackageJsonPaths(projectPath, patterns) {
89
108
  }
90
109
  return [...matches];
91
110
  }
111
+ /**
112
+ * Directory names directly under `relativePath`, skipping `node_modules` and dot-directories.
113
+ * A workspace member never lives inside `node_modules`, and descending into it during a `**`
114
+ * walk is both wrong and ruinously slow on a real monorepo.
115
+ */
116
+ function childDirectoryNames(projectPath, relativePath) {
117
+ const baseDir = relativePath ? path.join(projectPath, relativePath) : projectPath;
118
+ try {
119
+ return fs
120
+ .readdirSync(baseDir, { withFileTypes: true })
121
+ // isDirectory() is false for a symlink, so a link pointing back up cannot loop the walk.
122
+ .filter(entry => entry.isDirectory())
123
+ .map(entry => entry.name)
124
+ .filter(name => name !== "node_modules" && !name.startsWith("."));
125
+ }
126
+ catch {
127
+ return [];
128
+ }
129
+ }
130
+ /**
131
+ * Compiles one path segment containing `*` into an anchored matcher. `*` matches any run of
132
+ * characters within a single segment, so `pkg-*` and `*-app` both work. Everything else is
133
+ * escaped, so a literal dot in a directory name is not treated as a regex wildcard.
134
+ */
135
+ function segmentMatcher(segment) {
136
+ const escaped = segment.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*");
137
+ return new RegExp(`^${escaped}$`);
138
+ }
92
139
  function expandWorkspacePattern(projectPath, segments, currentRelativePath) {
93
140
  if (segments.length === 0) {
94
141
  return currentRelativePath ? [currentRelativePath] : [];
95
142
  }
96
143
  const [segment, ...rest] = segments;
97
- if (segment === "*") {
98
- const baseDir = currentRelativePath ? path.join(projectPath, currentRelativePath) : projectPath;
99
- let entries = [];
100
- try {
101
- entries = fs.readdirSync(baseDir, { withFileTypes: true });
102
- }
103
- catch {
104
- return [];
144
+ // `**` matches zero or more directory levels, so it expands both to "the rest of the
145
+ // pattern applied here" and to the same pattern applied one level deeper.
146
+ if (segment === "**") {
147
+ const results = new Set(expandWorkspacePattern(projectPath, rest, currentRelativePath));
148
+ for (const name of childDirectoryNames(projectPath, currentRelativePath)) {
149
+ const next = currentRelativePath ? path.join(currentRelativePath, name) : name;
150
+ for (const found of expandWorkspacePattern(projectPath, segments, next)) {
151
+ results.add(found);
152
+ }
105
153
  }
106
- return entries
107
- .filter(entry => entry.isDirectory())
108
- .flatMap(entry => {
109
- const nextRelativePath = currentRelativePath
110
- ? path.join(currentRelativePath, entry.name)
111
- : entry.name;
154
+ return [...results];
155
+ }
156
+ // Any segment containing `*` is matched against the directory entries. A whole-segment `*`
157
+ // is the degenerate case of this and needs no separate branch.
158
+ if (segment.includes("*")) {
159
+ const matcher = segmentMatcher(segment);
160
+ return childDirectoryNames(projectPath, currentRelativePath)
161
+ .filter(name => matcher.test(name))
162
+ .flatMap(name => {
163
+ const nextRelativePath = currentRelativePath ? path.join(currentRelativePath, name) : name;
112
164
  return expandWorkspacePattern(projectPath, rest, nextRelativePath);
113
165
  });
114
166
  }
@@ -8,6 +8,28 @@ export function reachesFailOn(findings, failOn) {
8
8
  const failLevel = normalizeSeverity(failOn);
9
9
  return findings.some((f) => severityOrder[f.severity] >= severityOrder[failLevel]);
10
10
  }
11
+ // One line that names what tripped the --fail-on gate, so a red CI job says why
12
+ // it is red. The gate ORs three finding classes (CVE, override hygiene,
13
+ // maintenance risk) and none of the rendered output mentioned the gate before,
14
+ // which read as a broken exit code. Returns null when the gate would not fire,
15
+ // so callers derive the exit decision from it (gateLine !== null) and the two
16
+ // cannot disagree. The parenthetical echoes the raw flag value: --fail-on is not
17
+ // validated and normalizeSeverity falls back to critical, so echoing the
18
+ // normalized level would show the user a value they never typed.
19
+ export function failingGateSummary(classes, failOn) {
20
+ if (!failOn)
21
+ return null;
22
+ const failLevel = normalizeSeverity(failOn);
23
+ const parts = [];
24
+ for (const { label, findings } of classes) {
25
+ const count = findings.filter((f) => severityOrder[f.severity] >= severityOrder[failLevel]).length;
26
+ if (count > 0)
27
+ parts.push(`${count} ${label} ${count === 1 ? "finding" : "findings"}`);
28
+ }
29
+ if (parts.length === 0)
30
+ return null;
31
+ return `Failing: ${parts.join(", ")} at or above ${failLevel} (--fail-on ${failOn}).`;
32
+ }
11
33
  export function formatSeverityLabel(severity) {
12
34
  const lower = severity.toLowerCase();
13
35
  if (lower === "critical")
@@ -4,6 +4,7 @@ import os from "node:os";
4
4
  import { chalk, stripAnsi } from "./chalk.js";
5
5
  import { getCliVersion } from "./version-info.js";
6
6
  const NPM_REGISTRY_URL = "https://registry.npmjs.org/cve-lite-cli/latest";
7
+ const NPM_INSTALL_COMMAND = "npm install -g cve-lite-cli";
7
8
  const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
8
9
  const BOX_INNER_WIDTH = 50;
9
10
  export function isNewer(latest, current) {
@@ -75,7 +76,7 @@ function renderBox(current, latest) {
75
76
  const empty = chalk.yellow("│") + " ".repeat(BOX_INNER_WIDTH) + chalk.yellow("│");
76
77
  const bottom = chalk.yellow("╰" + "─".repeat(BOX_INNER_WIDTH) + "╯");
77
78
  const line1 = ` ${chalk.bold.yellow("Update available!")} ${chalk.gray(current)} ${chalk.yellow("→")} ${chalk.green(latest)}`;
78
- const line2 = ` ${chalk.white("Run: npm install -g cve-lite-cli")}`;
79
+ const line2 = ` ${chalk.white("Run: " + NPM_INSTALL_COMMAND)}`;
79
80
  const padLine = (content) => {
80
81
  const visual = stripAnsi(content).length;
81
82
  return chalk.yellow("│") + content + " ".repeat(Math.max(0, BOX_INNER_WIDTH - visual)) + chalk.yellow("│");
@@ -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,101 +173,95 @@ export function coerceVersion(input) {
172
173
  return `${major}.${minor}.${patch}`;
173
174
  }
174
175
  /**
175
- * Does the string parse as a version range cve-lite recognises?
176
- * Supports plain versions and the operators `^`, `~`, `>=`, `<=`, `>`, `<`, `=`.
177
- * Does not support OR (`||`) or hyphen ranges (`1.0.0 - 2.0.0`) - if those
178
- * surface in real projects, extend later.
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 `*`.
179
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.
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)
182
- return false;
183
- const trimmed = input.trim();
184
- if (!/^(?:\^|~|>=|<=|>|<|=)?\s*\d+(?:\.\d+)?(?:\.\d+)?(?:[-+][^\s]+)?$/.test(trimmed)) {
221
+ if (!input || !input.trim())
185
222
  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`? Minimal subset of semver semantics covering
191
- * what the OA detectors need: exact, `^`, `~`, `>=`, `<=`, `>`, `<`, `=`.
226
+ * Does `version` satisfy `range`?
192
227
  *
193
- * Pre-releases follow semver convention: a pre-release version (e.g.
194
- * "1.2.3-beta") satisfies a range only if the range explicitly mentions a
195
- * pre-release component at the same major.minor.patch boundary.
228
+ * Delegates normalization and comparison to `positionAgainstRange` so
229
+ * prerelease handling and coercion stay on one path. Uninterpretable input
230
+ * returns false because `positionAgainstRange` returns null.
196
231
  */
197
232
  export function satisfiesRange(version, range) {
198
- const v = coerceVersion(version);
199
- if (!v)
200
- return false;
233
+ return positionAgainstRange(version, range) === "satisfies";
234
+ }
235
+ /**
236
+ * Classify a concrete version relative to the complete set represented by a
237
+ * semver range. "outside" covers gaps in compound/union ranges: for example,
238
+ * 2.0.0 is neither globally below nor globally above `1.x || 3.x`.
239
+ *
240
+ * Returns null when either input cannot be interpreted as semver. Callers that
241
+ * already validate their inputs can treat null conservatively as "outside".
242
+ */
243
+ export function positionAgainstRange(version, range) {
244
+ if (!version || !range)
245
+ return null;
246
+ const parsed = semver.parse(version.trim(), { loose: true });
247
+ const normalizedVersion = parsed ? parsed.version : coerceVersion(version);
201
248
  const trimmedRange = range.trim();
202
- // Compound range: space-separated comparators are ANDed, so `>=5.7.0 <6`
203
- // means both. Operators may carry a space before their operand (`>= 5.7.0`),
204
- // so glue those back on before splitting. Without this the first comparator
205
- // won and every ceiling was silently discarded, which made `>=5.7.0 <6`
206
- // accept 99.0.0.
207
- const glued = trimmedRange.replace(/([<>]=?|=|\^|~)\s+/g, "$1");
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: >= floor, ceiling at the leftmost non-zero component of the
222
- // target (npm: ^1.2.0 -> <2.0.0; ^0.2.3 -> <0.3.0; ^0.0.3 -> <0.0.4).
223
- // Partial ranges keep their component count: ^0 admits all 0.x, ^0.0 admits 0.0.x.
224
- if (trimmedRange.startsWith("^")) {
225
- const target = coerceVersion(trimmedRange.slice(1));
226
- if (!target)
227
- return false;
228
- if (compareVersions(v, target) < 0)
229
- return false;
230
- const [vMaj, vMin, vPatch] = v.split(".").map(Number);
231
- const [tMaj, tMin, tPatch] = target.split(".").map(Number);
232
- const parts = trimmedRange.slice(1).split("-")[0].split(".");
233
- if (tMaj > 0)
234
- return vMaj === tMaj; // ^1, ^1.2, ^1.2.3
235
- if (tMin > 0)
236
- return vMaj === tMaj && vMin === tMin; // ^0.1, ^0.1.x
237
- if (parts.length >= 3)
238
- return vMaj === tMaj && vMin === tMin && vPatch === tPatch; // ^0.0.3 exact
239
- if (parts.length === 2)
240
- return vMaj === tMaj && vMin === tMin; // ^0.0 -> 0.0.x
241
- return vMaj === tMaj; // ^0 -> all 0.x
242
- }
243
- // `~` tilde: same major.minor, >= specified
244
- if (trimmedRange.startsWith("~")) {
245
- const target = coerceVersion(trimmedRange.slice(1));
246
- if (!target)
247
- return false;
248
- if (compareVersions(v, target) < 0)
249
- return false;
250
- const [vMaj, vMin] = v.split(".").map(Number);
251
- const [tMaj, tMin] = target.split(".").map(Number);
252
- return vMaj === tMaj && vMin === tMin;
249
+ // validRange only GUARDS here. Its normalized output is computed without
250
+ // includePrerelease, which rewrites prerelease bounds and would silently
251
+ // change the classification below, so the comparisons take the raw range.
252
+ if (!normalizedVersion || !semver.validRange(trimmedRange, { loose: true }))
253
+ return null;
254
+ const options = { loose: true, includePrerelease: true };
255
+ try {
256
+ if (semver.satisfies(normalizedVersion, trimmedRange, options))
257
+ return "satisfies";
258
+ if (semver.ltr(normalizedVersion, trimmedRange, options))
259
+ return "below";
260
+ if (semver.gtr(normalizedVersion, trimmedRange, options))
261
+ return "above";
262
+ return "outside";
253
263
  }
254
- // Comparators
255
- for (const op of [">=", "<=", ">", "<"]) {
256
- if (trimmedRange.startsWith(op)) {
257
- const target = coerceVersion(trimmedRange.slice(op.length));
258
- if (!target)
259
- return false;
260
- const cmp = compareVersions(v, target);
261
- if (op === ">=")
262
- return cmp >= 0;
263
- if (op === "<=")
264
- return cmp <= 0;
265
- if (op === ">")
266
- return cmp > 0;
267
- if (op === "<")
268
- return cmp < 0;
269
- }
264
+ catch {
265
+ return null;
270
266
  }
271
- return false;
272
267
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cve-lite-cli",
3
- "version": "1.36.1",
3
+ "version": "1.38.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
- * "GHSA-xxx (CVE-2026-84375)", capped. A single package can carry dozens of
212
- * advisories (tar@6.1.0 has 36), and listing them all produces a line nobody
213
- * can read. CVEs are shown in preference to GHSA ids because they are what a
214
- * reviewer recognises.
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