cve-lite-cli 1.41.4 → 1.42.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 (73) hide show
  1. package/README.md +22 -19
  2. package/dist/advisory/detail-resolution.js +62 -0
  3. package/dist/advisory/local-db.js +90 -15
  4. package/dist/advisory/osv-advisory-source.js +113 -62
  5. package/dist/advisory/osv-sync.js +18 -16
  6. package/dist/advisory/sqlite.js +50 -0
  7. package/dist/audit-log/ndjson-writer.js +6 -3
  8. package/dist/audit-log/open-error.js +22 -0
  9. package/dist/cli/args.js +145 -87
  10. package/dist/cli/flags.js +2 -0
  11. package/dist/cli/help.js +6 -2
  12. package/dist/cli/overrides.js +5 -2
  13. package/dist/cli/validate.js +45 -5
  14. package/dist/constants.js +10 -0
  15. package/dist/index.js +15 -6
  16. package/dist/licenses/license-check.js +17 -4
  17. package/dist/osv/cache.js +7 -13
  18. package/dist/output/cyclonedx.js +57 -18
  19. package/dist/output/finding-display.js +8 -1
  20. package/dist/output/formatters.js +52 -11
  21. package/dist/output/html-reporter.js +40 -8
  22. package/dist/output/override-findings-terminal.js +21 -13
  23. package/dist/output/printers.js +185 -76
  24. package/dist/output/sarif.js +182 -16
  25. package/dist/output/spdx.js +15 -1
  26. package/dist/output/write-outputs.js +29 -20
  27. package/dist/overrides/context-builder.js +1 -7
  28. package/dist/overrides/detectors/oa005-nested-ineffective.js +6 -1
  29. package/dist/overrides/detectors/oa008-materialized.js +33 -10
  30. package/dist/overrides/detectors/oa009-stale-floor.js +2 -2
  31. package/dist/overrides/detectors/oa010-vulnerable-floor.js +19 -13
  32. package/dist/overrides/detectors/phantom-utils.js +2 -10
  33. package/dist/overrides/fixer.js +13 -2
  34. package/dist/overrides/index.js +1 -0
  35. package/dist/overrides/types.js +15 -1
  36. package/dist/parsers/bun-lock.js +6 -0
  37. package/dist/parsers/index.js +177 -40
  38. package/dist/parsers/multi-package.js +4 -0
  39. package/dist/parsers/package-lock.js +6 -2
  40. package/dist/parsers/pnpm-lock.js +4 -7
  41. package/dist/parsers/requirements-txt.js +185 -0
  42. package/dist/parsers/utils.js +11 -6
  43. package/dist/parsers/yarn-lock.js +1 -5
  44. package/dist/remediation/fix-commands.js +60 -36
  45. package/dist/remediation/parent-update-child-note.js +3 -2
  46. package/dist/scan/completeness.js +57 -4
  47. package/dist/scan/multi-folder-scan.js +27 -13
  48. package/dist/scan/single-scan.js +118 -37
  49. package/dist/scanner.js +59 -36
  50. package/dist/types.js +1 -1
  51. package/dist/usage/scanner.js +345 -45
  52. package/dist/utils/array.js +5 -0
  53. package/dist/utils/baseline.js +8 -2
  54. package/dist/utils/chalk.js +1 -3
  55. package/dist/utils/create-pr.js +2 -2
  56. package/dist/utils/debug-bundle.js +37 -22
  57. package/dist/utils/debug-project.js +6 -5
  58. package/dist/utils/debug-redaction.js +1 -1
  59. package/dist/utils/effective-options.js +5 -1
  60. package/dist/utils/finding.js +4 -0
  61. package/dist/utils/fix-runner.js +110 -36
  62. package/dist/utils/import-type-queries.js +5 -1
  63. package/dist/utils/install-command.js +6 -0
  64. package/dist/utils/malicious.js +11 -0
  65. package/dist/utils/package-identity.js +12 -2
  66. package/dist/utils/path-coverage.js +1 -5
  67. package/dist/utils/sanitize.js +59 -0
  68. package/dist/utils/sbom-format.js +17 -8
  69. package/dist/utils/severity.js +61 -7
  70. package/dist/utils/url.js +175 -0
  71. package/dist/utils/version.js +44 -0
  72. package/dist/utils/vuln.js +11 -14
  73. package/package.json +2 -4
