cve-lite-cli 1.37.0 → 1.39.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 (47) hide show
  1. package/README.md +20 -1
  2. package/dist/cli/args.js +121 -104
  3. package/dist/cli/flags.js +39 -0
  4. package/dist/cli/help.js +6 -3
  5. package/dist/cli/overrides.js +25 -19
  6. package/dist/cli/validate.js +31 -9
  7. package/dist/index.js +6 -1
  8. package/dist/output/compact-truncation.js +35 -0
  9. package/dist/output/formatters.js +10 -2
  10. package/dist/output/html-reporter.js +24 -12
  11. package/dist/output/multi-folder-html-reporter.js +26 -7
  12. package/dist/output/override-findings-html.js +24 -3
  13. package/dist/output/override-findings-json.js +5 -2
  14. package/dist/output/override-findings-sarif.js +1 -0
  15. package/dist/output/override-findings-terminal.js +21 -1
  16. package/dist/output/printers.js +34 -21
  17. package/dist/output/sarif.js +54 -3
  18. package/dist/output/scan-json.js +74 -0
  19. package/dist/output/skipped-override-rules.js +41 -0
  20. package/dist/output/write-outputs.js +16 -28
  21. package/dist/overrides/admitted-scan.js +12 -1
  22. package/dist/overrides/api.js +75 -21
  23. package/dist/overrides/context-builder.js +49 -6
  24. package/dist/overrides/detectors/index.js +2 -0
  25. package/dist/overrides/detectors/oa005-nested-ineffective.js +50 -2
  26. package/dist/overrides/detectors/oa008-materialized.js +72 -13
  27. package/dist/overrides/detectors/oa009-stale-floor.js +12 -15
  28. package/dist/overrides/detectors/oa010-vulnerable-floor.js +5 -1
  29. package/dist/overrides/detectors/oa011-exceeds-range.js +128 -0
  30. package/dist/overrides/detectors/pd001-override-only-phantom.js +5 -4
  31. package/dist/overrides/detectors/pd002-transitive-only-phantom.js +5 -4
  32. package/dist/overrides/detectors/phantom-utils.js +29 -0
  33. package/dist/overrides/parsing/registry.js +79 -10
  34. package/dist/scan/multi-folder-scan.js +65 -51
  35. package/dist/scan/override-audit.js +49 -0
  36. package/dist/scan/single-scan.js +109 -33
  37. package/dist/scanner.js +8 -4
  38. package/dist/skills/content.js +4 -2
  39. package/dist/usage/scanner.js +219 -28
  40. package/dist/utils/contextual-signals.js +193 -0
  41. package/dist/utils/finding.js +5 -0
  42. package/dist/utils/node-builtins.js +32 -0
  43. package/dist/utils/package-json.js +66 -14
  44. package/dist/utils/severity.js +22 -0
  45. package/dist/utils/update-check.js +2 -1
  46. package/dist/utils/version.js +37 -19
  47. package/package.json +1 -1
@@ -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("│");
@@ -225,29 +225,47 @@ export function isValidRange(input) {
225
225
  /**
226
226
  * Does `version` satisfy `range`?
227
227
  *
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.
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.
238
231
  */
239
232
  export function satisfiesRange(version, range) {
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) {
240
244
  if (!version || !range)
241
- return false;
245
+ return null;
242
246
  const parsed = semver.parse(version.trim(), { loose: true });
243
247
  const normalizedVersion = parsed ? parsed.version : coerceVersion(version);
244
- if (!normalizedVersion)
245
- return false;
246
248
  const trimmedRange = range.trim();
247
- if (!semver.validRange(trimmedRange, { loose: true }))
248
- return false;
249
- return semver.satisfies(normalizedVersion, trimmedRange, {
250
- loose: true,
251
- includePrerelease: true,
252
- });
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
+ // includePrerelease is deliberate and must not be dropped. Without it semver
255
+ // excludes a prerelease from a range it should satisfy, so a prerelease sitting
256
+ // inside a vulnerable range reads as safe. That was a real false negative, fixed
257
+ // in v1.34.0, and this flag is what keeps it fixed.
258
+ const options = { loose: true, includePrerelease: true };
259
+ try {
260
+ if (semver.satisfies(normalizedVersion, trimmedRange, options))
261
+ return "satisfies";
262
+ if (semver.ltr(normalizedVersion, trimmedRange, options))
263
+ return "below";
264
+ if (semver.gtr(normalizedVersion, trimmedRange, options))
265
+ return "above";
266
+ return "outside";
267
+ }
268
+ catch {
269
+ return null;
270
+ }
253
271
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cve-lite-cli",
3
- "version": "1.37.0",
3
+ "version": "1.39.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": {