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.
- package/README.md +20 -1
- package/dist/cli/args.js +121 -104
- package/dist/cli/flags.js +39 -0
- package/dist/cli/help.js +6 -3
- package/dist/cli/overrides.js +25 -19
- package/dist/cli/validate.js +31 -9
- package/dist/index.js +6 -1
- package/dist/output/compact-truncation.js +35 -0
- package/dist/output/formatters.js +10 -2
- package/dist/output/html-reporter.js +24 -12
- package/dist/output/multi-folder-html-reporter.js +26 -7
- package/dist/output/override-findings-html.js +24 -3
- package/dist/output/override-findings-json.js +5 -2
- package/dist/output/override-findings-sarif.js +1 -0
- package/dist/output/override-findings-terminal.js +21 -1
- package/dist/output/printers.js +34 -21
- package/dist/output/sarif.js +54 -3
- package/dist/output/scan-json.js +74 -0
- package/dist/output/skipped-override-rules.js +41 -0
- package/dist/output/write-outputs.js +16 -28
- package/dist/overrides/admitted-scan.js +12 -1
- package/dist/overrides/api.js +75 -21
- package/dist/overrides/context-builder.js +49 -6
- package/dist/overrides/detectors/index.js +2 -0
- package/dist/overrides/detectors/oa005-nested-ineffective.js +50 -2
- package/dist/overrides/detectors/oa008-materialized.js +72 -13
- package/dist/overrides/detectors/oa009-stale-floor.js +12 -15
- package/dist/overrides/detectors/oa010-vulnerable-floor.js +5 -1
- package/dist/overrides/detectors/oa011-exceeds-range.js +128 -0
- package/dist/overrides/detectors/pd001-override-only-phantom.js +5 -4
- package/dist/overrides/detectors/pd002-transitive-only-phantom.js +5 -4
- package/dist/overrides/detectors/phantom-utils.js +29 -0
- package/dist/overrides/parsing/registry.js +79 -10
- package/dist/scan/multi-folder-scan.js +65 -51
- package/dist/scan/override-audit.js +49 -0
- package/dist/scan/single-scan.js +109 -33
- package/dist/scanner.js +8 -4
- package/dist/skills/content.js +4 -2
- package/dist/usage/scanner.js +219 -28
- package/dist/utils/contextual-signals.js +193 -0
- package/dist/utils/finding.js +5 -0
- package/dist/utils/node-builtins.js +32 -0
- package/dist/utils/package-json.js +66 -14
- package/dist/utils/severity.js +22 -0
- package/dist/utils/update-check.js +2 -1
- package/dist/utils/version.js +37 -19
- 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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
}
|
package/dist/utils/severity.js
CHANGED
|
@@ -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:
|
|
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("│");
|
package/dist/utils/version.js
CHANGED
|
@@ -225,29 +225,47 @@ export function isValidRange(input) {
|
|
|
225
225
|
/**
|
|
226
226
|
* Does `version` satisfy `range`?
|
|
227
227
|
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
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
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
}
|