cve-lite-cli 1.38.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/args.js +1 -1
- 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/context-builder.js +33 -5
- package/dist/overrides/detectors/oa005-nested-ineffective.js +50 -2
- 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 +86 -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/node-builtins.js +32 -0
- 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 +21 -1
- package/dist/utils/vuln.js +75 -0
- package/package.json +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { DEFAULT_BATCH_SIZE, DEFAULT_SEARCH_DEPTH } from "../constants.js";
|
|
2
|
+
export function summarizeEffectiveOptions(options) {
|
|
3
|
+
const summary = {
|
|
4
|
+
json: options.json ?? false,
|
|
5
|
+
debug: options.debug ?? false,
|
|
6
|
+
verbose: options.verbose ?? false,
|
|
7
|
+
fix: options.fix ?? false,
|
|
8
|
+
ratchet: options.ratchet ?? false,
|
|
9
|
+
createPr: options.createPr ?? false,
|
|
10
|
+
prodOnly: options.prodOnly ?? false,
|
|
11
|
+
offline: options.offline ?? false,
|
|
12
|
+
all: options.all ?? false,
|
|
13
|
+
onlyUsed: options.onlyUsed ?? false,
|
|
14
|
+
noOpen: options.noOpen ?? false,
|
|
15
|
+
noCache: options.noCache ?? false,
|
|
16
|
+
sarif: options.sarif ?? false,
|
|
17
|
+
cdx: options.cdx ?? false,
|
|
18
|
+
sbomInventoryOnly: options.sbomInventoryOnly ?? false,
|
|
19
|
+
checkOverrides: options.checkOverrides ?? false,
|
|
20
|
+
checkMaintenance: options.checkMaintenance ?? false,
|
|
21
|
+
checkLicenses: options.checkLicenses ?? false,
|
|
22
|
+
checkNetwork: options.checkNetwork ?? false,
|
|
23
|
+
allowPrivateOsvUrl: options.allowPrivateOsvUrl ?? false,
|
|
24
|
+
usage: options.usage ?? false,
|
|
25
|
+
failOn: options.failOn,
|
|
26
|
+
incompletePolicy: options.incompletePolicy,
|
|
27
|
+
// Same normalization as the CLI entrypoint (src/index.ts).
|
|
28
|
+
batchSize: Number(options.batchSize || DEFAULT_BATCH_SIZE),
|
|
29
|
+
searchDepth: Math.max(0, Number(options.searchDepth || DEFAULT_SEARCH_DEPTH)),
|
|
30
|
+
};
|
|
31
|
+
if (options.minSeverity !== undefined)
|
|
32
|
+
summary.minSeverity = options.minSeverity;
|
|
33
|
+
if (options.sbom !== undefined)
|
|
34
|
+
summary.sbom = options.sbom;
|
|
35
|
+
if (options.rule !== undefined)
|
|
36
|
+
summary.rule = options.rule;
|
|
37
|
+
if (options.prBase !== undefined)
|
|
38
|
+
summary.prBase = options.prBase;
|
|
39
|
+
// Path/URL options: record only that they were set, never the value.
|
|
40
|
+
if (options.offlineDb)
|
|
41
|
+
summary.offlineDb = true;
|
|
42
|
+
if (options.cacheDir)
|
|
43
|
+
summary.cacheDir = true;
|
|
44
|
+
if (options.osvUrl)
|
|
45
|
+
summary.osvUrl = true;
|
|
46
|
+
if (options.output)
|
|
47
|
+
summary.output = true;
|
|
48
|
+
if (options.caCert)
|
|
49
|
+
summary.caCert = true;
|
|
50
|
+
if (options.auditLog)
|
|
51
|
+
summary.auditLog = true;
|
|
52
|
+
if (options.report)
|
|
53
|
+
summary.report = true;
|
|
54
|
+
return summary;
|
|
55
|
+
}
|
package/dist/utils/finding.js
CHANGED
|
@@ -12,7 +12,7 @@ export function getPrimaryParent(finding) {
|
|
|
12
12
|
/**
|
|
13
13
|
* Unique root (top-level) dependencies that pull in this package, derived from
|
|
14
14
|
* every known dependencyPaths chain. Paths of length < 3 (direct dependencies,
|
|
15
|
-
* where the package itself is path[1]) are excluded
|
|
15
|
+
* where the package itself is path[1]) are excluded - there is no meaningful
|
|
16
16
|
* root distinct from the package.
|
|
17
17
|
*
|
|
18
18
|
* Gated on relationship === "transitive": a package can be a direct dependency
|
package/dist/utils/fix-runner.js
CHANGED
|
@@ -111,8 +111,9 @@ export async function applyFixesIfRequested(params) {
|
|
|
111
111
|
const spinner = createSpinner(`Applying safe package fixes with ${commandLabel}... 0/${total}`, params.options);
|
|
112
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
113
|
// parent-update is keyed per child, so two children behind one parent produce
|
|
114
|
-
// two targets
|
|
115
|
-
//
|
|
114
|
+
// two targets. npm update names the child, so those commands differ. Two
|
|
115
|
+
// parents that refresh the same child can still share `npm update <child>`.
|
|
116
|
+
// Spawn each command once; the displayed plan already dedupes the same way.
|
|
116
117
|
const seenCommands = new Set();
|
|
117
118
|
for (let i = 0; i < applyTargets.length; i++) {
|
|
118
119
|
const target = applyTargets[i];
|
package/dist/utils/network.js
CHANGED
|
@@ -11,7 +11,7 @@ export function extractErrorMessage(error) {
|
|
|
11
11
|
}
|
|
12
12
|
export function sslCertificateErrorHint() {
|
|
13
13
|
return [
|
|
14
|
-
"Hint: SSL certificate error
|
|
14
|
+
"Hint: SSL certificate error. Your network may be using a corporate proxy that intercepts HTTPS traffic.",
|
|
15
15
|
"Fix (recommended): save your corporate CA certificate path once:",
|
|
16
16
|
" cve-lite config set ca-cert /path/to/corporate-ca.crt",
|
|
17
17
|
"Or pass it per-invocation:",
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { builtinModules } from "node:module";
|
|
2
|
+
/**
|
|
3
|
+
* Identifies import specifiers that resolve to a Node built-in module rather
|
|
4
|
+
* than to an npm package.
|
|
5
|
+
*
|
|
6
|
+
* Phantom-dependency rules compare imported names against declared
|
|
7
|
+
* dependencies, so a built-in has to be excluded before that comparison: it
|
|
8
|
+
* needs no declaration, and telling someone to install it points them at an
|
|
9
|
+
* unrelated npm shim.
|
|
10
|
+
*/
|
|
11
|
+
const NODE_PREFIX = "node:";
|
|
12
|
+
const BUILTIN_NAMES = new Set(builtinModules);
|
|
13
|
+
/**
|
|
14
|
+
* True when the specifier is a Node built-in.
|
|
15
|
+
*
|
|
16
|
+
* Two cases, and both are needed. `builtinModules` lists the bare names
|
|
17
|
+
* (`events`, `string_decoder`), but it deliberately omits the modules that
|
|
18
|
+
* exist only behind the prefix, so `test`, `sea` and `sqlite` are absent from
|
|
19
|
+
* it. Node also rejects any unknown `node:` specifier rather than falling back
|
|
20
|
+
* to the registry, so the prefix alone is proof of intent and nothing on npm
|
|
21
|
+
* can claim it.
|
|
22
|
+
*
|
|
23
|
+
* Subpaths resolve on their first segment, so `node:fs/promises` and
|
|
24
|
+
* `stream/web` are both recognised. A scoped package is unaffected, since
|
|
25
|
+
* `@scope` is never a built-in name.
|
|
26
|
+
*/
|
|
27
|
+
export function isNodeBuiltinSpecifier(specifier) {
|
|
28
|
+
if (specifier.startsWith(NODE_PREFIX))
|
|
29
|
+
return true;
|
|
30
|
+
const firstSegment = specifier.split("/")[0];
|
|
31
|
+
return BUILTIN_NAMES.has(firstSegment);
|
|
32
|
+
}
|
|
@@ -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
|
}
|
|
@@ -251,6 +263,10 @@ export function positionAgainstRange(version, range) {
|
|
|
251
263
|
// change the classification below, so the comparisons take the raw range.
|
|
252
264
|
if (!normalizedVersion || !semver.validRange(trimmedRange, { loose: true }))
|
|
253
265
|
return null;
|
|
266
|
+
// includePrerelease is deliberate and must not be dropped. Without it semver
|
|
267
|
+
// excludes a prerelease from a range it should satisfy, so a prerelease sitting
|
|
268
|
+
// inside a vulnerable range reads as safe. That was a real false negative, fixed
|
|
269
|
+
// in v1.34.0, and this flag is what keeps it fixed.
|
|
254
270
|
const options = { loose: true, includePrerelease: true };
|
|
255
271
|
try {
|
|
256
272
|
if (semver.satisfies(normalizedVersion, trimmedRange, options))
|
|
@@ -262,6 +278,10 @@ export function positionAgainstRange(version, range) {
|
|
|
262
278
|
return "outside";
|
|
263
279
|
}
|
|
264
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.
|
|
265
285
|
return null;
|
|
266
286
|
}
|
|
267
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
|
+
}
|