cve-lite-cli 1.39.0 → 1.41.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 (82) hide show
  1. package/README.md +28 -22
  2. package/dist/advisory/local-advisory-source.js +9 -5
  3. package/dist/advisory/local-db.js +91 -13
  4. package/dist/advisory/osv-sync.js +187 -56
  5. package/dist/advisory/staging-directory.js +112 -0
  6. package/dist/cli/advisories-sync.js +16 -2
  7. package/dist/cli/args.js +46 -35
  8. package/dist/cli/config.js +4 -1
  9. package/dist/cli/help.js +5 -3
  10. package/dist/cli/validate.js +23 -1
  11. package/dist/constants.js +15 -28
  12. package/dist/index.js +8 -3
  13. package/dist/osv/severity.js +1 -1
  14. package/dist/output/cyclonedx.js +24 -15
  15. package/dist/output/debug.js +68 -18
  16. package/dist/output/formatters.js +35 -7
  17. package/dist/output/html-reporter.js +68 -12
  18. package/dist/output/multi-folder-html-reporter.js +71 -11
  19. package/dist/output/output-dir.js +193 -7
  20. package/dist/output/override-findings-html.js +3 -6
  21. package/dist/output/override-findings-terminal.js +7 -12
  22. package/dist/output/override-fix-command.js +13 -0
  23. package/dist/output/printers.js +27 -12
  24. package/dist/output/sarif.js +168 -57
  25. package/dist/output/sbom-dependency-edges.js +16 -10
  26. package/dist/output/sbom-file.js +14 -6
  27. package/dist/output/scan-json.js +46 -3
  28. package/dist/output/spdx.js +61 -23
  29. package/dist/output/spinner.js +2 -1
  30. package/dist/output/write-outputs.js +143 -41
  31. package/dist/overrides/context-builder.js +23 -70
  32. package/dist/overrides/parsing/registry.js +1 -1
  33. package/dist/parsers/bun-lock.js +1 -2
  34. package/dist/parsers/index.js +22 -1
  35. package/dist/parsers/npm-lock-graph.js +39 -1
  36. package/dist/parsers/package-lock.js +25 -5
  37. package/dist/parsers/pnpm-lock.js +26 -12
  38. package/dist/parsers/utils.js +5 -3
  39. package/dist/parsers/yarn-lock-graph.js +5 -2
  40. package/dist/parsers/yarn-lock.js +1 -2
  41. package/dist/remediation/fix-commands.js +140 -50
  42. package/dist/remediation/npm-registry.js +56 -7
  43. package/dist/remediation/npm-transitive-graph.js +30 -72
  44. package/dist/remediation/npm-transitive-resolution.js +35 -107
  45. package/dist/remediation/parent-candidate-resolver.js +65 -0
  46. package/dist/remediation/parent-upgrade-blockers.js +51 -0
  47. package/dist/remediation/parent-upgrade.js +11 -116
  48. package/dist/remediation/registry-parent-ranges.js +21 -0
  49. package/dist/remediation/transitive-chain-resolver.js +3 -3
  50. package/dist/scan/completeness.js +17 -11
  51. package/dist/scan/multi-folder-scan.js +154 -59
  52. package/dist/scan/override-audit.js +11 -1
  53. package/dist/scan/single-scan.js +123 -67
  54. package/dist/scanner.js +288 -66
  55. package/dist/skills/content.js +12 -12
  56. package/dist/usage/scanner.js +19 -8
  57. package/dist/utils/array.js +11 -3
  58. package/dist/utils/contextual-signals.js +1 -1
  59. package/dist/utils/debug-bundle.js +118 -0
  60. package/dist/utils/debug-project.js +102 -0
  61. package/dist/utils/debug-redaction.js +117 -0
  62. package/dist/utils/effective-options.js +55 -0
  63. package/dist/utils/file.js +2 -1
  64. package/dist/utils/finding.js +1 -1
  65. package/dist/utils/fix-runner.js +98 -15
  66. package/dist/utils/import-type-queries.js +322 -0
  67. package/dist/utils/network.js +14 -10
  68. package/dist/utils/npm-lockfile.js +12 -0
  69. package/dist/utils/osv-fetch.js +70 -0
  70. package/dist/utils/package-identity.js +43 -0
  71. package/dist/utils/package-manager-source.js +24 -0
  72. package/dist/utils/purl.js +37 -0
  73. package/dist/utils/registry-config.js +129 -0
  74. package/dist/utils/severity.js +8 -0
  75. package/dist/utils/string.js +8 -0
  76. package/dist/utils/validate-url.js +4 -4
  77. package/dist/utils/version.js +47 -8
  78. package/dist/utils/versions/osv-range.js +191 -0
  79. package/dist/utils/versions/pep440.js +246 -0
  80. package/dist/utils/versions/scheme.js +10 -0
  81. package/dist/utils/vuln.js +75 -0
  82. package/package.json +3 -2
@@ -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
+ }
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cve-lite-cli",
3
- "version": "1.39.0",
3
+ "version": "1.41.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": {
@@ -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": ">=20"
53
+ "node": ">=22"
53
54
  },
54
55
  "repository": {
55
56
  "type": "git",