cve-lite-cli 1.30.0 → 1.31.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/dist/cli/validate.js +12 -12
- package/dist/output/html-reporter.js +4 -4
- package/dist/parsers/pnpm-lock.js +4 -3
- package/dist/scanner.js +26 -2
- package/dist/utils/severity.js +2 -0
- package/package.json +1 -1
package/dist/cli/validate.js
CHANGED
|
@@ -2,13 +2,13 @@ import { validateCaCertFile } from "./config.js";
|
|
|
2
2
|
import { validateOsvUrl } from "../utils/validate-url.js";
|
|
3
3
|
export async function validateOptions(options) {
|
|
4
4
|
if (options.allowPrivateOsvUrl && !options.osvUrl) {
|
|
5
|
-
throw new Error("--allow-private-osv-url requires --osv-url");
|
|
5
|
+
throw new Error("--allow-private-osv-url requires --osv-url. Provide a custom OSV endpoint with --osv-url, or remove --allow-private-osv-url.");
|
|
6
6
|
}
|
|
7
7
|
if ((options.offline || options.offlineDb) && options.osvUrl) {
|
|
8
|
-
throw new Error("--offline/--offline-db cannot be used with --osv-url");
|
|
8
|
+
throw new Error("--offline/--offline-db cannot be used with --osv-url. Choose offline mode (local DB) or online mode (custom OSV endpoint), not both.");
|
|
9
9
|
}
|
|
10
10
|
if (options.noCache && (options.offline || options.offlineDb)) {
|
|
11
|
-
throw new Error("--no-cache cannot be used with --offline or --offline-db");
|
|
11
|
+
throw new Error("--no-cache cannot be used with --offline or --offline-db. Offline mode uses the local advisory DB directly; --no-cache only applies to online scans.");
|
|
12
12
|
}
|
|
13
13
|
let ssrfWarning;
|
|
14
14
|
if (options.osvUrl) {
|
|
@@ -21,26 +21,26 @@ export async function validateOptions(options) {
|
|
|
21
21
|
// SSRF defense: validate scheme, IP, and allow-private flag
|
|
22
22
|
ssrfWarning = await validateOsvUrl(options.osvUrl, !!options.allowPrivateOsvUrl);
|
|
23
23
|
}
|
|
24
|
+
if (options.createPr && options.json) {
|
|
25
|
+
throw new Error("--create-pr cannot be used with --json. Use --create-pr to open a pull request for applied fixes, or --json to save scan results as JSON, not both.");
|
|
26
|
+
}
|
|
24
27
|
if (options.fix && options.json) {
|
|
25
|
-
throw new Error("--fix cannot be used with --json");
|
|
28
|
+
throw new Error("--fix cannot be used with --json. Use --fix to apply validated fixes and rescan, or --json to save scan results as JSON, not both.");
|
|
26
29
|
}
|
|
27
30
|
if (options.fix && options.sarif) {
|
|
28
|
-
throw new Error("--fix cannot be used with --sarif");
|
|
31
|
+
throw new Error("--fix cannot be used with --sarif. Use --fix to apply validated fixes and rescan, or --sarif to save scan results as SARIF, not both.");
|
|
29
32
|
}
|
|
30
33
|
if (options.fix && options.cdx) {
|
|
31
|
-
throw new Error("--fix cannot be used with --cdx");
|
|
34
|
+
throw new Error("--fix cannot be used with --cdx. Use --fix to apply validated fixes and rescan, or --cdx to save a CycloneDX SBOM, not both.");
|
|
32
35
|
}
|
|
33
36
|
if (options.createPr && !options.fix) {
|
|
34
|
-
throw new Error("--create-pr requires --fix");
|
|
35
|
-
}
|
|
36
|
-
if (options.createPr && options.json) {
|
|
37
|
-
throw new Error("--create-pr cannot be used with --json");
|
|
37
|
+
throw new Error("--create-pr requires --fix. Add --fix to apply validated fixes before opening a pull request, or remove --create-pr.");
|
|
38
38
|
}
|
|
39
39
|
if (options.prBase && !options.createPr) {
|
|
40
|
-
throw new Error("--base can only be used with --create-pr");
|
|
40
|
+
throw new Error("--base can only be used with --create-pr. Add --create-pr to select its target branch, or remove --base.");
|
|
41
41
|
}
|
|
42
42
|
if (options.report && options.json) {
|
|
43
|
-
throw new Error("--report cannot be used with --json");
|
|
43
|
+
throw new Error("--report cannot be used with --json. Use --report to generate an HTML report, or --json to save scan results as JSON, not both.");
|
|
44
44
|
}
|
|
45
45
|
if (options.caCert) {
|
|
46
46
|
try {
|
|
@@ -509,7 +509,7 @@ export function renderFindingRow(finding, idx, skippedKeys) {
|
|
|
509
509
|
const depPathHtml = finding.dependencyPaths.length > 0
|
|
510
510
|
? finding.dependencyPaths[0].map((node, i, arr) => {
|
|
511
511
|
const isLast = i === arr.length - 1;
|
|
512
|
-
return `<
|
|
512
|
+
return `<a href="https://www.npmjs.com/package/${encodeURIComponent(node)}" target="_blank" rel="noopener noreferrer" class="dep-node${isLast ? " vulnerable" : ""}">${escapeHtml(node)}</a>${isLast ? "" : '<span class="dep-arrow">→</span>'}`;
|
|
513
513
|
}).join("")
|
|
514
514
|
: `<span class="dep-node">${escapeHtml(finding.package)}</span>`;
|
|
515
515
|
const description = finding.vulnerabilities[0]?.summary ?? "";
|
|
@@ -526,9 +526,9 @@ export function renderFindingRow(finding, idx, skippedKeys) {
|
|
|
526
526
|
const rootDepsHtml = finding.rootDependencies.length > 0
|
|
527
527
|
? finding.rootDependencies.map(name => `<span class="root-dep">${escapeHtml(name)}</span>`).join(", ")
|
|
528
528
|
: `<span class="root-dep-none">-</span>`;
|
|
529
|
-
return
|
|
529
|
+
return `<tr id="row-${idx}" data-skipped="${isSkipped ? '1' : '0'}" onclick="toggleRow(${idx})">
|
|
530
530
|
<td><span class="expand-icon" id="icon-${idx}">▶</span></td>
|
|
531
|
-
<td><div class="pkg-name">${escapeHtml(finding.package)}</div><div class="pkg-version">${escapeHtml(finding.version)}</div></td>
|
|
531
|
+
<td><div class="pkg-name"><a href="https://www.npmjs.com/package/${encodeURIComponent(finding.package)}" target="_blank" rel="noopener noreferrer">${escapeHtml(finding.package)}</a></div><div class="pkg-version">${escapeHtml(finding.version)}</div></td>
|
|
532
532
|
<td>${fixHtml}</td>
|
|
533
533
|
<td><span class="sev-badge ${escapeHtml(finding.severity)}">${escapeHtml(finding.severity)}</span></td>
|
|
534
534
|
<td>${renderRelBadge(finding)}</td>
|
|
@@ -758,7 +758,7 @@ export function renderFixPlan(plan) {
|
|
|
758
758
|
: "";
|
|
759
759
|
const chainProofHtml = t.chainProof && t.chainSafeVersion
|
|
760
760
|
? (() => {
|
|
761
|
-
const hops = t.chainProof.map(h =>
|
|
761
|
+
const hops = t.chainProof.map(h => `<a href="https://www.npmjs.com/package/${encodeURIComponent(h.name)}" target="_blank" rel="noopener noreferrer">${escapeHtml(h.name)}</a>@${escapeHtml(h.version)}`);
|
|
762
762
|
const safe = escapeHtml(t.chainSafeVersion);
|
|
763
763
|
const proofText = hops.length > 0
|
|
764
764
|
? `resolves via ${hops.join(" -> ")} -> ${safe} (safe)`
|
|
@@ -294,10 +294,11 @@ function parsePnpmPackageKey(key) {
|
|
|
294
294
|
return { key, name, version };
|
|
295
295
|
}
|
|
296
296
|
function parsePnpmPackageKeyV9(key) {
|
|
297
|
-
|
|
297
|
+
// strip leading slash (pnpm v9 can emit /@babel/core@7.20.0) then peer-dep suffix (pkg@1.0.0(peer@2.0.0))
|
|
298
|
+
const cleaned = key.replace(/^\//, "").split("(")[0];
|
|
298
299
|
const idx = cleaned.lastIndexOf("@");
|
|
299
300
|
if (idx <= 0)
|
|
300
|
-
return null; // no @ or @ is the first char
|
|
301
|
+
return null; // no @ or @ is the first char (scoped package name only)
|
|
301
302
|
const name = cleaned.slice(0, idx);
|
|
302
303
|
const version = cleaned.slice(idx + 1);
|
|
303
304
|
if (!name || !version)
|
|
@@ -324,7 +325,7 @@ function normalizePnpmDepRef(depName, depRef) {
|
|
|
324
325
|
}
|
|
325
326
|
function normalizePnpmDepRefV9(depName, depRef) {
|
|
326
327
|
if (typeof depRef === "string") {
|
|
327
|
-
const cleaned = depRef.replace(/^link:/, "").replace(/^workspace:/, "").split("(")[0];
|
|
328
|
+
const cleaned = depRef.replace(/^link:/, "").replace(/^workspace:/, "").replace(/^\//, "").split("(")[0];
|
|
328
329
|
if (!cleaned || cleaned.startsWith(".") || cleaned.startsWith(".."))
|
|
329
330
|
return null;
|
|
330
331
|
if (looksLikeVersion(cleaned))
|
package/dist/scanner.js
CHANGED
|
@@ -267,7 +267,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
267
267
|
const cveAliases = extractCveAliases(vulnerabilities);
|
|
268
268
|
const dependencyPaths = result.pkg.paths ?? [];
|
|
269
269
|
const relationship = classifyRelationship(dependencyPaths, result.pkg.name, context?.directDependencyNames);
|
|
270
|
-
const firstFixedVersion = findFirstFixedVersion(vulnerabilities);
|
|
270
|
+
const firstFixedVersion = findFirstFixedVersion(vulnerabilities, result.pkg.name, result.pkg.ecosystem);
|
|
271
271
|
return {
|
|
272
272
|
pkg: result.pkg,
|
|
273
273
|
vulnerabilities,
|
|
@@ -727,10 +727,34 @@ function classifyRelationship(paths, packageName, directDependencyNames) {
|
|
|
727
727
|
return "direct";
|
|
728
728
|
return "transitive";
|
|
729
729
|
}
|
|
730
|
-
|
|
730
|
+
/**
|
|
731
|
+
* Does this `affected[]` entry describe the package being scanned?
|
|
732
|
+
*
|
|
733
|
+
* Permissive by design, matching `resolveLowestKnownNonVulnerableVersion` in
|
|
734
|
+
* remediation/npm-registry.ts: an entry is excluded only when it positively
|
|
735
|
+
* identifies a *different* package. An entry that omits the name (or the
|
|
736
|
+
* ecosystem) is kept, so an advisory with sparse metadata still contributes
|
|
737
|
+
* its fix rather than silently dropping to "no fix known".
|
|
738
|
+
*/
|
|
739
|
+
function affectedEntryMatchesPackage(affected, packageName, ecosystem) {
|
|
740
|
+
const affectedName = affected.package?.name;
|
|
741
|
+
if (affectedName && affectedName !== packageName)
|
|
742
|
+
return false;
|
|
743
|
+
const affectedEcosystem = affected.package?.ecosystem?.toLowerCase();
|
|
744
|
+
if (affectedEcosystem && affectedEcosystem !== ecosystem.toLowerCase())
|
|
745
|
+
return false;
|
|
746
|
+
return true;
|
|
747
|
+
}
|
|
748
|
+
export function findFirstFixedVersion(vulns, packageName, ecosystem) {
|
|
731
749
|
const fixedVersions = [];
|
|
732
750
|
for (const vuln of vulns) {
|
|
733
751
|
for (const affected of vuln.affected ?? []) {
|
|
752
|
+
// An advisory may list several packages with different fix versions.
|
|
753
|
+
// Without this filter the global minimum across all of them was
|
|
754
|
+
// returned, so a package inherited another package's (lower) fix and
|
|
755
|
+
// the scan reported a version that does not fix it.
|
|
756
|
+
if (!affectedEntryMatchesPackage(affected, packageName, ecosystem))
|
|
757
|
+
continue;
|
|
734
758
|
for (const range of affected.ranges ?? []) {
|
|
735
759
|
for (const event of range.events ?? []) {
|
|
736
760
|
const fixed = event.fixed;
|
package/dist/utils/severity.js
CHANGED
|
@@ -3,6 +3,8 @@ import { severityOrder } from "../constants.js";
|
|
|
3
3
|
import { normalizeSeverity } from "../osv/severity.js";
|
|
4
4
|
export const SEVERITY_ORDER = ["critical", "high", "medium", "low", "unknown", "none"];
|
|
5
5
|
export function reachesFailOn(findings, failOn) {
|
|
6
|
+
if (!failOn)
|
|
7
|
+
return false;
|
|
6
8
|
const failLevel = normalizeSeverity(failOn);
|
|
7
9
|
return findings.some((f) => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
8
10
|
}
|