cve-lite-cli 1.22.0 → 1.23.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 +10 -6
- package/dist/advisory/osv-sync.js +2 -7
- package/dist/constants.js +6 -0
- package/dist/output/cyclonedx.js +10 -1
- package/dist/output/formatters.js +11 -1
- package/dist/output/html-reporter.js +43 -8
- package/dist/output/multi-folder-html-reporter.js +2 -3
- package/dist/output/printers.js +16 -1
- package/dist/output/sarif.js +10 -1
- package/dist/parsers/bun-lock.js +3 -2
- package/dist/parsers/npm-lock-graph.js +49 -17
- package/dist/parsers/pnpm-lock.js +3 -2
- package/dist/parsers/yarn-lock.js +3 -2
- package/dist/remediation/npm-transitive-resolution.js +6 -2
- package/dist/remediation/parent-upgrade.js +12 -7
- package/dist/scanner.js +60 -22
- package/dist/utils/advisory.js +17 -0
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
[](https://owasp.org/cve-lite-cli)
|
|
3
3
|
[](https://www.npmjs.com/package/cve-lite-cli)
|
|
4
4
|
[](https://www.npmjs.com/package/cve-lite-cli)
|
|
5
5
|
[](https://github.com/OWASP/cve-lite-cli/actions)
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
<h1>CVE Lite CLI</h1>
|
|
17
17
|
|
|
18
|
-
**🏆 Officially recognized as an [OWASP
|
|
18
|
+
**🏆 Officially recognized as an [OWASP Lab Project](https://owasp.org/cve-lite-cli)**
|
|
19
19
|
|
|
20
20
|
<p>Vulnerability scanning that belongs in your terminal — not your CI pipeline.<br/>Scan your lockfile, get copy-and-run fix commands, and ship clean code.</p>
|
|
21
21
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
<table>
|
|
27
27
|
<tr>
|
|
28
|
-
<td align="center" width="33%"><p>🏆</p><strong>OWASP
|
|
28
|
+
<td align="center" width="33%"><p>🏆</p><strong>OWASP Lab Project</strong><br/><sub>Peer-reviewed by the org behind the OWASP Top 10 —<br/>the security standard followed by millions of developers</sub></td>
|
|
29
29
|
<td align="center" width="33%"><p>🎯</p><strong>Remediation-first</strong><br/><sub>Validated fix commands + parent-aware<br/>transitive guidance — not just CVE IDs</sub></td>
|
|
30
30
|
<td align="center" width="33%"><p>🔒</p><strong>Runs locally</strong><br/><sub>Nothing leaves your machine — not your<br/>code, not your dependency tree</sub></td>
|
|
31
31
|
</tr>
|
|
@@ -226,8 +226,12 @@ CVE Lite CLI has been evaluated against real open-source projects to verify that
|
|
|
226
226
|
- [n8n](https://owasp.org/cve-lite-cli/docs/case-studies/n8n) — verified baseline scan of a workflow automation pnpm monorepo (3,746 packages, 32 findings at revision `e2e0394`) with one direct `turbo` fix, four command groups, and email/editor transitive clusters
|
|
227
227
|
- [CamoFox Browser](https://owasp.org/cve-lite-cli/docs/case-studies/camofox-browser) — verified baseline scan of an AI agent browser automation npm graph (435 packages, 2 findings at revision `ce3a3b0`) with dual `qs` fix strategies — within-range `npm update qs` and parent `npm install express@4.22.2`
|
|
228
228
|
- [Storybook](https://owasp.org/cve-lite-cli/docs/case-studies/storybook) — verified baseline scan of a Yarn Berry monorepo (3,008 packages, 92 findings at revision `cc19ae1`) spanning cross-framework sandbox templates, five critical transitive chains, and one direct vite fix command
|
|
229
|
+
- [Twenty](https://owasp.org/cve-lite-cli/docs/case-studies/twenty) — verified baseline scan of an open-source CRM Yarn Berry monorepo (5,451 packages, 105 findings at revision `fc90b4b`) with 0 direct findings, six critical test-stack chains, and four Nx parent-upgrade command groups
|
|
230
|
+
- [Strapi](https://owasp.org/cve-lite-cli/docs/case-studies/strapi) — verified baseline scan of a headless CMS Yarn Berry monorepo (2,887 packages, 18 findings) with two direct findings (`lodash`, `qs`) and mixed transitive remediation paths
|
|
231
|
+
- [Payload CMS](https://owasp.org/cve-lite-cli/docs/case-studies/payload) — verified baseline scan of a TypeScript-first headless CMS pnpm monorepo (2,602 packages, 18 findings) with one direct finding and workspace-scoped fix commands
|
|
232
|
+
- [Presenton](https://owasp.org/cve-lite-cli/docs/case-studies/presenton) — verified baseline scan of an AI presentation generator with dual npm lockfiles (root + Electron shell), demonstrating multi-lockfile coverage across 9 findings
|
|
229
233
|
|
|
230
|
-
In-repo lockfile fixtures for Astro, Turborepo, Visual Studio Code, Gatsby, Vercel AI SDK, Mastra, Lit, LangChain.js, OpenAI Agents JS, n8n, CamoFox Browser, and
|
|
234
|
+
In-repo lockfile fixtures for Astro, Turborepo, Visual Studio Code, Gatsby, Vercel AI SDK, Mastra, Lit, LangChain.js, OpenAI Agents JS, n8n, CamoFox Browser, Storybook, Twenty, Strapi, Payload CMS, and Presenton live under [`examples/`](examples/readme.md) — clone the repo and scan immediately without downloading full upstream checkouts.
|
|
231
235
|
|
|
232
236
|
These are not demos. They are documented scans against real codebases with real findings, recorded before and after applying fix commands.
|
|
233
237
|
|
|
@@ -251,7 +255,7 @@ If you maintain an open-source JavaScript or TypeScript project and want CVE Lit
|
|
|
251
255
|
|
|
252
256
|
OWASP (Open Web Application Security Project) is the globally recognized nonprofit behind the security standards followed by millions of developers worldwide — most notably the [OWASP Top 10](https://owasp.org/www-project-top-ten/), the most widely cited web application security reference in the industry. Organizations from startups to Fortune 500 companies use OWASP guidelines as the foundation of their security programs.
|
|
253
257
|
|
|
254
|
-
CVE Lite CLI is an [OWASP
|
|
258
|
+
CVE Lite CLI is an [OWASP Lab Project](https://owasp.org/cve-lite-cli) — reviewed and accepted by the OWASP community as a vendor-neutral, open source security tool. Being part of OWASP means:
|
|
255
259
|
|
|
256
260
|
- **Peer-reviewed** by security professionals
|
|
257
261
|
- **Community-driven** development and governance
|
|
@@ -480,7 +484,7 @@ npm run build
|
|
|
480
484
|
|
|
481
485
|
## Governance
|
|
482
486
|
|
|
483
|
-
CVE Lite CLI is an OWASP
|
|
487
|
+
CVE Lite CLI is an OWASP Lab Project maintained by Sonu Kapoor as project lead. The project follows a single-maintainer (benevolent dictator) governance model. The project lead makes final decisions on scope, design direction, and releases after considering input from contributors and the wider community.
|
|
484
488
|
|
|
485
489
|
### Roles
|
|
486
490
|
|
|
@@ -110,13 +110,8 @@ export async function syncOsvAdvisories(options = {}) {
|
|
|
110
110
|
return { advisoryCount, dbPath, sourceUrl };
|
|
111
111
|
}
|
|
112
112
|
catch (error) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
finally {
|
|
117
|
-
if (fs.existsSync(dbPath)) {
|
|
118
|
-
fs.rmSync(dbPath, { force: true });
|
|
119
|
-
}
|
|
113
|
+
if (fs.existsSync(dbPath)) {
|
|
114
|
+
fs.rmSync(dbPath, { force: true });
|
|
120
115
|
}
|
|
121
116
|
throw error;
|
|
122
117
|
}
|
package/dist/constants.js
CHANGED
|
@@ -12,6 +12,12 @@ export const NPM_PUBLIC_REGISTRY = "https://registry.npmjs.org/";
|
|
|
12
12
|
export const MAL_PRIVATE_REGISTRY_MESSAGE = "This package has a MAL- advisory but resolved from a private registry - unverifiable whether this advisory applies to your artifact. Inspect the source manually.";
|
|
13
13
|
export const MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE = "MAL- advisory could not be confirmed for this artifact.";
|
|
14
14
|
export const MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE = "verify artifact source manually";
|
|
15
|
+
export const MAL_GIT_SOURCE_PINNED_MESSAGE = "Advisory targets registry packages. This package resolves from a git source pinned to a commit SHA — verify the repository and org are trusted.";
|
|
16
|
+
export const MAL_GIT_SOURCE_FLOATING_MESSAGE = "Advisory targets registry packages. This package resolves from a git source with a floating reference — verify the repository, org, and ref are safe.";
|
|
17
|
+
export const MAL_GIT_SOURCE_COMPACT_MESSAGE = "Git source — verify repository and org are trusted.";
|
|
18
|
+
export const MAL_GIT_SOURCE_LEGEND_MESSAGE = "verify repository and org are trusted";
|
|
19
|
+
export const MAL_GIT_SOURCE_PINNED_DISPLAY = "⚠ Git source (SHA-pinned)";
|
|
20
|
+
export const MAL_GIT_SOURCE_FLOATING_DISPLAY = "⚠ Git source (floating ref)";
|
|
15
21
|
export const EXCLUDED_DIRS = new Set([
|
|
16
22
|
".git",
|
|
17
23
|
"node_modules",
|
package/dist/output/cyclonedx.js
CHANGED
|
@@ -83,6 +83,15 @@ export function writeCycloneDxReport(allPackages, findings, plan, projectMeta) {
|
|
|
83
83
|
const filename = `cve-lite-scan-${ts}.cdx.json`;
|
|
84
84
|
const outputPath = path.join(process.cwd(), filename);
|
|
85
85
|
const bom = buildCycloneDxBom(allPackages, findings, projectMeta, getCliVersion(), plan);
|
|
86
|
-
|
|
86
|
+
try {
|
|
87
|
+
fs.writeFileSync(outputPath, JSON.stringify(bom, null, 2));
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
try {
|
|
91
|
+
fs.rmSync(outputPath, { force: true });
|
|
92
|
+
}
|
|
93
|
+
catch { /* best-effort cleanup */ }
|
|
94
|
+
throw new Error(`Failed to write CycloneDX report to ${outputPath}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
95
|
+
}
|
|
87
96
|
return filename;
|
|
88
97
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
|
|
2
2
|
import { chalk } from "../utils/chalk.js";
|
|
3
|
-
import { severityOrder, MAL_PRIVATE_REGISTRY_MESSAGE } from "../constants.js";
|
|
3
|
+
import { severityOrder, MAL_PRIVATE_REGISTRY_MESSAGE, MAL_GIT_SOURCE_PINNED_MESSAGE, MAL_GIT_SOURCE_FLOATING_MESSAGE, } from "../constants.js";
|
|
4
4
|
import { loadCache } from "../osv/cache.js";
|
|
5
5
|
import { inferSeverity } from "../osv/severity.js";
|
|
6
6
|
import { getPrimaryParent } from "../utils/finding.js";
|
|
@@ -91,6 +91,14 @@ export function getRecommendedAction(finding) {
|
|
|
91
91
|
return `No parent dependency was identified for ${finding.pkg.name} in the lockfile. Run \`npm ls ${finding.pkg.name}\` (or your package manager equivalent) to find which package pulls it in.`;
|
|
92
92
|
}
|
|
93
93
|
export function summarizeRisk(finding) {
|
|
94
|
+
if (finding.maliciousUnverifiable) {
|
|
95
|
+
return MAL_PRIVATE_REGISTRY_MESSAGE;
|
|
96
|
+
}
|
|
97
|
+
if (finding.maliciousGitSource) {
|
|
98
|
+
return finding.maliciousGitSourcePinned
|
|
99
|
+
? MAL_GIT_SOURCE_PINNED_MESSAGE
|
|
100
|
+
: MAL_GIT_SOURCE_FLOATING_MESSAGE;
|
|
101
|
+
}
|
|
94
102
|
let risk = "";
|
|
95
103
|
if (finding.severity === "critical" && finding.relationship === "direct") {
|
|
96
104
|
risk = "Critical direct dependency. Prioritize this first because the project controls it directly.";
|
|
@@ -206,6 +214,8 @@ export function serializeFinding(finding, plan) {
|
|
|
206
214
|
dependencyPaths: finding.dependencyPaths,
|
|
207
215
|
usage: finding.usage ?? null,
|
|
208
216
|
maliciousUnverifiable: finding.maliciousUnverifiable ?? false,
|
|
217
|
+
maliciousGitSource: finding.maliciousGitSource ?? false,
|
|
218
|
+
maliciousGitSourcePinned: finding.maliciousGitSourcePinned ?? false,
|
|
209
219
|
vulnerabilities: finding.vulnerabilities.map(v => ({
|
|
210
220
|
id: v.id,
|
|
211
221
|
aliases: v.aliases ?? [],
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
|
-
import { serializeFinding } from "./formatters.js";
|
|
4
|
+
import { serializeFinding, summarizeNextAction, summarizeRisk } from "./formatters.js";
|
|
5
5
|
import { LOGO_BASE64 } from "./logo-base64.js";
|
|
6
6
|
import { OWASP_LOGO_BASE64 } from "./owasp-logo-base64.js";
|
|
7
7
|
import { isMajorVersionBump } from "../utils/version.js";
|
|
8
8
|
import { pluralize } from "../utils/string.js";
|
|
9
|
+
import { MAL_GIT_SOURCE_PINNED_DISPLAY, MAL_GIT_SOURCE_FLOATING_DISPLAY } from "../constants.js";
|
|
10
|
+
export function serializeHtmlFinding(finding, plan) {
|
|
11
|
+
return {
|
|
12
|
+
...serializeFinding(finding, plan),
|
|
13
|
+
riskSummary: summarizeRisk(finding),
|
|
14
|
+
nextAction: summarizeNextAction(finding),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
9
17
|
export function buildReportData(params) {
|
|
10
18
|
return {
|
|
11
19
|
projectPath: params.projectPath,
|
|
@@ -14,7 +22,7 @@ export function buildReportData(params) {
|
|
|
14
22
|
packageManager: params.packageManager,
|
|
15
23
|
lockfileSource: params.lockfileSource,
|
|
16
24
|
packageCount: params.packageCount,
|
|
17
|
-
findings: params.findings.map(finding =>
|
|
25
|
+
findings: params.findings.map(finding => serializeHtmlFinding(finding, params.suggestedFixCommands)),
|
|
18
26
|
suggestedFixCommands: params.suggestedFixCommands,
|
|
19
27
|
notes: params.notes,
|
|
20
28
|
warnings: params.warnings,
|
|
@@ -98,6 +106,7 @@ button.header-link:hover{color:#58a6ff;border-color:#58a6ff}
|
|
|
98
106
|
.sev-badge.low{background:#388bfd22;color:#388bfd;border:1px solid #388bfd66}
|
|
99
107
|
.sev-badge.unknown{background:#8b949e22;color:#8b949e;border:1px solid #8b949e66}
|
|
100
108
|
.badge-warning{display:inline-block;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.4px;padding:2px 8px;border-radius:4px;background:#e3b34122;color:#e3b341;border:1px solid #e3b34166}
|
|
109
|
+
.badge-git-source{background:#fb8c0022;color:#fb8c00;border:1px solid #fb8c0055;border-radius:4px;font-size:11px;padding:2px 6px}
|
|
101
110
|
.rel-badge{font-size:11px;padding:2px 7px;border-radius:4px}
|
|
102
111
|
.rel-badge.direct{color:#3fb950;background:#3fb95022}
|
|
103
112
|
.rel-badge.transitive{color:#e3b341;background:#e3b34122}
|
|
@@ -115,6 +124,7 @@ button.header-link:hover{color:#58a6ff;border-color:#58a6ff}
|
|
|
115
124
|
.expanded-inner{padding:16px 20px 20px 48px;display:flex;gap:32px}
|
|
116
125
|
.detail-col{flex:1}
|
|
117
126
|
.detail-col h4{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.4px;color:#8b949e;margin-bottom:8px}
|
|
127
|
+
.detail-col h4.detail-subheading{margin-top:14px}
|
|
118
128
|
.detail-col p{font-size:12px;color:#8b949e;line-height:1.6}
|
|
119
129
|
.dep-path{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
|
|
120
130
|
.dep-node{font-size:11px;font-family:monospace;background:#161b22;border:1px solid #30363d;border-radius:4px;padding:2px 8px;color:#e6edf3}
|
|
@@ -414,9 +424,13 @@ export function renderFindingRow(finding, idx, skippedKeys) {
|
|
|
414
424
|
? `<span class="fix-hint">${escapeHtml(fixVersion)}</span>`
|
|
415
425
|
: isMalicious && finding.maliciousUnverifiable
|
|
416
426
|
? `<span class="badge badge-warning" title="MAL- advisory found but package resolved from a private registry - may not apply to your artifact">Unverifiable (private source)</span>`
|
|
417
|
-
: isMalicious
|
|
418
|
-
? `<span class="
|
|
419
|
-
:
|
|
427
|
+
: isMalicious && finding.maliciousGitSource && finding.maliciousGitSourcePinned
|
|
428
|
+
? `<span class="badge badge-git-source" title="MAL- advisory found but package resolves from a git source pinned to a commit SHA — verify the repository and org are trusted">${escapeHtml(MAL_GIT_SOURCE_PINNED_DISPLAY)}</span>`
|
|
429
|
+
: isMalicious && finding.maliciousGitSource
|
|
430
|
+
? `<span class="badge badge-git-source" title="MAL- advisory found but package resolves from a git source with a floating reference — verify the repository, org, and ref are safe">${escapeHtml(MAL_GIT_SOURCE_FLOATING_DISPLAY)}</span>`
|
|
431
|
+
: isMalicious
|
|
432
|
+
? `<span class="fix-hint none" title="Malicious code advisory — remove this package">⚠ Malicious</span>`
|
|
433
|
+
: `<span class="fix-hint none" title="No known fix — consider replacing this package">⚠ No fix</span>`;
|
|
420
434
|
const depPathHtml = finding.dependencyPaths.length > 0
|
|
421
435
|
? finding.dependencyPaths[0].map((node, i, arr) => {
|
|
422
436
|
const isLast = i === arr.length - 1;
|
|
@@ -457,6 +471,10 @@ export function renderFindingRow(finding, idx, skippedKeys) {
|
|
|
457
471
|
<div class="detail-col">
|
|
458
472
|
<h4>Recommended action</h4>
|
|
459
473
|
${recommendedActionHtml}
|
|
474
|
+
<h4 class="detail-subheading">Risk summary</h4>
|
|
475
|
+
<p>${escapeHtml(finding.riskSummary)}</p>
|
|
476
|
+
<h4 class="detail-subheading">Next action</h4>
|
|
477
|
+
<p>${escapeHtml(finding.nextAction)}</p>
|
|
460
478
|
</div>
|
|
461
479
|
</div>
|
|
462
480
|
</td>
|
|
@@ -573,11 +591,28 @@ export function renderFixPlan(plan) {
|
|
|
573
591
|
</div>`;
|
|
574
592
|
}
|
|
575
593
|
export async function writeHtmlReport(params) {
|
|
576
|
-
fs.
|
|
594
|
+
const dirExisted = fs.existsSync(params.outputDir);
|
|
595
|
+
try {
|
|
596
|
+
fs.mkdirSync(params.outputDir, { recursive: true });
|
|
597
|
+
}
|
|
598
|
+
catch (err) {
|
|
599
|
+
throw new Error(`Failed to create report directory ${params.outputDir}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
600
|
+
}
|
|
577
601
|
const indexPath = path.join(params.outputDir, "index.html");
|
|
578
602
|
const jsonPath = path.join(params.outputDir, "report.json");
|
|
579
|
-
|
|
580
|
-
|
|
603
|
+
try {
|
|
604
|
+
fs.writeFileSync(jsonPath, JSON.stringify(params.data, null, 2), "utf8");
|
|
605
|
+
fs.writeFileSync(indexPath, renderHtmlReport(params.data), "utf8");
|
|
606
|
+
}
|
|
607
|
+
catch (err) {
|
|
608
|
+
if (!dirExisted) {
|
|
609
|
+
try {
|
|
610
|
+
fs.rmSync(params.outputDir, { recursive: true, force: true });
|
|
611
|
+
}
|
|
612
|
+
catch { /* best-effort cleanup */ }
|
|
613
|
+
}
|
|
614
|
+
throw new Error(`Failed to write HTML report to ${params.outputDir}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
615
|
+
}
|
|
581
616
|
if (params.autoOpen) {
|
|
582
617
|
openInBrowser(indexPath);
|
|
583
618
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { REPORT_STYLES, escapeHtml, renderFindingRow, renderFixPlan,
|
|
3
|
+
import { REPORT_STYLES, escapeHtml, openInBrowser, renderFindingRow, renderFixPlan, serializeHtmlFinding, } from "./html-reporter.js";
|
|
4
4
|
import { LOGO_BASE64 } from "./logo-base64.js";
|
|
5
5
|
import { OWASP_LOGO_BASE64 } from "./owasp-logo-base64.js";
|
|
6
|
-
import { serializeFinding } from "./formatters.js";
|
|
7
6
|
import { pluralize } from "../utils/string.js";
|
|
8
7
|
function summaryCounts(results) {
|
|
9
8
|
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0, none: 0 };
|
|
@@ -97,7 +96,7 @@ export async function writeMultiFolderHtmlReport(params) {
|
|
|
97
96
|
const totalCVEs = params.results.reduce((sum, r) => sum + r.sorted.reduce((s, f) => s + f.cveAliases.length, 0), 0);
|
|
98
97
|
const folderCount = params.results.length;
|
|
99
98
|
// Pre-serialize findings once per folder for both HTML rendering and JS filter/sort
|
|
100
|
-
const allSerialized = params.results.map(r => r.sorted.map(f =>
|
|
99
|
+
const allSerialized = params.results.map(r => r.sorted.map(f => serializeHtmlFinding(f, r.suggestedFixCommands)));
|
|
101
100
|
// Compact per-folder findings for JavaScript (only fields needed for filter/sort/search)
|
|
102
101
|
const folderFindingsJson = JSON.stringify(allSerialized.map(findings => findings.map(f => ({
|
|
103
102
|
package: f.package,
|
package/dist/output/printers.js
CHANGED
|
@@ -5,7 +5,7 @@ import { getPrimaryParent } from "../utils/finding.js";
|
|
|
5
5
|
import { countUniqueAdvisories, formatSeverityLabel, formatRelationshipLabel, formatRelLabel } from "./formatters.js";
|
|
6
6
|
import { pluralize } from "../utils/string.js";
|
|
7
7
|
import { selectFindingsForCompact } from "./finding-display.js";
|
|
8
|
-
import { MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE, MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE } from "../constants.js";
|
|
8
|
+
import { MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE, MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE, MAL_GIT_SOURCE_PINNED_MESSAGE, MAL_GIT_SOURCE_FLOATING_MESSAGE, MAL_GIT_SOURCE_COMPACT_MESSAGE, MAL_GIT_SOURCE_LEGEND_MESSAGE, MAL_GIT_SOURCE_PINNED_DISPLAY, MAL_GIT_SOURCE_FLOATING_DISPLAY, } from "../constants.js";
|
|
9
9
|
export function printSummary(findings, packageCount, scanInput) {
|
|
10
10
|
if (findings.length === 0) {
|
|
11
11
|
if (scanInput.mode === "manifest-fallback") {
|
|
@@ -168,6 +168,9 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
168
168
|
else if (f.maliciousUnverifiable) {
|
|
169
169
|
fixedDisplay = chalk.yellow("⚠ Unverifiable (private source)");
|
|
170
170
|
}
|
|
171
|
+
else if (f.maliciousGitSource) {
|
|
172
|
+
fixedDisplay = chalk.yellow(f.maliciousGitSourcePinned ? MAL_GIT_SOURCE_PINNED_DISPLAY : MAL_GIT_SOURCE_FLOATING_DISPLAY);
|
|
173
|
+
}
|
|
171
174
|
else if (f.vulnerabilities.some(v => v.id.startsWith("MAL-"))) {
|
|
172
175
|
fixedDisplay = chalk.yellow("⚠ Malicious");
|
|
173
176
|
}
|
|
@@ -224,6 +227,11 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
224
227
|
if (f.maliciousUnverifiable) {
|
|
225
228
|
console.log(chalk.yellow(` · ${f.pkg.name}@${f.pkg.version} - Unverifiable (private source) - ${action}`));
|
|
226
229
|
}
|
|
230
|
+
else if (f.maliciousGitSource) {
|
|
231
|
+
const msg = f.maliciousGitSourcePinned ? MAL_GIT_SOURCE_PINNED_MESSAGE : MAL_GIT_SOURCE_FLOATING_MESSAGE;
|
|
232
|
+
const url = f.pkg.resolvedUrl ? ` (${f.pkg.resolvedUrl})` : "";
|
|
233
|
+
console.log(chalk.yellow(` · ${f.pkg.name}@${f.pkg.version}${url} - ${msg}`));
|
|
234
|
+
}
|
|
227
235
|
else {
|
|
228
236
|
console.log(chalk.red(` · ${f.pkg.name}@${f.pkg.version} - ${action}`));
|
|
229
237
|
}
|
|
@@ -336,6 +344,10 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
336
344
|
if (finding.maliciousUnverifiable) {
|
|
337
345
|
console.log(` ${chalk.yellow(`⚠ Unverifiable (private source) - ${MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE}`)}`);
|
|
338
346
|
}
|
|
347
|
+
else if (finding.maliciousGitSource) {
|
|
348
|
+
const url = finding.pkg.resolvedUrl ? ` Source: ${finding.pkg.resolvedUrl}` : "";
|
|
349
|
+
console.log(` ${chalk.yellow(`⚠ ${MAL_GIT_SOURCE_COMPACT_MESSAGE}${url}`)}`);
|
|
350
|
+
}
|
|
339
351
|
else {
|
|
340
352
|
const action = finding.relationship === "direct"
|
|
341
353
|
? "Remove this package from your dependencies immediately."
|
|
@@ -447,6 +459,9 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
447
459
|
if (f.maliciousUnverifiable) {
|
|
448
460
|
console.log(chalk.yellow(` · ${f.pkg.name}@${f.pkg.version} - Unverifiable (private source) - ${MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE}`));
|
|
449
461
|
}
|
|
462
|
+
else if (f.maliciousGitSource) {
|
|
463
|
+
console.log(chalk.yellow(` · ${f.pkg.name}@${f.pkg.version} - Git source - ${MAL_GIT_SOURCE_LEGEND_MESSAGE}`));
|
|
464
|
+
}
|
|
450
465
|
else {
|
|
451
466
|
const action = f.relationship === "direct"
|
|
452
467
|
? "Remove it from your dependencies immediately."
|
package/dist/output/sarif.js
CHANGED
|
@@ -81,6 +81,15 @@ export function writeSarifReport(findings, lockfileUri, plan) {
|
|
|
81
81
|
const filename = `cve-lite-scan-${ts}.sarif`;
|
|
82
82
|
const outputPath = path.join(process.cwd(), filename);
|
|
83
83
|
const sarif = buildSarifOutput(findings, lockfileUri, getCliVersion(), plan);
|
|
84
|
-
|
|
84
|
+
try {
|
|
85
|
+
fs.writeFileSync(outputPath, JSON.stringify(sarif, null, 2));
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
try {
|
|
89
|
+
fs.rmSync(outputPath, { force: true });
|
|
90
|
+
}
|
|
91
|
+
catch { /* best-effort cleanup */ }
|
|
92
|
+
throw new Error(`Failed to write SARIF report to ${outputPath}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
93
|
+
}
|
|
85
94
|
return filename;
|
|
86
95
|
}
|
package/dist/parsers/bun-lock.js
CHANGED
|
@@ -32,8 +32,9 @@ function extractChildDependencyNames(depMeta) {
|
|
|
32
32
|
function collectBunPaths(rootDepNames, childDepsByPackageName, map, packageNameToVersion) {
|
|
33
33
|
const queue = rootDepNames.map(name => ({ name, path: ["project"] }));
|
|
34
34
|
const visitedStates = new Set();
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
let head = 0;
|
|
36
|
+
while (head < queue.length) {
|
|
37
|
+
const current = queue[head++];
|
|
37
38
|
const nextPath = [...current.path, current.name];
|
|
38
39
|
const version = packageNameToVersion.get(current.name);
|
|
39
40
|
const stateKey = `${current.name}@${version ?? ""}>${nextPath.join(">")}`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import { unique
|
|
2
|
+
import { unique } from "../utils/array.js";
|
|
3
3
|
export function loadNpmLockGraph(filePath, options) {
|
|
4
4
|
const raw = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
5
5
|
const packages = raw?.packages;
|
|
@@ -17,9 +17,9 @@ export function loadNpmLockGraph(filePath, options) {
|
|
|
17
17
|
return createGraph({
|
|
18
18
|
entryPackages: [],
|
|
19
19
|
nodesById,
|
|
20
|
-
nodeIdsByPackageKey,
|
|
21
|
-
parentNodeIdsByChildNodeId,
|
|
22
|
-
childNodeIdsByParentNodeId,
|
|
20
|
+
nodeIdsByPackageKey: setsToArrays(nodeIdsByPackageKey),
|
|
21
|
+
parentNodeIdsByChildNodeId: setsToArrays(parentNodeIdsByChildNodeId),
|
|
22
|
+
childNodeIdsByParentNodeId: setsToArrays(childNodeIdsByParentNodeId),
|
|
23
23
|
rangeByParentNodeId,
|
|
24
24
|
pathSetByNodeId,
|
|
25
25
|
});
|
|
@@ -46,7 +46,9 @@ export function loadNpmLockGraph(filePath, options) {
|
|
|
46
46
|
dev: !!meta?.dev,
|
|
47
47
|
});
|
|
48
48
|
nodeIdByPackagePath.set(packagePath, id);
|
|
49
|
-
|
|
49
|
+
const keySet = nodeIdsByPackageKey.get(packageKey) ?? new Set();
|
|
50
|
+
keySet.add(id);
|
|
51
|
+
nodeIdsByPackageKey.set(packageKey, keySet);
|
|
50
52
|
dependencyRangesByNodeId.set(id, collectDependencyRanges(resolveDependencySource(meta, rawPackages)));
|
|
51
53
|
resolutionBasePathsByNodeId.set(id, resolveBasePaths(packagePath, meta));
|
|
52
54
|
}
|
|
@@ -87,37 +89,56 @@ export function loadNpmLockGraph(filePath, options) {
|
|
|
87
89
|
return createGraph({
|
|
88
90
|
entryPackages,
|
|
89
91
|
nodesById,
|
|
90
|
-
nodeIdsByPackageKey,
|
|
91
|
-
parentNodeIdsByChildNodeId,
|
|
92
|
-
childNodeIdsByParentNodeId,
|
|
92
|
+
nodeIdsByPackageKey: setsToArrays(nodeIdsByPackageKey),
|
|
93
|
+
parentNodeIdsByChildNodeId: setsToArrays(parentNodeIdsByChildNodeId),
|
|
94
|
+
childNodeIdsByParentNodeId: setsToArrays(childNodeIdsByParentNodeId),
|
|
93
95
|
rangeByParentNodeId,
|
|
94
96
|
pathSetByNodeId,
|
|
95
97
|
});
|
|
96
98
|
}
|
|
97
99
|
function createGraph(args) {
|
|
98
100
|
const entryPackages = Object.freeze([...unique(args.entryPackages)]);
|
|
101
|
+
const EMPTY_ARRAY = Object.freeze([]);
|
|
102
|
+
// Pre-freeze all node objects so getNode() returns a pre-computed frozen copy
|
|
103
|
+
const frozenNodesById = new Map();
|
|
104
|
+
for (const [id, node] of args.nodesById) {
|
|
105
|
+
frozenNodesById.set(id, Object.freeze({ ...node }));
|
|
106
|
+
}
|
|
107
|
+
// Pre-freeze all package-key -> nodeId arrays
|
|
108
|
+
const frozenNodeIdsByPackageKey = new Map();
|
|
109
|
+
for (const [key, ids] of args.nodeIdsByPackageKey) {
|
|
110
|
+
frozenNodeIdsByPackageKey.set(key, Object.freeze([...ids]));
|
|
111
|
+
}
|
|
112
|
+
// Pre-freeze all parent arrays
|
|
113
|
+
const frozenParentsByChild = new Map();
|
|
114
|
+
for (const [id, parents] of args.parentNodeIdsByChildNodeId) {
|
|
115
|
+
frozenParentsByChild.set(id, Object.freeze([...parents]));
|
|
116
|
+
}
|
|
117
|
+
// Pre-freeze all children arrays
|
|
118
|
+
const frozenChildrenByParent = new Map();
|
|
119
|
+
for (const [id, children] of args.childNodeIdsByParentNodeId) {
|
|
120
|
+
frozenChildrenByParent.set(id, Object.freeze([...children]));
|
|
121
|
+
}
|
|
99
122
|
return {
|
|
100
123
|
entryPackages,
|
|
101
124
|
nodeIdsFor(name, version) {
|
|
102
|
-
return
|
|
125
|
+
return frozenNodeIdsByPackageKey.get(buildPackageKey(name, version)) ?? EMPTY_ARRAY;
|
|
103
126
|
},
|
|
104
127
|
getNode(nodeId) {
|
|
105
|
-
|
|
106
|
-
return node ? Object.freeze({ ...node }) : null;
|
|
128
|
+
return frozenNodesById.get(nodeId) ?? null;
|
|
107
129
|
},
|
|
108
130
|
parentsFor(nodeId) {
|
|
109
|
-
return
|
|
131
|
+
return frozenParentsByChild.get(nodeId) ?? EMPTY_ARRAY;
|
|
110
132
|
},
|
|
111
133
|
childrenFor(nodeId) {
|
|
112
|
-
return
|
|
134
|
+
return frozenChildrenByParent.get(nodeId) ?? EMPTY_ARRAY;
|
|
113
135
|
},
|
|
114
136
|
rangeFor(parentNodeId, childName) {
|
|
115
137
|
return args.rangeByParentNodeId.get(parentNodeId)?.get(childName) ?? null;
|
|
116
138
|
},
|
|
117
139
|
pathsFor(nodeId) {
|
|
118
|
-
|
|
140
|
+
return [...(args.pathSetByNodeId.get(nodeId) ?? new Set())]
|
|
119
141
|
.map((item) => item.split(">"));
|
|
120
|
-
return uniquePathArrays(serializedPaths);
|
|
121
142
|
},
|
|
122
143
|
};
|
|
123
144
|
}
|
|
@@ -134,8 +155,12 @@ function resolveEdgesForParent(parentPackagePath, dependencyRanges, resolutionBa
|
|
|
134
155
|
const parentNodeId = parentPackagePath ? nodeIdByPackagePath.get(parentPackagePath) : null;
|
|
135
156
|
if (!parentNodeId)
|
|
136
157
|
continue;
|
|
137
|
-
|
|
138
|
-
|
|
158
|
+
const childSet = childNodeIdsByParentNodeId.get(parentNodeId) ?? new Set();
|
|
159
|
+
childSet.add(childNodeId);
|
|
160
|
+
childNodeIdsByParentNodeId.set(parentNodeId, childSet);
|
|
161
|
+
const parentSet = parentNodeIdsByChildNodeId.get(childNodeId) ?? new Set();
|
|
162
|
+
parentSet.add(parentNodeId);
|
|
163
|
+
parentNodeIdsByChildNodeId.set(childNodeId, parentSet);
|
|
139
164
|
const rangesForParent = rangeByParentNodeId.get(parentNodeId) ?? new Map();
|
|
140
165
|
rangesForParent.set(dependencyName, range);
|
|
141
166
|
rangeByParentNodeId.set(parentNodeId, rangesForParent);
|
|
@@ -214,6 +239,13 @@ function rememberPath(pathSetByNodeId, nodeId, pathParts) {
|
|
|
214
239
|
existing.add(serialized);
|
|
215
240
|
pathSetByNodeId.set(nodeId, existing);
|
|
216
241
|
}
|
|
242
|
+
function setsToArrays(map) {
|
|
243
|
+
const result = new Map();
|
|
244
|
+
for (const [key, set] of map) {
|
|
245
|
+
result.set(key, [...set]);
|
|
246
|
+
}
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
217
249
|
function isRecord(value) {
|
|
218
250
|
return !!value && typeof value === "object";
|
|
219
251
|
}
|
|
@@ -160,8 +160,9 @@ function loadV9(parsed, prodOnly) {
|
|
|
160
160
|
function collectPnpmPaths(rootDeps, graph, map, parsePackageKey) {
|
|
161
161
|
const queue = rootDeps.map(dep => ({ key: dep, path: ["project"] }));
|
|
162
162
|
const visitedStates = new Set();
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
let head = 0;
|
|
164
|
+
while (head < queue.length) {
|
|
165
|
+
const current = queue[head++];
|
|
165
166
|
const ref = parsePackageKey(current.key);
|
|
166
167
|
if (!ref)
|
|
167
168
|
continue;
|
|
@@ -86,8 +86,9 @@ function parseYarnPackageKey(key) {
|
|
|
86
86
|
function collectYarnPaths(rootDepKeys, graph, map) {
|
|
87
87
|
const queue = rootDepKeys.map(key => ({ key, path: ["project"] }));
|
|
88
88
|
const visitedStates = new Set();
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
let head = 0;
|
|
90
|
+
while (head < queue.length) {
|
|
91
|
+
const current = queue[head++];
|
|
91
92
|
const ref = parseYarnPackageKey(current.key);
|
|
92
93
|
if (!ref)
|
|
93
94
|
continue;
|
|
@@ -14,6 +14,7 @@ export async function resolveTransitiveRemediationViaRegistry(args) {
|
|
|
14
14
|
const vulnerableName = args.finding.pkg.name;
|
|
15
15
|
const fixHint = args.finding.validatedFirstFixedVersion ?? args.finding.firstFixedVersion;
|
|
16
16
|
if (directParentName !== immediateParentName) {
|
|
17
|
+
const packagesByName = new Map(args.packages.map(p => [p.name, p]));
|
|
17
18
|
return resolveWithinRangeForDeepChainViaRegistry({
|
|
18
19
|
immediateParentName,
|
|
19
20
|
vulnerableName,
|
|
@@ -21,6 +22,7 @@ export async function resolveTransitiveRemediationViaRegistry(args) {
|
|
|
21
22
|
fixHint,
|
|
22
23
|
viaPath,
|
|
23
24
|
packages: args.packages,
|
|
25
|
+
packagesByName,
|
|
24
26
|
workspaceMap: args.workspaceMap,
|
|
25
27
|
});
|
|
26
28
|
}
|
|
@@ -68,6 +70,7 @@ export async function resolveNpmTransitiveRemediation(args) {
|
|
|
68
70
|
// immediate parent's declared range for the vulnerable package already covers a safe version.
|
|
69
71
|
// If so, a lockfile refresh of the vulnerable package itself is sufficient.
|
|
70
72
|
if (directParentName !== immediateParentName) {
|
|
73
|
+
const packagesByName = new Map(args.packages.map(p => [p.name, p]));
|
|
71
74
|
return resolveWithinRangeForDeepChain({
|
|
72
75
|
graph: args.graph,
|
|
73
76
|
immediateParentName,
|
|
@@ -76,6 +79,7 @@ export async function resolveNpmTransitiveRemediation(args) {
|
|
|
76
79
|
fixHint,
|
|
77
80
|
viaPath,
|
|
78
81
|
packages: args.packages,
|
|
82
|
+
packagesByName,
|
|
79
83
|
offline: args.offline,
|
|
80
84
|
});
|
|
81
85
|
}
|
|
@@ -301,7 +305,7 @@ function parseCoreVersion(version) {
|
|
|
301
305
|
return [Number(major), Number(minor), Number(patch)];
|
|
302
306
|
}
|
|
303
307
|
async function resolveWithinRangeForDeepChainViaRegistry(args) {
|
|
304
|
-
const immediateParent = args.
|
|
308
|
+
const immediateParent = args.packagesByName.get(args.immediateParentName);
|
|
305
309
|
if (!immediateParent || !looksLikeVersion(immediateParent.version))
|
|
306
310
|
return null;
|
|
307
311
|
const safeCandidates = await findSafeChildCandidates(args.vulnerableName, args.installedVersion, args.fixHint);
|
|
@@ -331,7 +335,7 @@ async function resolveWithinRangeForDeepChainViaRegistry(args) {
|
|
|
331
335
|
};
|
|
332
336
|
}
|
|
333
337
|
async function resolveWithinRangeForDeepChain(args) {
|
|
334
|
-
const immediateParent = args.
|
|
338
|
+
const immediateParent = args.packagesByName.get(args.immediateParentName);
|
|
335
339
|
if (!immediateParent || !looksLikeVersion(immediateParent.version))
|
|
336
340
|
return null;
|
|
337
341
|
const nodeIds = args.graph.nodeIdsFor(args.immediateParentName, immediateParent.version);
|
|
@@ -10,7 +10,8 @@ export async function resolveRecommendedParentUpgrade(finding, packages, directD
|
|
|
10
10
|
const viaPath = getBestPath(finding);
|
|
11
11
|
if (!viaPath || viaPath.length < 3)
|
|
12
12
|
return null;
|
|
13
|
-
const
|
|
13
|
+
const packagesByName = new Map(packages.map(p => [p.name, p]));
|
|
14
|
+
const directParentContext = resolveDirectParentContext(viaPath, packages, directDependencyNames, packagesByName);
|
|
14
15
|
if (!directParentContext)
|
|
15
16
|
return null;
|
|
16
17
|
const { directParentName, immediateParentName, directParent } = directParentContext;
|
|
@@ -49,13 +50,13 @@ function getBestPath(finding) {
|
|
|
49
50
|
return null;
|
|
50
51
|
return [...paths].sort((a, b) => a.length - b.length)[0] ?? null;
|
|
51
52
|
}
|
|
52
|
-
function findDirectDependency(packages, name, directDependencyNames) {
|
|
53
|
+
function findDirectDependency(packages, name, directDependencyNames, packagesByName) {
|
|
54
|
+
if (directDependencyNames?.has(name)) {
|
|
55
|
+
return packagesByName.get(name) ?? null;
|
|
56
|
+
}
|
|
53
57
|
for (const pkg of packages) {
|
|
54
58
|
if (pkg.name !== name)
|
|
55
59
|
continue;
|
|
56
|
-
if (directDependencyNames?.has(name)) {
|
|
57
|
-
return pkg;
|
|
58
|
-
}
|
|
59
60
|
const paths = pkg.paths ?? [];
|
|
60
61
|
if (paths.some(path => path.at(-1) === name && path.length >= 2)) {
|
|
61
62
|
return pkg;
|
|
@@ -63,7 +64,7 @@ function findDirectDependency(packages, name, directDependencyNames) {
|
|
|
63
64
|
}
|
|
64
65
|
return null;
|
|
65
66
|
}
|
|
66
|
-
function resolveDirectParentContext(viaPath, packages, directDependencyNames) {
|
|
67
|
+
function resolveDirectParentContext(viaPath, packages, directDependencyNames, packagesByName) {
|
|
67
68
|
const immediateParentName = viaPath[viaPath.length - 2];
|
|
68
69
|
const candidateSegments = viaPath.slice(1, -1);
|
|
69
70
|
const directParentCandidates = directDependencyNames
|
|
@@ -72,12 +73,16 @@ function resolveDirectParentContext(viaPath, packages, directDependencyNames) {
|
|
|
72
73
|
const directParentName = directParentCandidates[0];
|
|
73
74
|
if (!directParentName)
|
|
74
75
|
return null;
|
|
75
|
-
const directParent = findDirectDependency(packages, directParentName, directDependencyNames);
|
|
76
|
+
const directParent = findDirectDependency(packages, directParentName, directDependencyNames, packagesByName);
|
|
76
77
|
if (!directParent)
|
|
77
78
|
return null;
|
|
78
79
|
return { directParentName, immediateParentName, directParent };
|
|
79
80
|
}
|
|
80
81
|
function findPackageVersion(packages, name, pathPrefix) {
|
|
82
|
+
// Cannot use a name-keyed Map here: when the same package is installed at
|
|
83
|
+
// multiple versions (e.g. lodash@3 and lodash@4 on different paths), a Map
|
|
84
|
+
// would only hold one entry. We need path-aware iteration across all installed
|
|
85
|
+
// versions to find the right one for this specific dependency chain.
|
|
81
86
|
for (const pkg of packages) {
|
|
82
87
|
if (pkg.name !== name)
|
|
83
88
|
continue;
|
package/dist/scanner.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { chunk, unique, runWithConcurrency } from "./utils/array.js";
|
|
2
|
-
import { isPrivateRegistrySource } from "./utils/advisory.js";
|
|
2
|
+
import { isPrivateRegistrySource, isGitSource, hasCommitShaPinning } from "./utils/advisory.js";
|
|
3
3
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "./utils/version.js";
|
|
4
4
|
import { loadCache, saveCache, isEntryStale } from "./osv/cache.js";
|
|
5
5
|
import { maxSeverity } from "./osv/severity.js";
|
|
@@ -9,7 +9,7 @@ import { LocalAdvisorySource } from "./advisory/local-advisory-source.js";
|
|
|
9
9
|
import { LocalAdvisoryDatabase } from "./advisory/local-db.js";
|
|
10
10
|
import { ADVISORY_DB_STALE_AFTER_MS, getDefaultAdvisoryDbPath } from "./advisory/osv-sync.js";
|
|
11
11
|
import { resolveRecommendedParentUpgrade } from "./remediation/parent-upgrade.js";
|
|
12
|
-
import { configureNpmRegistryDebug, resolveLowestKnownNonVulnerableVersion, resolvePublishedFixVersion, } from "./remediation/npm-registry.js";
|
|
12
|
+
import { configureNpmRegistryDebug, fetchPackument, resolveLowestKnownNonVulnerableVersion, resolvePublishedFixVersion, } from "./remediation/npm-registry.js";
|
|
13
13
|
import { countBySeverity } from "./utils/severity.js";
|
|
14
14
|
import { resolveNpmTransitiveRemediation, resolveTransitiveRemediationViaRegistry } from "./remediation/npm-transitive-resolution.js";
|
|
15
15
|
import { loadNpmLockGraph } from "./parsers/npm-lock-graph.js";
|
|
@@ -142,25 +142,37 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
142
142
|
const ids = [...idSet];
|
|
143
143
|
const detailSpinner = createSpinner("Fetching vulnerability details...", options);
|
|
144
144
|
try {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
// cache.entries holds OsvVuln detail records. Unlike cache.queryEntries (which has a
|
|
146
|
+
// 30-minute staleness check applied earlier in this function), detail records have no
|
|
147
|
+
// expiry — they are considered valid for the lifetime of the cache file. The check below
|
|
148
|
+
// is therefore a simple presence check, not a staleness check. This is intentional and
|
|
149
|
+
// matches the original behaviour. Fetches run concurrently because there is no ordering
|
|
150
|
+
// dependency between CVE ID detail requests.
|
|
151
|
+
const uncachedIds = [];
|
|
152
|
+
for (const id of ids) {
|
|
148
153
|
if (id in cache.entries) {
|
|
149
154
|
const cached = cache.entries[id];
|
|
150
|
-
if (cached)
|
|
155
|
+
if (cached)
|
|
151
156
|
vulnMap.set(id, cached);
|
|
152
|
-
}
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
try {
|
|
156
|
-
const detail = await advisorySource.getVuln(id);
|
|
157
|
-
vulnMap.set(id, detail);
|
|
158
|
-
cache.entries[id] = detail;
|
|
159
157
|
}
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
else {
|
|
159
|
+
uncachedIds.push(id);
|
|
162
160
|
}
|
|
163
161
|
}
|
|
162
|
+
// Fetch all uncached IDs concurrently
|
|
163
|
+
if (uncachedIds.length > 0) {
|
|
164
|
+
detailSpinner.update(`Fetching ${uncachedIds.length} vulnerability details...`);
|
|
165
|
+
await runWithConcurrency(uncachedIds, 10, async (id) => {
|
|
166
|
+
try {
|
|
167
|
+
const detail = await advisorySource.getVuln(id);
|
|
168
|
+
vulnMap.set(id, detail);
|
|
169
|
+
cache.entries[id] = detail;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
cache.entries[id] = null;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
164
176
|
detailSpinner.succeed(`Loaded ${ids.length} vulnerability detail ${pluralize(ids.length, "record")}`);
|
|
165
177
|
}
|
|
166
178
|
catch (error) {
|
|
@@ -172,9 +184,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
172
184
|
const ids = [...idSet];
|
|
173
185
|
const detailSpinner = createSpinner("Loading local advisory details...", options);
|
|
174
186
|
try {
|
|
175
|
-
|
|
176
|
-
const id = ids[i];
|
|
177
|
-
detailSpinner.update(`Loading local advisory details ${i + 1}/${ids.length}...`);
|
|
187
|
+
await runWithConcurrency(ids, 10, async (id) => {
|
|
178
188
|
try {
|
|
179
189
|
const detail = await advisorySource.getVuln(id);
|
|
180
190
|
vulnMap.set(id, detail);
|
|
@@ -182,7 +192,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
182
192
|
catch {
|
|
183
193
|
// ignore missing local records so scans remain resilient to partial DB state
|
|
184
194
|
}
|
|
185
|
-
}
|
|
195
|
+
});
|
|
186
196
|
detailSpinner.succeed(`Loaded ${ids.length} local advisory detail ${pluralize(ids.length, "record")}`);
|
|
187
197
|
}
|
|
188
198
|
catch (error) {
|
|
@@ -219,9 +229,14 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
219
229
|
};
|
|
220
230
|
});
|
|
221
231
|
for (const finding of findings) {
|
|
222
|
-
if (finding.vulnerabilities.some(v => v.id.startsWith("MAL-"))
|
|
223
|
-
|
|
224
|
-
|
|
232
|
+
if (finding.vulnerabilities.some(v => v.id.startsWith("MAL-"))) {
|
|
233
|
+
if (isGitSource(finding.pkg)) {
|
|
234
|
+
finding.maliciousGitSource = true;
|
|
235
|
+
finding.maliciousGitSourcePinned = hasCommitShaPinning(finding.pkg);
|
|
236
|
+
}
|
|
237
|
+
else if (isPrivateRegistrySource(finding.pkg)) {
|
|
238
|
+
finding.maliciousUnverifiable = true;
|
|
239
|
+
}
|
|
225
240
|
}
|
|
226
241
|
}
|
|
227
242
|
const npmTransitiveGraph = context?.scanSource === "package-lock" && context.scanFilePath
|
|
@@ -297,6 +312,29 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
297
312
|
updateAnalysisProgress("validating fix target for", `${finding.pkg.name}@${finding.pkg.version}`);
|
|
298
313
|
}, log);
|
|
299
314
|
}
|
|
315
|
+
// Pre-warm packument cache for all packages needed in the remediation loop.
|
|
316
|
+
// This converts N sequential registry round-trips into one concurrent burst,
|
|
317
|
+
// after which the loop runs entirely from the in-memory packument cache.
|
|
318
|
+
if (!offline) {
|
|
319
|
+
const packumentsToPrewarm = new Set();
|
|
320
|
+
for (const finding of findings) {
|
|
321
|
+
if (finding.relationship !== "transitive")
|
|
322
|
+
continue;
|
|
323
|
+
packumentsToPrewarm.add(finding.pkg.name);
|
|
324
|
+
const paths = finding.dependencyPaths;
|
|
325
|
+
if (paths.length > 0 && paths[0].length >= 2) {
|
|
326
|
+
packumentsToPrewarm.add(paths[0][paths[0].length - 2]);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (packumentsToPrewarm.size > 0) {
|
|
330
|
+
await runWithConcurrency([...packumentsToPrewarm], 8, async (name) => {
|
|
331
|
+
try {
|
|
332
|
+
await fetchPackument(name);
|
|
333
|
+
}
|
|
334
|
+
catch { /* loop will handle missing packuments */ }
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
300
338
|
for (const finding of findings) {
|
|
301
339
|
if (finding.relationship !== "transitive")
|
|
302
340
|
continue;
|
package/dist/utils/advisory.js
CHANGED
|
@@ -4,3 +4,20 @@ export function isPrivateRegistrySource(pkg) {
|
|
|
4
4
|
pkg.resolvedUrl !== "" &&
|
|
5
5
|
!pkg.resolvedUrl.startsWith(NPM_PUBLIC_REGISTRY));
|
|
6
6
|
}
|
|
7
|
+
const GIT_SOURCE_PREFIXES = [
|
|
8
|
+
"https://codeload.github.com/",
|
|
9
|
+
"https://github.com/",
|
|
10
|
+
"https://gitlab.com/",
|
|
11
|
+
"https://bitbucket.org/",
|
|
12
|
+
"git+https://",
|
|
13
|
+
"git+ssh://",
|
|
14
|
+
"git://",
|
|
15
|
+
];
|
|
16
|
+
export function isGitSource(pkg) {
|
|
17
|
+
return (pkg.resolvedUrl !== undefined &&
|
|
18
|
+
pkg.resolvedUrl !== "" &&
|
|
19
|
+
GIT_SOURCE_PREFIXES.some(prefix => pkg.resolvedUrl.startsWith(prefix)));
|
|
20
|
+
}
|
|
21
|
+
export function hasCommitShaPinning(pkg) {
|
|
22
|
+
return pkg.resolvedUrl !== undefined && /[0-9a-f]{40}/i.test(pkg.resolvedUrl);
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cve-lite-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.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": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@types/node": "^24.0.0",
|
|
26
26
|
"jest": "^30.3.0",
|
|
27
27
|
"ts-jest": "^29.4.9",
|
|
28
|
-
"tsx": "^4.
|
|
28
|
+
"tsx": "^4.22.0",
|
|
29
29
|
"typescript": "^5.8.2"
|
|
30
30
|
},
|
|
31
31
|
"keywords": [
|
|
@@ -44,6 +44,14 @@
|
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=18"
|
|
46
46
|
},
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/OWASP/cve-lite-cli.git"
|
|
50
|
+
},
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/OWASP/cve-lite-cli/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/OWASP/cve-lite-cli#readme",
|
|
47
55
|
"files": [
|
|
48
56
|
"dist",
|
|
49
57
|
"README.md",
|