cve-lite-cli 1.40.0 → 1.41.1
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 +17 -11
- package/dist/advisory/local-advisory-source.js +9 -5
- package/dist/advisory/local-db.js +91 -13
- package/dist/advisory/osv-sync.js +187 -56
- package/dist/advisory/staging-directory.js +112 -0
- package/dist/cli/advisories-sync.js +16 -2
- package/dist/cli/args.js +46 -35
- package/dist/cli/config.js +4 -1
- package/dist/cli/help.js +4 -3
- package/dist/cli/validate.js +23 -1
- package/dist/constants.js +11 -25
- package/dist/index.js +8 -3
- package/dist/output/cyclonedx.js +23 -14
- package/dist/output/debug.js +68 -18
- package/dist/output/formatters.js +33 -5
- package/dist/output/html-reporter.js +55 -5
- package/dist/output/multi-folder-html-reporter.js +59 -3
- package/dist/output/output-dir.js +193 -7
- package/dist/output/override-fix-command.js +5 -7
- package/dist/output/printers.js +16 -5
- package/dist/output/sarif.js +131 -48
- package/dist/output/sbom-dependency-edges.js +16 -10
- package/dist/output/sbom-file.js +14 -6
- package/dist/output/scan-json.js +21 -3
- package/dist/output/spdx.js +61 -23
- package/dist/output/spinner.js +2 -1
- package/dist/output/write-outputs.js +142 -52
- package/dist/overrides/context-builder.js +23 -70
- package/dist/overrides/parsing/registry.js +19 -69
- package/dist/parsers/bun-lock.js +1 -2
- package/dist/parsers/index.js +22 -1
- package/dist/parsers/npm-lock-graph.js +39 -1
- package/dist/parsers/package-lock.js +25 -5
- package/dist/parsers/pnpm-lock.js +3 -2
- package/dist/parsers/utils.js +5 -3
- package/dist/parsers/yarn-lock-graph.js +36 -17
- package/dist/parsers/yarn-lock.js +92 -25
- package/dist/remediation/fix-commands.js +101 -45
- package/dist/remediation/npm-registry.js +10 -2
- package/dist/remediation/npm-transitive-graph.js +30 -72
- package/dist/remediation/npm-transitive-resolution.js +24 -77
- package/dist/remediation/parent-upgrade-blockers.js +51 -0
- package/dist/remediation/parent-upgrade.js +5 -79
- package/dist/remediation/registry-parent-ranges.js +21 -0
- package/dist/remediation/transitive-chain-resolver.js +3 -3
- package/dist/scan/completeness.js +10 -4
- package/dist/scan/multi-folder-scan.js +133 -58
- package/dist/scan/override-audit.js +6 -4
- package/dist/scan/single-scan.js +41 -25
- package/dist/scanner.js +263 -58
- package/dist/usage/scanner.js +19 -8
- package/dist/utils/array.js +11 -3
- package/dist/utils/checked-address-policy.js +44 -0
- package/dist/utils/debug-bundle.js +118 -0
- package/dist/utils/debug-project.js +102 -0
- package/dist/utils/debug-redaction.js +117 -0
- package/dist/utils/file.js +2 -1
- package/dist/utils/fix-runner.js +95 -13
- package/dist/utils/import-type-queries.js +322 -0
- package/dist/utils/network.js +14 -9
- package/dist/utils/npm-lockfile.js +12 -0
- package/dist/utils/osv-fetch.js +34 -0
- package/dist/utils/package-identity.js +43 -0
- package/dist/utils/package-manager-source.js +24 -0
- package/dist/utils/purl.js +37 -0
- package/dist/utils/registry-config.js +47 -15
- package/dist/utils/registry-fetch.js +42 -0
- package/dist/utils/shell-quote.js +12 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/validate-url.js +1 -1
- package/dist/utils/version.js +30 -7
- package/dist/utils/versions/osv-range.js +191 -0
- package/dist/utils/versions/pep440.js +246 -0
- package/dist/utils/versions/scheme.js +10 -0
- package/package.json +3 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { NPM_PUBLIC_REGISTRY } from "../constants.js";
|
|
2
|
+
import { createCheckedAddressPolicy } from "./checked-address-policy.js";
|
|
3
|
+
import { createCertAwareFetch } from "./network.js";
|
|
4
|
+
export class RegistryNetworkPolicyError extends Error {
|
|
5
|
+
}
|
|
6
|
+
const publicRegistryPolicy = createCheckedAddressPolicy({
|
|
7
|
+
allowPrivate: false,
|
|
8
|
+
invalidAddressMessage: "Repository registry resolves to a private/reserved or invalid address",
|
|
9
|
+
privateAddressError: () => new RegistryNetworkPolicyError("Repository registry resolves to a private/reserved address"),
|
|
10
|
+
missingFamilyMessage: "Registry has no address for the requested IP family",
|
|
11
|
+
});
|
|
12
|
+
/** Repository settings select metadata sources, not permission to access internal services. */
|
|
13
|
+
export async function fetchRegistryMetadata(base, requestUrl, allowPrivate, init, fetchImpl) {
|
|
14
|
+
const registry = new URL(base);
|
|
15
|
+
if (registry.username || registry.password || registry.search || registry.hash || base.includes("?") || base.includes("#")) {
|
|
16
|
+
throw new Error("Registry URL must not contain credentials, a query or a fragment");
|
|
17
|
+
}
|
|
18
|
+
if (registry.protocol === "http:" && !allowPrivate) {
|
|
19
|
+
throw new RegistryNetworkPolicyError("Repository registry requires HTTPS");
|
|
20
|
+
}
|
|
21
|
+
if (registry.protocol !== "https:" && registry.protocol !== "http:") {
|
|
22
|
+
throw new Error("Registry URL must use HTTP or HTTPS");
|
|
23
|
+
}
|
|
24
|
+
const target = new URL(requestUrl);
|
|
25
|
+
if (target.origin !== registry.origin)
|
|
26
|
+
throw new Error("Registry request changed origin");
|
|
27
|
+
const ca = process.env.NODE_EXTRA_CA_CERTS;
|
|
28
|
+
const official = registry.origin === new URL(NPM_PUBLIC_REGISTRY).origin;
|
|
29
|
+
let transport;
|
|
30
|
+
if (allowPrivate || official) {
|
|
31
|
+
transport = fetchImpl ?? (ca && registry.protocol === "https:" ? createCertAwareFetch(ca) : fetch);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
publicRegistryPolicy.checkLiteral(target.hostname);
|
|
35
|
+
transport = createCertAwareFetch(ca, publicRegistryPolicy.lookup);
|
|
36
|
+
}
|
|
37
|
+
// Use the canonical URL so alternate HTTPS spellings still use the checked transport.
|
|
38
|
+
const response = await transport(target.href, { ...init, redirect: "error" });
|
|
39
|
+
if (response.status >= 300 && response.status < 400)
|
|
40
|
+
throw new Error("Registry redirects are not permitted");
|
|
41
|
+
return response;
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/** Quote a token for a command the user may paste into a POSIX shell. */
|
|
3
|
+
export function shellQuote(token) {
|
|
4
|
+
if (/^[A-Za-z0-9_@%+./:=,-]+$/.test(token))
|
|
5
|
+
return token;
|
|
6
|
+
return "'" + token.replace(/'/g, "'\\''") + "'";
|
|
7
|
+
}
|
|
8
|
+
export function quoteShellPath(directory) {
|
|
9
|
+
// Preserve literal backslashes in POSIX names and keep ordinary Windows paths unquoted.
|
|
10
|
+
const normalized = path.sep === "\\" ? directory.replace(/\\/g, "/") : directory;
|
|
11
|
+
return shellQuote(normalized.startsWith("-") ? `./${normalized}` : normalized);
|
|
12
|
+
}
|
package/dist/utils/string.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
export function pluralize(count, singular, plural = `${singular}s`) {
|
|
2
2
|
return count === 1 ? singular : plural;
|
|
3
3
|
}
|
|
4
|
+
/** End diagnostic text as a sentence without duplicating existing punctuation. */
|
|
5
|
+
export function ensureSentence(message) {
|
|
6
|
+
const text = message.trimEnd();
|
|
7
|
+
return text && !/[.!?]$/.test(text) ? `${text}.` : text;
|
|
8
|
+
}
|
|
9
|
+
export function isOutputStdout(output) {
|
|
10
|
+
return output?.trim() === "-";
|
|
11
|
+
}
|
|
4
12
|
/** Known top-level cve-lite commands, for typo suggestions on a mistyped first argument. */
|
|
5
13
|
const KNOWN_COMMANDS = ["advisories", "install-skill", "config", "overrides"];
|
|
6
14
|
/**
|
|
@@ -181,7 +181,7 @@ export function isPrivateOrReservedIp(ip) {
|
|
|
181
181
|
return isPrivateOrReservedIpv6(ip);
|
|
182
182
|
}
|
|
183
183
|
// Strip brackets from IPv6 literal hostnames (e.g. "[::1]" → "::1")
|
|
184
|
-
function stripIpv6Brackets(hostname) {
|
|
184
|
+
export function stripIpv6Brackets(hostname) {
|
|
185
185
|
if (hostname.startsWith("[") && hostname.endsWith("]")) {
|
|
186
186
|
return hostname.slice(1, -1);
|
|
187
187
|
}
|
package/dist/utils/version.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import semver from "semver";
|
|
2
|
-
|
|
2
|
+
import { pep440Scheme } from "./versions/pep440.js";
|
|
3
|
+
// `filter` and `map` pass the element index as an extra argument. `sort` does
|
|
4
|
+
// not. A non-string argument stays on the npm path. Only the ecosystem name
|
|
5
|
+
// "pypi" selects PEP 440. Callers that omit it keep the historical semver behavior.
|
|
6
|
+
export function isPep440Ecosystem(ecosystem) {
|
|
7
|
+
return typeof ecosystem === "string" && ecosystem.trim().toLowerCase() === "pypi";
|
|
8
|
+
}
|
|
9
|
+
export function looksLikeVersion(value, ecosystem) {
|
|
10
|
+
if (isPep440Ecosystem(ecosystem))
|
|
11
|
+
return pep440Scheme.looksLikeVersion(value);
|
|
3
12
|
return /^[0-9]+\.[0-9]+\.[0-9]+(?:[-+][^/]+)?$/.test(value);
|
|
4
13
|
}
|
|
5
14
|
// Matches a well-formed X.Y.Z version, capturing an optional dot-separated
|
|
@@ -93,7 +102,9 @@ function comparePrerelease(a, b) {
|
|
|
93
102
|
}
|
|
94
103
|
return 0;
|
|
95
104
|
}
|
|
96
|
-
export function compareVersions(a, b) {
|
|
105
|
+
export function compareVersions(a, b, ecosystem) {
|
|
106
|
+
if (isPep440Ecosystem(ecosystem))
|
|
107
|
+
return pep440Scheme.compare(a, b);
|
|
97
108
|
const pa = parseVersion(a);
|
|
98
109
|
const pb = parseVersion(b);
|
|
99
110
|
if (!pa || !pb)
|
|
@@ -111,8 +122,8 @@ export function parseExactManifestVersion(spec) {
|
|
|
111
122
|
return null;
|
|
112
123
|
}
|
|
113
124
|
export function isBreakingUpgrade(from, to) {
|
|
114
|
-
const [fromMajor, fromMinor] = from.split(".").map(
|
|
115
|
-
const [toMajor, toMinor] = to.split(".").map(
|
|
125
|
+
const [fromMajor, fromMinor, fromPatch] = from.split(".").map(n => parseInt(n, 10));
|
|
126
|
+
const [toMajor, toMinor, toPatch] = to.split(".").map(n => parseInt(n, 10));
|
|
116
127
|
if (Number.isNaN(fromMajor) || Number.isNaN(toMajor))
|
|
117
128
|
return false;
|
|
118
129
|
if (toMajor > fromMajor)
|
|
@@ -120,7 +131,15 @@ export function isBreakingUpgrade(from, to) {
|
|
|
120
131
|
// Under semver, 0.x releases treat the minor as the breaking position
|
|
121
132
|
// (^0.21.1 resolves to >=0.21.1 <0.22.0), so a 0.x cross-minor bump is breaking.
|
|
122
133
|
if (fromMajor === 0 && toMajor === 0) {
|
|
123
|
-
|
|
134
|
+
if (Number.isNaN(fromMinor) || Number.isNaN(toMinor))
|
|
135
|
+
return false;
|
|
136
|
+
if (toMinor > fromMinor)
|
|
137
|
+
return true;
|
|
138
|
+
// 0.0.x releases treat the patch as the breaking position (^0.0.3 resolves
|
|
139
|
+
// to >=0.0.3 <0.0.4), so any 0.0.x patch bump is breaking.
|
|
140
|
+
if (fromMinor === 0 && toMinor === 0) {
|
|
141
|
+
return !Number.isNaN(fromPatch) && !Number.isNaN(toPatch) && toPatch > fromPatch;
|
|
142
|
+
}
|
|
124
143
|
}
|
|
125
144
|
return false;
|
|
126
145
|
}
|
|
@@ -136,7 +155,9 @@ export function isBreakingUpgrade(from, to) {
|
|
|
136
155
|
export function isLocalProtocolVersion(version) {
|
|
137
156
|
return /^(?:workspace|file|link):/.test(version.trim());
|
|
138
157
|
}
|
|
139
|
-
export function isPreReleaseVersion(version) {
|
|
158
|
+
export function isPreReleaseVersion(version, ecosystem) {
|
|
159
|
+
if (isPep440Ecosystem(ecosystem))
|
|
160
|
+
return pep440Scheme.isPreRelease(version);
|
|
140
161
|
return /^\d+\.\d+\.\d+-[^\s]+$/.test(version);
|
|
141
162
|
}
|
|
142
163
|
export function normalizeRawVersion(value) {
|
|
@@ -220,7 +241,9 @@ export function coerceVersion(input) {
|
|
|
220
241
|
* override specs, where a bare `1.22` is the range `1.22.x` rather than 1.22.0.
|
|
221
242
|
*/
|
|
222
243
|
const ADVISORY_VERSION = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$/;
|
|
223
|
-
export function normalizeAdvisoryVersion(value) {
|
|
244
|
+
export function normalizeAdvisoryVersion(value, ecosystem) {
|
|
245
|
+
if (isPep440Ecosystem(ecosystem))
|
|
246
|
+
return pep440Scheme.normalizeAdvisoryVersion(value);
|
|
224
247
|
if (!value)
|
|
225
248
|
return null;
|
|
226
249
|
const match = ADVISORY_VERSION.exec(value.trim());
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { compareVersions, normalizeAdvisoryVersion } from "../version.js";
|
|
2
|
+
/**
|
|
3
|
+
* Affected windows of one PyPI range.
|
|
4
|
+
*
|
|
5
|
+
* Events are sorted by PEP 440 order before they are paired, so a range
|
|
6
|
+
* written with the 2.x fix ahead of the 1.x fix describes the same windows
|
|
7
|
+
* as the sorted form. `introduced: "0"` sorts before every version, including
|
|
8
|
+
* `0.dev0`. Equal versions keep file order.
|
|
9
|
+
*
|
|
10
|
+
* The walk follows the OSV evaluation: an introduced opens a window, a later
|
|
11
|
+
* introduced does not split a window that is already open, `fixed` closes it
|
|
12
|
+
* exclusively, and `last_affected` closes it inclusively. A version is affected
|
|
13
|
+
* when it sits in any of those windows. A fix from one window cannot clear
|
|
14
|
+
* another.
|
|
15
|
+
*
|
|
16
|
+
* A boundary that does not parse is left off the timeline. An unreadable
|
|
17
|
+
* `fixed` or `last_affected` also drops a trailing open window, because that
|
|
18
|
+
* boundary might have closed it. Events after that closer are a new range,
|
|
19
|
+
* so a later fix cannot close the window the unreadable value may already
|
|
20
|
+
* have closed.
|
|
21
|
+
*/
|
|
22
|
+
export function readPep440Range(events) {
|
|
23
|
+
const segments = splitAtUnreadableClosers(events);
|
|
24
|
+
if (segments.length <= 1)
|
|
25
|
+
return readPep440Segment(events);
|
|
26
|
+
const windows = [];
|
|
27
|
+
const fixes = [];
|
|
28
|
+
const unreadable = [];
|
|
29
|
+
for (const segment of segments) {
|
|
30
|
+
const read = readPep440Segment(segment);
|
|
31
|
+
windows.push(...read.windows);
|
|
32
|
+
fixes.push(...read.fixes);
|
|
33
|
+
unreadable.push(...read.unreadable);
|
|
34
|
+
}
|
|
35
|
+
return { windows, fixes, unreadable };
|
|
36
|
+
}
|
|
37
|
+
function splitAtUnreadableClosers(events) {
|
|
38
|
+
const segments = [];
|
|
39
|
+
let current = [];
|
|
40
|
+
for (const event of events) {
|
|
41
|
+
current.push(event);
|
|
42
|
+
const fixedUnreadable = event.fixed !== undefined && !normalizeAdvisoryVersion(event.fixed, "PyPI");
|
|
43
|
+
const lastUnreadable = event.last_affected !== undefined && !normalizeAdvisoryVersion(event.last_affected, "PyPI");
|
|
44
|
+
if (fixedUnreadable || lastUnreadable) {
|
|
45
|
+
segments.push(current);
|
|
46
|
+
current = [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (current.length > 0)
|
|
50
|
+
segments.push(current);
|
|
51
|
+
return segments;
|
|
52
|
+
}
|
|
53
|
+
function readPep440Segment(events) {
|
|
54
|
+
const points = [];
|
|
55
|
+
const unreadable = [];
|
|
56
|
+
const fixes = [];
|
|
57
|
+
const lowerBound = unreadableLowerBound(events);
|
|
58
|
+
let index = 0;
|
|
59
|
+
for (const event of events) {
|
|
60
|
+
if (event.introduced !== undefined) {
|
|
61
|
+
pushBoundary(points, unreadable, "introduced", event.introduced, index, lowerBound);
|
|
62
|
+
index += 1;
|
|
63
|
+
}
|
|
64
|
+
if (event.fixed !== undefined) {
|
|
65
|
+
const canon = normalizeAdvisoryVersion(event.fixed, "PyPI");
|
|
66
|
+
if (canon)
|
|
67
|
+
fixes.push(canon);
|
|
68
|
+
pushBoundary(points, unreadable, "fixed", event.fixed, index, lowerBound);
|
|
69
|
+
index += 1;
|
|
70
|
+
}
|
|
71
|
+
if (event.last_affected !== undefined) {
|
|
72
|
+
pushBoundary(points, unreadable, "last_affected", event.last_affected, index, lowerBound);
|
|
73
|
+
index += 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
points.sort((left, right) => {
|
|
77
|
+
const leftSentinel = left.kind === "introduced" && left.raw === "0";
|
|
78
|
+
const rightSentinel = right.kind === "introduced" && right.raw === "0";
|
|
79
|
+
if (leftSentinel !== rightSentinel)
|
|
80
|
+
return leftSentinel ? -1 : 1;
|
|
81
|
+
if (!leftSentinel) {
|
|
82
|
+
const compared = compareVersions(left.canonical, right.canonical, "PyPI");
|
|
83
|
+
if (compared !== 0)
|
|
84
|
+
return compared;
|
|
85
|
+
}
|
|
86
|
+
return left.index - right.index;
|
|
87
|
+
});
|
|
88
|
+
const windows = [];
|
|
89
|
+
let open = false;
|
|
90
|
+
let introduced = null;
|
|
91
|
+
for (const point of points) {
|
|
92
|
+
if (point.kind === "introduced") {
|
|
93
|
+
if (!open) {
|
|
94
|
+
open = true;
|
|
95
|
+
introduced = storedIntroduced(point);
|
|
96
|
+
}
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (!open)
|
|
100
|
+
continue;
|
|
101
|
+
windows.push({
|
|
102
|
+
introduced,
|
|
103
|
+
fixed: point.kind === "fixed" ? point.canonical : null,
|
|
104
|
+
lastAffected: point.kind === "last_affected" ? point.canonical : null,
|
|
105
|
+
});
|
|
106
|
+
open = false;
|
|
107
|
+
introduced = null;
|
|
108
|
+
}
|
|
109
|
+
const unreadableCloser = unreadable.some(boundary => boundary.field === "fixed" || boundary.field === "last_affected");
|
|
110
|
+
if (open && !unreadableCloser) {
|
|
111
|
+
windows.push({ introduced, fixed: null, lastAffected: null });
|
|
112
|
+
}
|
|
113
|
+
return { windows, fixes, unreadable };
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The raw event `"0"` is the OSV sentinel. A version whose canonical form is
|
|
117
|
+
* also `"0"` (`v0`, `00`, `0!0`) is version 0, stored as `"0.0"` so a caller
|
|
118
|
+
* does not treat it as the sentinel.
|
|
119
|
+
*/
|
|
120
|
+
function storedIntroduced(point) {
|
|
121
|
+
if (point.raw === "0")
|
|
122
|
+
return "0";
|
|
123
|
+
if (point.canonical === "0")
|
|
124
|
+
return "0.0";
|
|
125
|
+
return point.canonical;
|
|
126
|
+
}
|
|
127
|
+
function pushBoundary(points, unreadable, field, value, index, lowerBound) {
|
|
128
|
+
if (field === "introduced" && value === "0") {
|
|
129
|
+
points.push({ kind: field, raw: value, canonical: "0", index });
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const canonical = normalizeAdvisoryVersion(value, "PyPI");
|
|
133
|
+
if (!canonical) {
|
|
134
|
+
unreadable.push({ field, value, introduced: lowerBound });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
points.push({ kind: field, raw: value, canonical, index });
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The introduced value stored beside an unreadable boundary.
|
|
141
|
+
* A version below every concrete introduced value is outside every window,
|
|
142
|
+
* so the caller can ignore the unreadable boundary for that version.
|
|
143
|
+
*/
|
|
144
|
+
function unreadableLowerBound(events) {
|
|
145
|
+
let sawSentinel = false;
|
|
146
|
+
let lowest = null;
|
|
147
|
+
for (const event of events) {
|
|
148
|
+
if (event.introduced === undefined)
|
|
149
|
+
continue;
|
|
150
|
+
if (event.introduced === "0") {
|
|
151
|
+
sawSentinel = true;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const canonical = normalizeAdvisoryVersion(event.introduced, "PyPI");
|
|
155
|
+
if (!canonical)
|
|
156
|
+
return null;
|
|
157
|
+
const stored = canonical === "0" ? "0.0" : canonical;
|
|
158
|
+
if (lowest === null || compareVersions(stored, lowest, "PyPI") < 0)
|
|
159
|
+
lowest = stored;
|
|
160
|
+
}
|
|
161
|
+
if (sawSentinel)
|
|
162
|
+
return "0";
|
|
163
|
+
return lowest;
|
|
164
|
+
}
|
|
165
|
+
/** True when `version` is inside one window produced by `readPep440Range`. */
|
|
166
|
+
export function versionInPep440Window(version, window) {
|
|
167
|
+
if (window.introduced && window.introduced !== "0") {
|
|
168
|
+
if (compareVersions(version, window.introduced, "PyPI") < 0)
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
if (window.fixed && compareVersions(version, window.fixed, "PyPI") >= 0)
|
|
172
|
+
return false;
|
|
173
|
+
if (window.lastAffected && compareVersions(version, window.lastAffected, "PyPI") > 0)
|
|
174
|
+
return false;
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* True when an unreadable boundary might still describe a window that
|
|
179
|
+
* contains `version`. A version below the boundary's introduced value is
|
|
180
|
+
* outside that window.
|
|
181
|
+
*/
|
|
182
|
+
export function pep440UnreadableApplies(version, boundary) {
|
|
183
|
+
if (boundary.field === "introduced")
|
|
184
|
+
return true;
|
|
185
|
+
if (!boundary.introduced || boundary.introduced === "0")
|
|
186
|
+
return true;
|
|
187
|
+
const introduced = normalizeAdvisoryVersion(boundary.introduced, "PyPI");
|
|
188
|
+
if (!introduced)
|
|
189
|
+
return true;
|
|
190
|
+
return compareVersions(version, introduced, "PyPI") >= 0;
|
|
191
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { UnparseableVersionError } from "./scheme.js";
|
|
2
|
+
// PEP 440 public versions, plus the spellings packaging 26 accepts on top of
|
|
3
|
+
// the spec text: `rev` and `r` are post releases. The shape follows the
|
|
4
|
+
// packaging regex (possessive quantifiers dropped; JavaScript has none).
|
|
5
|
+
// Surrounding whitespace is accepted because packaging accepts it. The match
|
|
6
|
+
// is case-insensitive ASCII: the caller lowercases after rejecting non-ASCII.
|
|
7
|
+
const VERSION_PATTERN = /^v?(?:(?:(?<epoch>[0-9]+)!)?(?<release>[0-9]+(?:\.[0-9]+)*)(?<pre>[._-]?(?<pre_l>alpha|a|beta|b|preview|pre|c|rc)[._-]?(?<pre_n>[0-9]+)?)?(?<post>(?:-(?<post_n1>[0-9]+))|(?:[._-]?(?<post_l>post|rev|r)[._-]?(?<post_n2>[0-9]+)?))?(?<dev>[._-]?(?<dev_l>dev)[._-]?(?<dev_n>[0-9]+)?)?)(?:\+(?<local>[a-z0-9]+(?:[._-][a-z0-9]+)*))?$/;
|
|
8
|
+
const PRE_LETTER = {
|
|
9
|
+
a: 0,
|
|
10
|
+
alpha: 0,
|
|
11
|
+
b: 1,
|
|
12
|
+
beta: 1,
|
|
13
|
+
c: 2,
|
|
14
|
+
pre: 2,
|
|
15
|
+
preview: 2,
|
|
16
|
+
rc: 2,
|
|
17
|
+
};
|
|
18
|
+
const parsedCache = new Map();
|
|
19
|
+
function digits(raw) {
|
|
20
|
+
const stripped = raw.replace(/^0+/, "");
|
|
21
|
+
return BigInt(stripped.length === 0 ? "0" : stripped);
|
|
22
|
+
}
|
|
23
|
+
function cmpBig(a, b) {
|
|
24
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
25
|
+
}
|
|
26
|
+
function trimRelease(release) {
|
|
27
|
+
let end = release.length;
|
|
28
|
+
while (end > 0 && release[end - 1] === 0n)
|
|
29
|
+
end -= 1;
|
|
30
|
+
return release.slice(0, end);
|
|
31
|
+
}
|
|
32
|
+
function cmpRelease(a, b) {
|
|
33
|
+
const length = Math.max(a.length, b.length);
|
|
34
|
+
for (let i = 0; i < length; i++) {
|
|
35
|
+
if (i >= a.length)
|
|
36
|
+
return -1;
|
|
37
|
+
if (i >= b.length)
|
|
38
|
+
return 1;
|
|
39
|
+
if (a[i] !== b[i])
|
|
40
|
+
return cmpBig(a[i], b[i]);
|
|
41
|
+
}
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
function suffixOf(parsed) {
|
|
45
|
+
// A dev release with no pre and no post sorts before every alpha.
|
|
46
|
+
// Any other missing pre sorts after rc. packaging encodes that as ranks
|
|
47
|
+
// -1 and 3 around a=0, b=1, rc=2.
|
|
48
|
+
let preRank;
|
|
49
|
+
let preN;
|
|
50
|
+
if (parsed.pre === null && parsed.post === null && parsed.dev !== null) {
|
|
51
|
+
preRank = -1;
|
|
52
|
+
preN = 0n;
|
|
53
|
+
}
|
|
54
|
+
else if (parsed.pre === null) {
|
|
55
|
+
preRank = 3;
|
|
56
|
+
preN = 0n;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
preRank = parsed.pre.letter;
|
|
60
|
+
preN = parsed.pre.n;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
preRank,
|
|
64
|
+
preN,
|
|
65
|
+
postRank: parsed.post === null ? 0 : 1,
|
|
66
|
+
postN: parsed.post ?? 0n,
|
|
67
|
+
devRank: parsed.dev === null ? 1 : 0,
|
|
68
|
+
devN: parsed.dev ?? 0n,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function cmpSuffix(a, b) {
|
|
72
|
+
if (a.preRank !== b.preRank)
|
|
73
|
+
return a.preRank < b.preRank ? -1 : 1;
|
|
74
|
+
const pre = cmpBig(a.preN, b.preN);
|
|
75
|
+
if (pre !== 0)
|
|
76
|
+
return pre;
|
|
77
|
+
if (a.postRank !== b.postRank)
|
|
78
|
+
return a.postRank < b.postRank ? -1 : 1;
|
|
79
|
+
const post = cmpBig(a.postN, b.postN);
|
|
80
|
+
if (post !== 0)
|
|
81
|
+
return post;
|
|
82
|
+
if (a.devRank !== b.devRank)
|
|
83
|
+
return a.devRank < b.devRank ? -1 : 1;
|
|
84
|
+
return cmpBig(a.devN, b.devN);
|
|
85
|
+
}
|
|
86
|
+
function cmpLocalPart(a, b) {
|
|
87
|
+
// PEP 440: a lexical local segment sorts before a numeric one.
|
|
88
|
+
if (a.kind === "str" && b.kind === "str") {
|
|
89
|
+
return a.s < b.s ? -1 : a.s > b.s ? 1 : 0;
|
|
90
|
+
}
|
|
91
|
+
if (a.kind === "num" && b.kind === "num")
|
|
92
|
+
return cmpBig(a.n, b.n);
|
|
93
|
+
return a.kind === "str" ? -1 : 1;
|
|
94
|
+
}
|
|
95
|
+
function cmpLocal(a, b) {
|
|
96
|
+
if (a === null && b === null)
|
|
97
|
+
return 0;
|
|
98
|
+
if (a === null)
|
|
99
|
+
return -1;
|
|
100
|
+
if (b === null)
|
|
101
|
+
return 1;
|
|
102
|
+
const length = Math.max(a.length, b.length);
|
|
103
|
+
for (let i = 0; i < length; i++) {
|
|
104
|
+
if (i >= a.length)
|
|
105
|
+
return -1;
|
|
106
|
+
if (i >= b.length)
|
|
107
|
+
return 1;
|
|
108
|
+
const cmp = cmpLocalPart(a[i], b[i]);
|
|
109
|
+
if (cmp !== 0)
|
|
110
|
+
return cmp;
|
|
111
|
+
}
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
function cmpParsed(a, b) {
|
|
115
|
+
const epoch = cmpBig(a.epoch, b.epoch);
|
|
116
|
+
if (epoch !== 0)
|
|
117
|
+
return epoch;
|
|
118
|
+
const release = cmpRelease(trimRelease(a.release), trimRelease(b.release));
|
|
119
|
+
if (release !== 0)
|
|
120
|
+
return release;
|
|
121
|
+
const suffix = cmpSuffix(suffixOf(a), suffixOf(b));
|
|
122
|
+
if (suffix !== 0)
|
|
123
|
+
return suffix;
|
|
124
|
+
return cmpLocal(a.local, b.local);
|
|
125
|
+
}
|
|
126
|
+
function canonicalOf(parsed) {
|
|
127
|
+
let out = parsed.release.map(part => part.toString()).join(".");
|
|
128
|
+
if (parsed.epoch !== 0n)
|
|
129
|
+
out = `${parsed.epoch.toString()}!${out}`;
|
|
130
|
+
if (parsed.pre) {
|
|
131
|
+
const letter = parsed.pre.letter === 0 ? "a" : parsed.pre.letter === 1 ? "b" : "rc";
|
|
132
|
+
out += `${letter}${parsed.pre.n.toString()}`;
|
|
133
|
+
}
|
|
134
|
+
if (parsed.post !== null)
|
|
135
|
+
out += `.post${parsed.post.toString()}`;
|
|
136
|
+
if (parsed.dev !== null)
|
|
137
|
+
out += `.dev${parsed.dev.toString()}`;
|
|
138
|
+
if (parsed.local) {
|
|
139
|
+
const local = parsed.local
|
|
140
|
+
.map(part => (part.kind === "num" ? part.n.toString() : part.s))
|
|
141
|
+
.join(".");
|
|
142
|
+
out += `+${local}`;
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
function parsePep440(value) {
|
|
147
|
+
const cached = parsedCache.get(value);
|
|
148
|
+
if (cached !== undefined)
|
|
149
|
+
return cached;
|
|
150
|
+
const trimmed = value.trim();
|
|
151
|
+
if (!trimmed || /[^\x00-\x7F]/.test(trimmed)) {
|
|
152
|
+
parsedCache.set(value, null);
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
const match = VERSION_PATTERN.exec(trimmed.toLowerCase());
|
|
156
|
+
if (!match?.groups) {
|
|
157
|
+
parsedCache.set(value, null);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
const groups = match.groups;
|
|
161
|
+
const releaseRaw = groups["release"];
|
|
162
|
+
if (!releaseRaw) {
|
|
163
|
+
parsedCache.set(value, null);
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const preLabel = groups["pre_l"];
|
|
167
|
+
let pre = null;
|
|
168
|
+
if (preLabel !== undefined) {
|
|
169
|
+
const letter = PRE_LETTER[preLabel];
|
|
170
|
+
if (letter === undefined) {
|
|
171
|
+
parsedCache.set(value, null);
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
const preN = groups["pre_n"];
|
|
175
|
+
pre = { letter, n: preN !== undefined ? digits(preN) : 0n };
|
|
176
|
+
}
|
|
177
|
+
let post = null;
|
|
178
|
+
const implicitPost = groups["post_n1"];
|
|
179
|
+
const postLabel = groups["post_l"];
|
|
180
|
+
if (implicitPost !== undefined) {
|
|
181
|
+
post = digits(implicitPost);
|
|
182
|
+
}
|
|
183
|
+
else if (postLabel !== undefined) {
|
|
184
|
+
const postN = groups["post_n2"];
|
|
185
|
+
post = postN !== undefined ? digits(postN) : 0n;
|
|
186
|
+
}
|
|
187
|
+
const devLabel = groups["dev_l"];
|
|
188
|
+
let dev = null;
|
|
189
|
+
if (devLabel !== undefined) {
|
|
190
|
+
const devN = groups["dev_n"];
|
|
191
|
+
dev = devN !== undefined ? digits(devN) : 0n;
|
|
192
|
+
}
|
|
193
|
+
const localRaw = groups["local"];
|
|
194
|
+
const local = localRaw === undefined
|
|
195
|
+
? null
|
|
196
|
+
: localRaw.split(/[._-]/).map(part => /^[0-9]+$/.test(part)
|
|
197
|
+
? { kind: "num", n: digits(part) }
|
|
198
|
+
: { kind: "str", s: part });
|
|
199
|
+
const epochRaw = groups["epoch"];
|
|
200
|
+
const draft = {
|
|
201
|
+
epoch: epochRaw !== undefined ? digits(epochRaw) : 0n,
|
|
202
|
+
release: releaseRaw.split(".").map(digits),
|
|
203
|
+
pre,
|
|
204
|
+
post,
|
|
205
|
+
dev,
|
|
206
|
+
local,
|
|
207
|
+
};
|
|
208
|
+
const parsed = { ...draft, canonical: canonicalOf(draft) };
|
|
209
|
+
parsedCache.set(value, parsed);
|
|
210
|
+
return parsed;
|
|
211
|
+
}
|
|
212
|
+
function looksLikeVersion(value) {
|
|
213
|
+
return parsePep440(value) !== null;
|
|
214
|
+
}
|
|
215
|
+
function compare(a, b) {
|
|
216
|
+
const parsedA = parsePep440(a);
|
|
217
|
+
const parsedB = parsePep440(b);
|
|
218
|
+
if (!parsedA)
|
|
219
|
+
throw new UnparseableVersionError("pep440", a);
|
|
220
|
+
if (!parsedB)
|
|
221
|
+
throw new UnparseableVersionError("pep440", b);
|
|
222
|
+
return cmpParsed(parsedA, parsedB);
|
|
223
|
+
}
|
|
224
|
+
function normalizeAdvisoryVersion(value) {
|
|
225
|
+
if (!value)
|
|
226
|
+
return null;
|
|
227
|
+
return parsePep440(value)?.canonical ?? null;
|
|
228
|
+
}
|
|
229
|
+
function isPreRelease(version) {
|
|
230
|
+
const parsed = parsePep440(version);
|
|
231
|
+
if (!parsed)
|
|
232
|
+
return false;
|
|
233
|
+
// Dev releases are not final, same as packaging's is_prerelease. Post is final.
|
|
234
|
+
return parsed.pre !== null || parsed.dev !== null;
|
|
235
|
+
}
|
|
236
|
+
function atOrAboveIntroduced(version, introduced) {
|
|
237
|
+
return compare(version, introduced) >= 0;
|
|
238
|
+
}
|
|
239
|
+
export const pep440Scheme = {
|
|
240
|
+
id: "pep440",
|
|
241
|
+
looksLikeVersion,
|
|
242
|
+
compare,
|
|
243
|
+
normalizeAdvisoryVersion,
|
|
244
|
+
isPreRelease,
|
|
245
|
+
atOrAboveIntroduced,
|
|
246
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class UnparseableVersionError extends Error {
|
|
2
|
+
schemeId;
|
|
3
|
+
version;
|
|
4
|
+
constructor(schemeId, version) {
|
|
5
|
+
super(`Unparseable ${schemeId} version: ${JSON.stringify(version)}`);
|
|
6
|
+
this.name = "UnparseableVersionError";
|
|
7
|
+
this.schemeId = schemeId;
|
|
8
|
+
this.version = version;
|
|
9
|
+
}
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cve-lite-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.1",
|
|
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": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@types/jest": "^30.0.0",
|
|
31
31
|
"@types/node": "^24.0.0",
|
|
32
32
|
"@types/semver": "^7.8.0",
|
|
33
|
+
"ajv": "^8.20.0",
|
|
33
34
|
"jest": "^30.4.2",
|
|
34
35
|
"ts-jest": "^29.4.9",
|
|
35
36
|
"tsx": "^4.22.0",
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
],
|
|
50
51
|
"license": "MIT",
|
|
51
52
|
"engines": {
|
|
52
|
-
"node": ">=
|
|
53
|
+
"node": ">=22"
|
|
53
54
|
},
|
|
54
55
|
"repository": {
|
|
55
56
|
"type": "git",
|