cve-lite-cli 1.39.0 → 1.40.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 +11 -11
- package/dist/cli/help.js +1 -0
- package/dist/constants.js +4 -3
- package/dist/osv/severity.js +1 -1
- package/dist/output/cyclonedx.js +1 -1
- package/dist/output/formatters.js +2 -2
- package/dist/output/html-reporter.js +14 -8
- package/dist/output/multi-folder-html-reporter.js +12 -8
- package/dist/output/override-findings-html.js +3 -6
- package/dist/output/override-findings-terminal.js +7 -12
- package/dist/output/override-fix-command.js +13 -0
- package/dist/output/printers.js +11 -7
- package/dist/output/sarif.js +39 -11
- package/dist/output/scan-json.js +26 -1
- package/dist/output/write-outputs.js +13 -1
- package/dist/overrides/parsing/registry.js +1 -1
- package/dist/parsers/pnpm-lock.js +23 -10
- package/dist/remediation/fix-commands.js +36 -7
- package/dist/remediation/npm-registry.js +56 -7
- package/dist/remediation/npm-transitive-resolution.js +11 -30
- package/dist/remediation/parent-candidate-resolver.js +65 -0
- package/dist/remediation/parent-upgrade.js +6 -37
- package/dist/scan/completeness.js +7 -7
- package/dist/scan/multi-folder-scan.js +28 -8
- package/dist/scan/override-audit.js +11 -1
- package/dist/scan/single-scan.js +85 -45
- package/dist/scanner.js +32 -9
- package/dist/skills/content.js +12 -12
- package/dist/utils/contextual-signals.js +1 -1
- package/dist/utils/effective-options.js +55 -0
- package/dist/utils/finding.js +1 -1
- package/dist/utils/fix-runner.js +3 -2
- package/dist/utils/network.js +1 -1
- package/dist/utils/registry-config.js +144 -0
- package/dist/utils/severity.js +8 -0
- package/dist/utils/validate-url.js +3 -3
- package/dist/utils/version.js +17 -1
- package/dist/utils/vuln.js +75 -0
- package/package.json +1 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import YAML from "yaml";
|
|
5
|
+
import { NPM_PUBLIC_REGISTRY } from "../constants.js";
|
|
6
|
+
/**
|
|
7
|
+
* Where each package manager keeps its registry, mirroring the per-manager table in
|
|
8
|
+
* `cooldown.ts`.
|
|
9
|
+
*
|
|
10
|
+
* npm and pnpm share `.npmrc`, because pnpm reads npm's own config file. Yarn Berry
|
|
11
|
+
* uses its own YAML.
|
|
12
|
+
*
|
|
13
|
+
* Bun is absent on purpose. It keeps its registry in `bunfig.toml`, and we do not
|
|
14
|
+
* parse TOML; adding a dependency for it is a decision of its own, and our small
|
|
15
|
+
* runtime footprint is a stated product property. Half-reading the file with a
|
|
16
|
+
* regex would be worse than not reading it, because a wrong registry is the bug
|
|
17
|
+
* this module exists to fix. Bun therefore behaves exactly as it does today.
|
|
18
|
+
*/
|
|
19
|
+
const MANAGER_CONFIG = {
|
|
20
|
+
npm: { file: ".npmrc", format: "ini" },
|
|
21
|
+
pnpm: { file: ".npmrc", format: "ini" },
|
|
22
|
+
yarn: { file: ".yarnrc.yml", format: "yaml" },
|
|
23
|
+
};
|
|
24
|
+
const SCOPED_INI_KEY = /^(@[^:\s]+):registry$/;
|
|
25
|
+
/** Reads `key=value` lines, ignoring comments and section headers. */
|
|
26
|
+
function parseIni(contents) {
|
|
27
|
+
const values = new Map();
|
|
28
|
+
for (const rawLine of contents.split(/\r?\n/)) {
|
|
29
|
+
const line = rawLine.trim();
|
|
30
|
+
if (!line || line.startsWith("#") || line.startsWith(";") || line.startsWith("["))
|
|
31
|
+
continue;
|
|
32
|
+
const eq = line.indexOf("=");
|
|
33
|
+
if (eq === -1)
|
|
34
|
+
continue;
|
|
35
|
+
values.set(line.slice(0, eq).trim(), line.slice(eq + 1).trim());
|
|
36
|
+
}
|
|
37
|
+
return values;
|
|
38
|
+
}
|
|
39
|
+
function fromIni(contents) {
|
|
40
|
+
const values = parseIni(contents);
|
|
41
|
+
const scopes = {};
|
|
42
|
+
for (const [key, value] of values) {
|
|
43
|
+
const scoped = SCOPED_INI_KEY.exec(key);
|
|
44
|
+
if (scoped?.[1] && value)
|
|
45
|
+
scopes[scoped[1]] = value;
|
|
46
|
+
}
|
|
47
|
+
return { registry: values.get("registry") || null, scopes };
|
|
48
|
+
}
|
|
49
|
+
function fromYaml(contents) {
|
|
50
|
+
let doc;
|
|
51
|
+
try {
|
|
52
|
+
doc = YAML.parse(contents);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// A malformed config is the project's problem to fix, not a reason to fail a scan.
|
|
56
|
+
// Falling through to the public registry keeps today's behaviour.
|
|
57
|
+
return { registry: null, scopes: {} };
|
|
58
|
+
}
|
|
59
|
+
if (!doc || typeof doc !== "object")
|
|
60
|
+
return { registry: null, scopes: {} };
|
|
61
|
+
const record = doc;
|
|
62
|
+
const registry = typeof record.npmRegistryServer === "string" ? record.npmRegistryServer : null;
|
|
63
|
+
const scopes = {};
|
|
64
|
+
const npmScopes = record.npmScopes;
|
|
65
|
+
if (npmScopes && typeof npmScopes === "object") {
|
|
66
|
+
for (const [scope, entry] of Object.entries(npmScopes)) {
|
|
67
|
+
if (!entry || typeof entry !== "object")
|
|
68
|
+
continue;
|
|
69
|
+
const server = entry.npmRegistryServer;
|
|
70
|
+
// Yarn writes scopes without the leading @; normalise so lookup is uniform.
|
|
71
|
+
if (typeof server === "string" && server)
|
|
72
|
+
scopes[scope.startsWith("@") ? scope : `@${scope}`] = server;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { registry, scopes };
|
|
76
|
+
}
|
|
77
|
+
function readIfPresent(file) {
|
|
78
|
+
try {
|
|
79
|
+
return fs.existsSync(file) ? fs.readFileSync(file, "utf8") : null;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Resolves the registry in the order the package manager itself uses: an environment
|
|
87
|
+
* override first, then the project file, then the user's home file.
|
|
88
|
+
*
|
|
89
|
+
* `env` and `homeDir` are injectable so this is testable without touching the real
|
|
90
|
+
* environment or the developer's own config.
|
|
91
|
+
*/
|
|
92
|
+
export function resolveRegistryConfig(args) {
|
|
93
|
+
const env = args.env ?? process.env;
|
|
94
|
+
const homeDir = args.homeDir ?? os.homedir();
|
|
95
|
+
const envRegistry = env.NPM_CONFIG_REGISTRY || env.npm_config_registry;
|
|
96
|
+
if (envRegistry) {
|
|
97
|
+
return { registry: envRegistry, scopes: {}, sourceFile: "NPM_CONFIG_REGISTRY" };
|
|
98
|
+
}
|
|
99
|
+
const config = args.packageManager ? MANAGER_CONFIG[args.packageManager] : undefined;
|
|
100
|
+
if (!config)
|
|
101
|
+
return { registry: NPM_PUBLIC_REGISTRY, scopes: {}, sourceFile: null };
|
|
102
|
+
for (const dir of [args.projectPath, homeDir]) {
|
|
103
|
+
const file = path.join(dir, config.file);
|
|
104
|
+
const contents = readIfPresent(file);
|
|
105
|
+
if (contents === null)
|
|
106
|
+
continue;
|
|
107
|
+
const parsed = config.format === "ini" ? fromIni(contents) : fromYaml(contents);
|
|
108
|
+
// A file that exists but configures no registry is not an answer; keep looking,
|
|
109
|
+
// the way npm continues up its own config chain.
|
|
110
|
+
if (!parsed.registry && Object.keys(parsed.scopes).length === 0)
|
|
111
|
+
continue;
|
|
112
|
+
return {
|
|
113
|
+
registry: parsed.registry || NPM_PUBLIC_REGISTRY,
|
|
114
|
+
scopes: parsed.scopes,
|
|
115
|
+
sourceFile: file,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return { registry: NPM_PUBLIC_REGISTRY, scopes: {}, sourceFile: null };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Which package manager a lockfile source implies, so callers that know the scan
|
|
122
|
+
* source do not each repeat the mapping. Returns null for the package.json fallback,
|
|
123
|
+
* which has no lockfile and therefore no manager to read config for.
|
|
124
|
+
*/
|
|
125
|
+
export function packageManagerForSource(source) {
|
|
126
|
+
if (source === "package-lock" || source === "npm-shrinkwrap")
|
|
127
|
+
return "npm";
|
|
128
|
+
if (source === "pnpm-lock")
|
|
129
|
+
return "pnpm";
|
|
130
|
+
if (source === "yarn-lock")
|
|
131
|
+
return "yarn";
|
|
132
|
+
if (source === "bun-lock")
|
|
133
|
+
return "bun";
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
/** The registry a single package resolves through, honouring its scope. */
|
|
137
|
+
export function registryForPackage(config, packageName) {
|
|
138
|
+
if (packageName.startsWith("@")) {
|
|
139
|
+
const scope = packageName.split("/")[0];
|
|
140
|
+
if (scope && config.scopes[scope])
|
|
141
|
+
return config.scopes[scope];
|
|
142
|
+
}
|
|
143
|
+
return config.registry;
|
|
144
|
+
}
|
package/dist/utils/severity.js
CHANGED
|
@@ -16,6 +16,14 @@ export function reachesFailOn(findings, failOn) {
|
|
|
16
16
|
// cannot disagree. The parenthetical echoes the raw flag value: --fail-on is not
|
|
17
17
|
// validated and normalizeSeverity falls back to critical, so echoing the
|
|
18
18
|
// normalized level would show the user a value they never typed.
|
|
19
|
+
// The three finding classes the --fail-on gate ORs, as failingGateSummary
|
|
20
|
+
// names them. Both scan paths build their gate input from this one list, so
|
|
21
|
+
// the wording for a class cannot differ between a single- and multi-folder scan.
|
|
22
|
+
export const GATE_CLASS_LABELS = {
|
|
23
|
+
vulnerability: "vulnerability",
|
|
24
|
+
overrideHygiene: "override hygiene",
|
|
25
|
+
maintenanceRisk: "maintenance risk",
|
|
26
|
+
};
|
|
19
27
|
export function failingGateSummary(classes, failOn) {
|
|
20
28
|
if (!failOn)
|
|
21
29
|
return null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import dns from "node:dns";
|
|
2
2
|
import { URL } from "node:url";
|
|
3
3
|
const OFFICIAL_OSV_HOSTS = ["api.osv.dev"];
|
|
4
|
-
// IPv4 special-purpose CIDRs
|
|
4
|
+
// IPv4 special-purpose CIDRs - numerical match replaces error-prone regex
|
|
5
5
|
// https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
|
|
6
6
|
const PRIVATE_IPV4_CIDRS = [
|
|
7
7
|
"0.0.0.0/8", // "this network"
|
|
@@ -197,7 +197,7 @@ export async function validateOsvUrl(url, allowPrivate) {
|
|
|
197
197
|
if (isOfficialOsv(url))
|
|
198
198
|
return undefined;
|
|
199
199
|
// Layer 2: Resolve DNS and check ALL addresses
|
|
200
|
-
// Strip brackets from IPv6 literal hostnames
|
|
200
|
+
// Strip brackets from IPv6 literal hostnames - dns.lookup expects bare addresses
|
|
201
201
|
const lookupHost = stripIpv6Brackets(parsed.hostname);
|
|
202
202
|
const addresses = await new Promise((resolve, reject) => {
|
|
203
203
|
dns.lookup(lookupHost, { all: true }, (err, addresses) => {
|
|
@@ -215,7 +215,7 @@ export async function validateOsvUrl(url, allowPrivate) {
|
|
|
215
215
|
throw new Error(`--osv-url resolves to private/reserved IP (${ipList}). ` +
|
|
216
216
|
`Use --allow-private-osv-url for internal mirrors.`);
|
|
217
217
|
}
|
|
218
|
-
// Layer 3: Explicit bypass
|
|
218
|
+
// Layer 3: Explicit bypass - return warning for caller to emit
|
|
219
219
|
return (`Warning: --allow-private-osv-url is set. ` +
|
|
220
220
|
`Requests may access internal host (${ipList}).`);
|
|
221
221
|
}
|
package/dist/utils/version.js
CHANGED
|
@@ -10,7 +10,7 @@ export function looksLikeVersion(value) {
|
|
|
10
10
|
// through to the flat-token fallback, which would reintroduce the exact
|
|
11
11
|
// precedence bug this file fixes.
|
|
12
12
|
const VERSION_SHAPE = /^(\d+)\.(\d+)\.(\d+)(?:-([^/+]+))?(?:\+.*)?$/;
|
|
13
|
-
// module-level; safe to grow unbounded
|
|
13
|
+
// module-level; safe to grow unbounded - a single scan sees at most
|
|
14
14
|
// a few hundred unique version strings, and the cache is discarded when the process exits.
|
|
15
15
|
const parsedVersionCache = new Map();
|
|
16
16
|
export function getVersionCacheSize() {
|
|
@@ -124,6 +124,18 @@ export function isBreakingUpgrade(from, to) {
|
|
|
124
124
|
}
|
|
125
125
|
return false;
|
|
126
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* True when a recorded version is a local protocol reference rather than a
|
|
129
|
+
* released version: `workspace:` for a monorepo member, `file:` or `link:` for
|
|
130
|
+
* a path dependency. These name source the project supplies itself, so there is
|
|
131
|
+
* no published release of them to install and they can never be an upgrade
|
|
132
|
+
* target. Bun and Yarn write a `workspace:` reference into the lockfile for a
|
|
133
|
+
* member a sibling depends on, which is why such an entry can resolve to a
|
|
134
|
+
* PackageRef at all.
|
|
135
|
+
*/
|
|
136
|
+
export function isLocalProtocolVersion(version) {
|
|
137
|
+
return /^(?:workspace|file|link):/.test(version.trim());
|
|
138
|
+
}
|
|
127
139
|
export function isPreReleaseVersion(version) {
|
|
128
140
|
return /^\d+\.\d+\.\d+-[^\s]+$/.test(version);
|
|
129
141
|
}
|
|
@@ -266,6 +278,10 @@ export function positionAgainstRange(version, range) {
|
|
|
266
278
|
return "outside";
|
|
267
279
|
}
|
|
268
280
|
catch {
|
|
281
|
+
// satisfies guards the SemVer constructor inside Range.test(), which catches
|
|
282
|
+
// and returns false; ltr/gtr route through outside(), which does not. Only
|
|
283
|
+
// the latter two throw, and only on a component above MAX_SAFE_INTEGER.
|
|
284
|
+
// Keep the guard: dropping it reintroduces the crash for those two calls.
|
|
269
285
|
return null;
|
|
270
286
|
}
|
|
271
287
|
}
|
package/dist/utils/vuln.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { inferSeverity } from "../osv/severity.js";
|
|
2
|
+
import { severityOrder } from "../constants.js";
|
|
1
3
|
import { unique } from "./array.js";
|
|
2
4
|
// MAL-* is the OSV prefix for malicious code advisories. Guarded because OSV
|
|
3
5
|
// records are external data - the declared `string` type on OsvVuln.id does
|
|
@@ -14,3 +16,76 @@ export function hasMaliciousAdvisory(vulns) {
|
|
|
14
16
|
export function extractCveAliases(vulns) {
|
|
15
17
|
return unique(vulns.flatMap(v => (v.aliases ?? []).filter((a) => typeof a === "string" && a.startsWith("CVE-"))));
|
|
16
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Collapses advisory records that OSV says are the same vulnerability.
|
|
21
|
+
*
|
|
22
|
+
* Two databases can both describe one flaw, and OSV records that by having each
|
|
23
|
+
* entry list the other in `aliases`. We read OSV faithfully, so both arrive and
|
|
24
|
+
* one vulnerability is reported twice on the same package. Real examples:
|
|
25
|
+
* `GHSA-f23m-r3pf-42rh` and `GHSA-xxjr-mmjv-4gpg` for a lodash prototype
|
|
26
|
+
* pollution, and `EEF-CVE-2026-56812` and `GHSA-63mc-hw7g-86rr` for phoenix,
|
|
27
|
+
* which crosses two databases.
|
|
28
|
+
*
|
|
29
|
+
* The test is deliberately mutual naming and nothing weaker. OSV aliasing is not
|
|
30
|
+
* always symmetric, so a one-directional reference can mean "related to" rather
|
|
31
|
+
* than "the same as", and a shared CVE is weaker still, since two advisories may
|
|
32
|
+
* legitimately cite one CVE.
|
|
33
|
+
*
|
|
34
|
+
* The survivor keeps the higher severity, so `maxSeverity` cannot change, and
|
|
35
|
+
* ties break on the smaller id so output is stable run to run. Its alias set
|
|
36
|
+
* absorbs the dropped id, which is the part that matters: the accuracy sweep
|
|
37
|
+
* compares our advisory ids against OSV's, and losing an id would read as a
|
|
38
|
+
* missed advisory rather than a de-duplicated one.
|
|
39
|
+
*/
|
|
40
|
+
export function collapseAliasedDuplicates(vulns) {
|
|
41
|
+
if (vulns.length < 2)
|
|
42
|
+
return [...vulns];
|
|
43
|
+
const aliasesOf = new Map();
|
|
44
|
+
for (const v of vulns) {
|
|
45
|
+
// The filter is not about throwing; nothing here calls a string method on an
|
|
46
|
+
// alias. It keeps a malformed entry out of the survivor's `aliases`, which is
|
|
47
|
+
// typed string[] and is serialised into the JSON and SARIF payloads.
|
|
48
|
+
aliasesOf.set(v.id, new Set((v.aliases ?? []).filter((a) => typeof a === "string")));
|
|
49
|
+
}
|
|
50
|
+
const absorbedBy = new Map();
|
|
51
|
+
for (const a of vulns) {
|
|
52
|
+
if (absorbedBy.has(a.id))
|
|
53
|
+
continue;
|
|
54
|
+
for (const b of vulns) {
|
|
55
|
+
if (a.id === b.id || absorbedBy.has(b.id))
|
|
56
|
+
continue;
|
|
57
|
+
if (!aliasesOf.get(a.id)?.has(b.id) || !aliasesOf.get(b.id)?.has(a.id))
|
|
58
|
+
continue;
|
|
59
|
+
const keep = preferred(a, b);
|
|
60
|
+
absorbedBy.set(keep.id === a.id ? b.id : a.id, keep.id);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (absorbedBy.size === 0)
|
|
64
|
+
return [...vulns];
|
|
65
|
+
return vulns
|
|
66
|
+
.filter(v => !absorbedBy.has(v.id))
|
|
67
|
+
.map(v => {
|
|
68
|
+
const absorbed = [...absorbedBy.entries()].filter(([, keptId]) => keptId === v.id);
|
|
69
|
+
if (absorbed.length === 0)
|
|
70
|
+
return v;
|
|
71
|
+
// The survivor already lists every absorbed id, because mutual naming is
|
|
72
|
+
// what qualified them to merge. Only the absorbed records' OTHER aliases,
|
|
73
|
+
// typically the CVE ids, need pulling across.
|
|
74
|
+
const ids = new Set(aliasesOf.get(v.id) ?? []);
|
|
75
|
+
for (const [droppedId] of absorbed) {
|
|
76
|
+
for (const a of aliasesOf.get(droppedId) ?? []) {
|
|
77
|
+
if (a !== v.id)
|
|
78
|
+
ids.add(a);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return { ...v, aliases: [...ids].sort() };
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/** Higher severity wins; the smaller id breaks a tie so the result is stable. */
|
|
85
|
+
function preferred(a, b) {
|
|
86
|
+
const ra = severityOrder[inferSeverity(a)];
|
|
87
|
+
const rb = severityOrder[inferSeverity(b)];
|
|
88
|
+
if (ra !== rb)
|
|
89
|
+
return ra > rb ? a : b;
|
|
90
|
+
return a.id <= b.id ? a : b;
|
|
91
|
+
}
|