@@ -0,0 +1,175 @@
1
+ import { URL } from "node:url";
2
+ export const SECRET_KEY = /^(?:password|passwd|pwd|pass|_authToken|_auth|authToken|auth|token|authorization|credentials?|apiKey|secret|accessToken|refreshToken|signature|sig|key|bearer|jwt|session)$/i;
3
+ const GIT_SSH_USER = "git";
4
+ const SSH_SCHEMES = new Set(["git+ssh:", "ssh:"]);
5
+ const SSH_PREFIXES = new Set(["git+ssh://", "ssh://"]);
6
+ /**
7
+ * Returns true if the query parameter key represents an authentication token,
8
+ * password, secret, API key, signature, or similar sensitive credential.
9
+ */
10
+ export function isSensitiveQueryParam(key) {
11
+ const normalized = key.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
12
+ const parts = normalized.split(/[_\-.[\]]+/).filter(Boolean);
13
+ return (parts.some(p => SECRET_KEY.test(p)) ||
14
+ parts.join("").includes("token") ||
15
+ parts.join("").includes("secret"));
16
+ }
17
+ function stripQueryParams(url) {
18
+ const hashIdx = url.indexOf("#");
19
+ const queryIdx = url.indexOf("?");
20
+ if (queryIdx === -1 || (hashIdx !== -1 && queryIdx > hashIdx))
21
+ return url;
22
+ const queryPart = url.slice(queryIdx + 1, hashIdx !== -1 ? hashIdx : undefined);
23
+ const filtered = queryPart.split("&").filter(param => {
24
+ if (!param)
25
+ return false;
26
+ const rawKey = param.split("=")[0];
27
+ try {
28
+ return !isSensitiveQueryParam(decodeURIComponent(rawKey));
29
+ }
30
+ catch {
31
+ // Undecodable key: drop it rather than risk leaking a secret
32
+ return false;
33
+ }
34
+ });
35
+ const newQuery = filtered.length > 0 ? `?${filtered.join("&")}` : "";
36
+ return url.slice(0, queryIdx) + newQuery + (hashIdx !== -1 ? url.slice(hashIdx) : "");
37
+ }
38
+ /**
39
+ * Strips user credentials from SCP-style Git references (e.g. secret@github.com:org/repo.git),
40
+ * while preserving the standard git@ service user and preserving relative scoped paths (packages/@scope/foo).
41
+ */
42
+ function stripScpUserinfo(url) {
43
+ const queryIdx = url.indexOf("?");
44
+ const hashIdx = url.indexOf("#");
45
+ const authorityEnd = queryIdx !== -1 && (hashIdx === -1 || queryIdx < hashIdx)
46
+ ? queryIdx
47
+ : (hashIdx !== -1 ? hashIdx : url.length);
48
+ const urlBeforeQuery = url.slice(0, authorityEnd);
49
+ // Match SCP pattern: userinfo@host:path where:
50
+ // - userinfo cannot contain slashes ("/")
51
+ // - host cannot contain slashes ("/"), colons (":"), or query/hash
52
+ // - greedy match consumes up to the last "@" before the host
53
+ const match = urlBeforeQuery.match(/^([^/]+)@([^/?#:]+):(.*)$/);
54
+ if (!match) {
55
+ return stripQueryParams(url);
56
+ }
57
+ const userinfo = match[1];
58
+ if (userinfo === GIT_SSH_USER) {
59
+ return stripQueryParams(url);
60
+ }
61
+ const hostAndPath = match[2] + ":" + match[3] + url.slice(authorityEnd);
62
+ return stripQueryParams(hostAndPath);
63
+ }
64
+ /**
65
+ * Fallback parser for non-standard, malformed, or SCP-style URLs that WHATWG URL cannot parse.
66
+ */
67
+ function stripUserinfoFallback(url) {
68
+ const schemeEnd = url.indexOf("://");
69
+ if (schemeEnd === -1) {
70
+ return stripScpUserinfo(url);
71
+ }
72
+ const prefix = url.slice(0, schemeEnd + 3);
73
+ let rest = url.slice(schemeEnd + 3);
74
+ const isSsh = SSH_PREFIXES.has(prefix);
75
+ const slashIdx = rest.indexOf("/");
76
+ const queryIdx = rest.indexOf("?");
77
+ const hashIdx = rest.indexOf("#");
78
+ if (slashIdx !== -1) {
79
+ // Userinfo can contain an unencoded "@"; the host follows the LAST "@" in
80
+ // the authority segment (strictly before the first "/" that marks the path).
81
+ const atIdx = rest.lastIndexOf("@", slashIdx);
82
+ if (atIdx !== -1) {
83
+ const hadQueryOrHash = (queryIdx !== -1 && queryIdx < atIdx) || (hashIdx !== -1 && hashIdx < atIdx);
84
+ if (!hadQueryOrHash) {
85
+ const userinfo = rest.slice(0, atIdx);
86
+ if (isSsh && userinfo === GIT_SSH_USER) {
87
+ // Keep git@ for SSH
88
+ }
89
+ else {
90
+ rest = rest.slice(atIdx + 1);
91
+ }
92
+ }
93
+ else {
94
+ // Delimiters (? or #) appeared before @, but @ is strictly before the path slash
95
+ // (e.g. user:pa?ss=foo@host:port/repo.git or user:pa#ss@host/repo.git).
96
+ // Fail closed by stripping credentials up to @ regardless of query-like "=" in the password.
97
+ rest = rest.slice(atIdx + 1);
98
+ }
99
+ }
100
+ }
101
+ else {
102
+ // No slash in URL (e.g. SCP-style git+ssh://host:repo or scheme://host?query)
103
+ const delimIdx = queryIdx !== -1 && (hashIdx === -1 || queryIdx < hashIdx) ? queryIdx : hashIdx;
104
+ const authorityEnd = delimIdx !== -1 ? delimIdx : rest.length;
105
+ const atBeforeDelim = rest.lastIndexOf("@", authorityEnd - 1);
106
+ if (atBeforeDelim !== -1) {
107
+ const userinfo = rest.slice(0, atBeforeDelim);
108
+ if (isSsh && userinfo === GIT_SSH_USER) {
109
+ // Keep git@ for SSH
110
+ }
111
+ else {
112
+ rest = rest.slice(atBeforeDelim + 1);
113
+ }
114
+ }
115
+ else {
116
+ // Check if unencoded delimiter exists before an SCP authority (e.g. user:pa?ss=foo@host:path)
117
+ const fullAt = rest.lastIndexOf("@");
118
+ if (fullAt !== -1 && delimIdx !== -1 && delimIdx < fullAt) {
119
+ const afterAt = rest.slice(fullAt + 1);
120
+ if (afterAt.includes(":")) {
121
+ // Unencoded delimiter before @ followed by host:path
122
+ rest = afterAt;
123
+ }
124
+ }
125
+ }
126
+ }
127
+ return stripQueryParams(prefix + rest);
128
+ }
129
+ export function stripUrlCredentials(url) {
130
+ if (!url || typeof url !== "string")
131
+ return url;
132
+ // Pure SCP-style Git URLs (e.g. git@host:repo) or non-standard schemes without authority
133
+ if (!url.includes("://") && !url.startsWith("file:") && !url.startsWith("npm:")) {
134
+ return stripUserinfoFallback(url);
135
+ }
136
+ try {
137
+ const parsed = new URL(url);
138
+ const isSsh = SSH_SCHEMES.has(parsed.protocol);
139
+ const hasUserinfoToStrip = isSsh
140
+ ? (parsed.username !== GIT_SSH_USER && parsed.username !== "") || Boolean(parsed.password)
141
+ : Boolean(parsed.username || parsed.password);
142
+ let hasSensitiveParam = false;
143
+ for (const [key] of parsed.searchParams) {
144
+ if (isSensitiveQueryParam(key)) {
145
+ hasSensitiveParam = true;
146
+ break;
147
+ }
148
+ }
149
+ // Return the original string unchanged when there is nothing to strip (#1591 maintainer review).
150
+ // This preserves relative paths such as file:vendor/foo.tgz, avoids lowercasing hostnames,
151
+ // and avoids re-encoding characters when no credential was present.
152
+ if (!hasUserinfoToStrip && !hasSensitiveParam) {
153
+ return url;
154
+ }
155
+ if (isSsh) {
156
+ if (parsed.username !== GIT_SSH_USER || parsed.password) {
157
+ parsed.username = "";
158
+ parsed.password = "";
159
+ }
160
+ }
161
+ else {
162
+ parsed.username = "";
163
+ parsed.password = "";
164
+ }
165
+ for (const [key] of [...parsed.searchParams]) {
166
+ if (isSensitiveQueryParam(key)) {
167
+ parsed.searchParams.delete(key);
168
+ }
169
+ }
170
+ return parsed.toString();
171
+ }
172
+ catch {
173
+ return stripUserinfoFallback(url);
174
+ }
175
+ }
@@ -6,6 +6,12 @@ import { pep440Scheme } from "./versions/pep440.js";
6
6
  export function isPep440Ecosystem(ecosystem) {
7
7
  return typeof ecosystem === "string" && ecosystem.trim().toLowerCase() === "pypi";
8
8
  }
9
+ /**
10
+ * Normalise a PEP 503 package name: lowercase, and replace runs of [-_.]+ with a single hyphen.
11
+ */
12
+ export function normalizePep503PackageName(name) {
13
+ return name.toLowerCase().replace(/[-_.]+/g, "-");
14
+ }
9
15
  export function looksLikeVersion(value, ecosystem) {
10
16
  if (isPep440Ecosystem(ecosystem))
11
17
  return pep440Scheme.looksLikeVersion(value);
@@ -257,6 +263,44 @@ export function isValidRange(input) {
257
263
  return false;
258
264
  return semver.validRange(input.trim(), { loose: true }) !== null;
259
265
  }
266
+ /** Replace a bare caret's floor while preserving its ceiling and prerelease rules. */
267
+ export function raiseCaretRangeFloor(pin, newFloor) {
268
+ let range;
269
+ try {
270
+ // Use ordinary package resolution here. Audit matching also considers
271
+ // prereleases that the original range may exclude from resolution.
272
+ range = new semver.Range(pin, { loose: true });
273
+ }
274
+ catch {
275
+ return null;
276
+ }
277
+ if (range.set.length !== 1 || !range.test(newFloor))
278
+ return null;
279
+ const ceiling = range.set[0]?.find((comparator) => comparator.operator === "<");
280
+ if (ceiling)
281
+ return `>=${newFloor} ${ceiling.value}`;
282
+ // Semver normalizes unbounded carets such as ^* and ^x to an empty range.
283
+ return range.range === "" ? `>=${newFloor}` : null;
284
+ }
285
+ /**
286
+ * Lowest version that satisfies `range`.
287
+ *
288
+ * Uses `semver.minVersion` with `{ loose: true }`. Upper-bound constraints
289
+ * (`<2.0.0`, `<=1.5.0`) return "0.0.0", ranges with a lower bound (`>=1.2.0`,
290
+ * `1.x`, `^1.2.0`, `1.2.0 - 2.0.0`) return their minimum version, preserving
291
+ * any prerelease tag. Returns null for invalid or unparseable ranges.
292
+ */
293
+ export function rangeMinVersion(range) {
294
+ if (!range || !range.trim())
295
+ return null;
296
+ try {
297
+ const mv = semver.minVersion(range.trim(), { loose: true });
298
+ return mv ? mv.version : null;
299
+ }
300
+ catch {
301
+ return null;
302
+ }
303
+ }
260
304
  /**
261
305
  * Does `version` satisfy `range`?
262
306
  *
@@ -1,15 +1,7 @@
1
1
  import { inferSeverity } from "../osv/severity.js";
2
2
  import { severityOrder } from "../constants.js";
3
3
  import { unique } from "./array.js";
4
- // MAL-* is the OSV prefix for malicious code advisories. Guarded because OSV
5
- // records are external data - the declared `string` type on OsvVuln.id does
6
- // not guarantee a malformed advisory record cannot have a missing/non-string id.
7
- export function isMaliciousVulnId(id) {
8
- return typeof id === "string" && id.startsWith("MAL-");
9
- }
10
- export function hasMaliciousAdvisory(vulns) {
11
- return vulns.some(v => isMaliciousVulnId(v.id));
12
- }
4
+ export { isMaliciousVulnId, hasMaliciousAdvisory } from "./malicious.js";
13
5
  // Guards against non-string alias elements from malformed OSV records - a
14
6
  // malformed record with a null/undefined/non-string entry in `aliases` must
15
7
  // not abort the whole scan.
@@ -31,8 +23,8 @@ export function extractCveAliases(vulns) {
31
23
  * than "the same as", and a shared CVE is weaker still, since two advisories may
32
24
  * legitimately cite one CVE.
33
25
  *
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
26
+ * The survivor keeps the highest known severity, and ties break on the
27
+ * smaller id so output is stable run to run. Its alias set
36
28
  * absorbs the dropped id, which is the part that matters: the accuracy sweep
37
29
  * compares our advisory ids against OSV's, and losing an id would read as a
38
30
  * missed advisory rather than a de-duplicated one.
@@ -81,10 +73,15 @@ export function collapseAliasedDuplicates(vulns) {
81
73
  return { ...v, aliases: [...ids].sort() };
82
74
  });
83
75
  }
84
- /** Higher severity wins; the smaller id breaks a tie so the result is stable. */
85
76
  function preferred(a, b) {
86
- const ra = severityOrder[inferSeverity(a)];
87
- const rb = severityOrder[inferSeverity(b)];
77
+ const aSeverity = inferSeverity(a);
78
+ const bSeverity = inferSeverity(b);
79
+ // The gate ranks unknown like low, but a measured rating takes precedence here.
80
+ if ((aSeverity === "unknown") !== (bSeverity === "unknown")) {
81
+ return aSeverity === "unknown" ? b : a;
82
+ }
83
+ const ra = severityOrder[aSeverity];
84
+ const rb = severityOrder[bSeverity];
88
85
  if (ra !== rb)
89
86
  return ra > rb ? a : b;
90
87
  return a.id <= b.id ? a : b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cve-lite-cli",
3
- "version": "1.41.4",
3
+ "version": "1.42.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": {
@@ -19,14 +19,12 @@
19
19
  "test:watch": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch --passWithNoTests"
20
20
  },
21
21
  "dependencies": {
22
- "better-sqlite3": "^12.8.0",
23
22
  "fflate": "^0.8.3",
24
23
  "semver": "^7.8.5",
25
24
  "yaml": "^2.7.1",
26
25
  "yarn-lockfile": "^1.1.0"
27
26
  },
28
27
  "devDependencies": {
29
- "@types/better-sqlite3": "^7.6.13",
30
28
  "@types/jest": "^30.0.0",
31
29
  "@types/node": "^24.0.0",
32
30
  "@types/semver": "^7.8.0",
@@ -50,7 +48,7 @@
50
48
  ],
51
49
  "license": "MIT",
52
50
  "engines": {
53
- "node": ">=22"
51
+ "node": "^22.13.0 || >=23.4.0"
54
52
  },
55
53
  "repository": {
56
54
  "type": "git",