cve-lite-cli 1.15.0 → 1.16.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/README.md +15 -3
- package/dist/cli/args.js +14 -0
- package/dist/cli/help.js +2 -0
- package/dist/index.js +32 -39
- package/dist/output/cyclonedx.js +88 -0
- package/dist/output/sarif.js +91 -0
- package/dist/output/write-outputs.js +54 -0
- package/dist/utils/severity.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ No account. No configuration. No source code leaves your machine.
|
|
|
89
89
|
- **Offline advisory DB** — sync advisory data ahead of time and scan with zero runtime API calls, designed for enterprise and air-gapped environments
|
|
90
90
|
- **Interactive HTML report** — generate a self-contained dashboard with severity cards, a searchable findings table, and copy-ready fix commands (`--report`)
|
|
91
91
|
- **Auto-fix mode** — apply validated direct dependency fixes and rescan automatically (`--fix`)
|
|
92
|
-
- **CI-ready** — `--fail-on high` exits non-zero on findings at or above a severity threshold; a first-party [GitHub Action](https://github.com/marketplace/actions/cve-lite-cli) is available on the Marketplace
|
|
92
|
+
- **CI-ready** — `--fail-on high` exits non-zero on findings at or above a severity threshold; a first-party [GitHub Action](https://github.com/marketplace/actions/cve-lite-cli) is available on the Marketplace; `--sarif` writes SARIF 2.1.0 output for direct upload to GitHub Code Scanning; `--cdx` writes a CycloneDX 1.4 SBOM for Dependency-Track and compliance artifacts; `--json` integrates with SIEM tools and dashboards
|
|
93
93
|
- **Minimal footprint** — four runtime dependencies, intentionally kept small for a security tool
|
|
94
94
|
|
|
95
95
|
## What it looks like
|
|
@@ -132,7 +132,7 @@ CVE Lite CLI fits at every stage of the development workflow, not just CI.
|
|
|
132
132
|
|
|
133
133
|
**Local development** — run a scan before opening a PR. The default output is fast and minimal. `--verbose` adds the full fix plan with dependency paths and prioritized remediation commands. `--report` opens an interactive HTML dashboard.
|
|
134
134
|
|
|
135
|
-
**CI pipelines** — use `--fail-on high` to gate builds on severity. JSON output (`--json`) integrates with SIEM, dashboards, and custom automation. SARIF output
|
|
135
|
+
**CI pipelines** — use `--fail-on high` to gate builds on severity. JSON output (`--json`) integrates with SIEM, dashboards, and custom automation. SARIF output (`--sarif`) writes a SARIF 2.1.0 file for direct upload to GitHub Code Scanning — findings appear in the Security tab and annotate PRs.
|
|
136
136
|
|
|
137
137
|
**Restricted and enterprise environments** — sync the advisory database ahead of time with `cve-lite advisories sync`, then scan offline with `--offline`. No runtime outbound calls during the scan. Syncing ~217,065 advisory records completes in under 9 seconds.
|
|
138
138
|
|
|
@@ -143,8 +143,17 @@ CVE Lite CLI fits at every stage of the development workflow, not just CI.
|
|
|
143
143
|
with:
|
|
144
144
|
verbose: "true"
|
|
145
145
|
fail-on: high
|
|
146
|
+
sarif: "true"
|
|
147
|
+
|
|
148
|
+
- name: Upload to GitHub Code Scanning
|
|
149
|
+
uses: github/codeql-action/upload-sarif@v4
|
|
150
|
+
if: always()
|
|
151
|
+
with:
|
|
152
|
+
sarif_file: ${{ github.workspace }}
|
|
146
153
|
```
|
|
147
154
|
|
|
155
|
+
> **Note:** `if: always()` is required on the upload step. Without it, the upload is skipped when `--fail-on` exits non-zero — losing your findings in Code Scanning exactly when they matter most.
|
|
156
|
+
|
|
148
157
|
CVE Lite CLI scans its own dependencies in CI. See [`self-scan.yml`](https://github.com/OWASP/cve-lite-cli/blob/main/.github/workflows/self-scan.yml).
|
|
149
158
|
|
|
150
159
|
For full CI patterns including offline workflows, git hooks, and scripted automation, see the [CI and Workflow Integration guide](https://owasp.org/cve-lite-cli/docs/ci-integration).
|
|
@@ -248,6 +257,9 @@ cve-lite /path/to/project --fail-on high
|
|
|
248
257
|
# JSON output
|
|
249
258
|
cve-lite /path/to/project --json
|
|
250
259
|
|
|
260
|
+
# SARIF output for GitHub Code Scanning and other SARIF-compatible tools
|
|
261
|
+
cve-lite /path/to/project --sarif
|
|
262
|
+
|
|
251
263
|
# Generate an HTML vulnerability dashboard (opens in browser automatically)
|
|
252
264
|
cve-lite /path/to/project --report
|
|
253
265
|
cve-lite /path/to/project --report ./my-report --no-open
|
|
@@ -485,4 +497,4 @@ If CVE Lite CLI helps your release workflow, a [GitHub star](https://github.com/
|
|
|
485
497
|
|
|
486
498
|
## License
|
|
487
499
|
|
|
488
|
-
MIT
|
|
500
|
+
MIT — built in public and maintained as an OWASP Foundation Project by Sonu Kapoor.
|
package/dist/cli/args.js
CHANGED
|
@@ -174,6 +174,14 @@ export function parseArgs(argv) {
|
|
|
174
174
|
options.noCache = true;
|
|
175
175
|
continue;
|
|
176
176
|
}
|
|
177
|
+
if (arg === "--sarif") {
|
|
178
|
+
options.sarif = true;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (arg === "--cdx") {
|
|
182
|
+
options.cdx = true;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
177
185
|
if (arg.startsWith("-"))
|
|
178
186
|
throw new Error(`Unknown option: ${arg}`);
|
|
179
187
|
if (!projectArg) {
|
|
@@ -182,5 +190,11 @@ export function parseArgs(argv) {
|
|
|
182
190
|
}
|
|
183
191
|
throw new Error(`Unexpected argument: ${arg}`);
|
|
184
192
|
}
|
|
193
|
+
if (options.sarif && options.report) {
|
|
194
|
+
throw new Error("cannot combine --sarif and --report");
|
|
195
|
+
}
|
|
196
|
+
if (options.cdx && options.report) {
|
|
197
|
+
throw new Error("cannot combine --cdx and --report");
|
|
198
|
+
}
|
|
185
199
|
return { command: "scan", options, projectArg };
|
|
186
200
|
}
|
package/dist/cli/help.js
CHANGED
|
@@ -33,6 +33,8 @@ export function printHelp() {
|
|
|
33
33
|
"Scan options:",
|
|
34
34
|
" --json Print JSON output",
|
|
35
35
|
" --report [dir] Generate an HTML report in [dir] (default: ./cve-report)",
|
|
36
|
+
" --sarif Write SARIF 2.1.0 output to a timestamped .sarif file",
|
|
37
|
+
" --cdx Write CycloneDX 1.4 SBOM to a timestamped .cdx.json file",
|
|
36
38
|
" --no-open Don't auto-open the report in the browser",
|
|
37
39
|
" --fix Apply validated direct dependency fixes and rescan",
|
|
38
40
|
" --osv-url <url> Use a custom OSV-compatible advisory endpoint",
|
package/dist/index.js
CHANGED
|
@@ -16,8 +16,9 @@ import { buildSuggestedFixCommandPlan } from "./remediation/fix-commands.js";
|
|
|
16
16
|
import { scanProjectForPackageUsage } from "./usage/scanner.js";
|
|
17
17
|
import { getCliVersion } from "./utils/version-info.js";
|
|
18
18
|
import { isLikelyBlockedAdvisoryRequestError } from "./utils/network.js";
|
|
19
|
-
import { logInfo, logWarn, printCacheSummary,
|
|
19
|
+
import { logInfo, logWarn, printCacheSummary, sortFindingsForOutput } from "./output/formatters.js";
|
|
20
20
|
import { buildReportData, writeHtmlReport } from "./output/html-reporter.js";
|
|
21
|
+
import { writeOutputs } from "./output/write-outputs.js";
|
|
21
22
|
import { printSummary, printActionSummary, printSuggestedFixCommands, printSuggestedFixCommandSkips, printCoverage, printSkippedDependencies, printTable, printFinalStatus, printCompactOutput } from "./output/printers.js";
|
|
22
23
|
import { installSkill } from "./skills/install.js";
|
|
23
24
|
let parsedArgs = null;
|
|
@@ -191,49 +192,40 @@ if (parsedArgs) {
|
|
|
191
192
|
remainingBySeverity: countBySeverity(scanState.sorted),
|
|
192
193
|
});
|
|
193
194
|
}
|
|
194
|
-
else
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
fs.writeFileSync(jsonOutputPath, JSON.stringify({
|
|
199
|
-
projectPath,
|
|
200
|
-
mode: scanInput.mode,
|
|
201
|
-
source: scanInput.source,
|
|
202
|
-
packageCount: packages.length,
|
|
203
|
-
findingCount: scanState.sorted.length,
|
|
195
|
+
else {
|
|
196
|
+
await writeOutputs(options, {
|
|
197
|
+
sorted: scanState.sorted,
|
|
198
|
+
allPackages: scanState.allPackages,
|
|
204
199
|
suggestedFixCommands: scanState.suggestedFixCommands,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
200
|
+
coverage: scanState.coverage,
|
|
201
|
+
minSeverity: scanState.minSeverity,
|
|
202
|
+
tableFindings: scanState.tableFindings,
|
|
203
|
+
}, scanInput, projectPath);
|
|
204
|
+
if (!(options.json || options.sarif || options.cdx) || options.verbose) {
|
|
205
|
+
const offline = !!options.offline || !!options.offlineDb;
|
|
206
|
+
if (options.verbose) {
|
|
207
|
+
printSummary(scanState.sorted, packages.length, scanInput);
|
|
208
|
+
printActionSummary(scanState.sorted);
|
|
209
|
+
printSuggestedFixCommands(scanState.sorted, scanInput, { offline });
|
|
210
|
+
printSuggestedFixCommandSkips(scanState.sorted, scanInput, { offline });
|
|
211
|
+
if (scanInput.skippedDependencies.length > 0) {
|
|
212
|
+
printSkippedDependencies(scanInput.skippedDependencies);
|
|
213
|
+
}
|
|
214
|
+
if (scanState.sorted.length > 0) {
|
|
215
|
+
if (scanState.tableFindings.length > 0) {
|
|
216
|
+
printTable(scanState.tableFindings, options.all ? null : scanState.minSeverity);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
logInfo(`No findings met the table threshold of ${scanState.minSeverity}. Re-run with --all to show everything.`, options);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
printCoverage([...scanInput.notes, ...scanState.coverage]);
|
|
223
|
+
printFinalStatus(scanState.sorted);
|
|
225
224
|
}
|
|
226
225
|
else {
|
|
227
|
-
|
|
226
|
+
printCompactOutput(scanState.sorted, scanInput, { offline, all: !!options.all });
|
|
228
227
|
}
|
|
229
228
|
}
|
|
230
|
-
printCoverage([...scanInput.notes, ...scanState.coverage]);
|
|
231
|
-
printFinalStatus(scanState.sorted);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
// Simplified output - cleaner, focused view
|
|
235
|
-
const offline = !!options.offline || !!options.offlineDb;
|
|
236
|
-
printCompactOutput(scanState.sorted, scanInput, { offline, all: !!options.all });
|
|
237
229
|
}
|
|
238
230
|
if (options.report) {
|
|
239
231
|
const outputDir = path.resolve(typeof options.report === "string" ? options.report : "./cve-report");
|
|
@@ -318,6 +310,7 @@ async function scanProject(params) {
|
|
|
318
310
|
minSeverity,
|
|
319
311
|
tableFindings,
|
|
320
312
|
suggestedFixCommands,
|
|
313
|
+
allPackages: params.scanInput.packages,
|
|
321
314
|
};
|
|
322
315
|
}
|
|
323
316
|
async function applyFixesIfRequested(params) {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
|
|
5
|
+
import { getRecommendedAction } from "./formatters.js";
|
|
6
|
+
import { getCliVersion } from "../utils/version-info.js";
|
|
7
|
+
export function buildPurl(name, version) {
|
|
8
|
+
const encodedName = name.startsWith("@") ? `%40${name.slice(1)}` : name;
|
|
9
|
+
return `pkg:npm/${encodedName}@${version}`;
|
|
10
|
+
}
|
|
11
|
+
export function buildCycloneDxBom(allPackages, findings, projectMeta, version, plan = null) {
|
|
12
|
+
const components = allPackages.map(pkg => {
|
|
13
|
+
const purl = buildPurl(pkg.name, pkg.version);
|
|
14
|
+
return {
|
|
15
|
+
type: "library",
|
|
16
|
+
"bom-ref": purl,
|
|
17
|
+
name: pkg.name,
|
|
18
|
+
version: pkg.version,
|
|
19
|
+
purl,
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
// Deduplicate vulnerabilities by CVE ID — one entry per CVE with multiple affects
|
|
23
|
+
const vulnMap = new Map();
|
|
24
|
+
for (const finding of findings) {
|
|
25
|
+
const cveIds = finding.cveAliases.length > 0
|
|
26
|
+
? finding.cveAliases
|
|
27
|
+
: finding.vulnerabilities.map(v => v.id);
|
|
28
|
+
const purl = buildPurl(finding.pkg.name, finding.pkg.version);
|
|
29
|
+
for (const cveId of cveIds) {
|
|
30
|
+
const existing = vulnMap.get(cveId);
|
|
31
|
+
if (existing) {
|
|
32
|
+
existing.affects.push({ ref: purl });
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// severity from first finding wins when the same CVE affects multiple packages
|
|
36
|
+
vulnMap.set(cveId, { finding, affects: [{ ref: purl }] });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const vulnerabilities = [];
|
|
41
|
+
for (const [cveId, { finding, affects }] of vulnMap) {
|
|
42
|
+
const runnableFixCommand = plan ? findSuggestedCommandForFinding(plan, finding) : null;
|
|
43
|
+
const recommendation = runnableFixCommand ?? getRecommendedAction(finding);
|
|
44
|
+
vulnerabilities.push({
|
|
45
|
+
id: cveId,
|
|
46
|
+
source: {
|
|
47
|
+
name: "OSV",
|
|
48
|
+
url: `https://osv.dev/vulnerability/${cveId}`,
|
|
49
|
+
},
|
|
50
|
+
ratings: [{ severity: finding.severity, method: "other" }],
|
|
51
|
+
affects,
|
|
52
|
+
recommendation,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const metadata = {
|
|
56
|
+
timestamp: new Date().toISOString(),
|
|
57
|
+
tools: [
|
|
58
|
+
{ vendor: "OWASP", name: "CVE Lite CLI", version },
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
if (projectMeta && projectMeta.name) {
|
|
62
|
+
const metaComponent = {
|
|
63
|
+
type: "application",
|
|
64
|
+
name: projectMeta.name,
|
|
65
|
+
};
|
|
66
|
+
if (projectMeta.version) {
|
|
67
|
+
metaComponent.version = projectMeta.version;
|
|
68
|
+
}
|
|
69
|
+
metadata.component = metaComponent;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
bomFormat: "CycloneDX",
|
|
73
|
+
specVersion: "1.4",
|
|
74
|
+
version: 1,
|
|
75
|
+
serialNumber: `urn:uuid:${randomUUID()}`,
|
|
76
|
+
metadata,
|
|
77
|
+
components,
|
|
78
|
+
vulnerabilities,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function writeCycloneDxReport(allPackages, findings, plan, projectMeta) {
|
|
82
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
83
|
+
const filename = `cve-lite-scan-${ts}.cdx.json`;
|
|
84
|
+
const outputPath = path.join(process.cwd(), filename);
|
|
85
|
+
const bom = buildCycloneDxBom(allPackages, findings, projectMeta, getCliVersion(), plan);
|
|
86
|
+
fs.writeFileSync(outputPath, JSON.stringify(bom, null, 2));
|
|
87
|
+
return filename;
|
|
88
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
|
|
4
|
+
import { getRecommendedAction } from "./formatters.js";
|
|
5
|
+
import { getCliVersion } from "../utils/version-info.js";
|
|
6
|
+
import { severityToSarifLevel } from "../utils/severity.js";
|
|
7
|
+
const SARIF_RULE_NAME = "VulnerableDependency";
|
|
8
|
+
const LOCKFILE_NAMES = {
|
|
9
|
+
"package-lock": "package-lock.json",
|
|
10
|
+
"pnpm-lock": "pnpm-lock.yaml",
|
|
11
|
+
"yarn-lock": "yarn.lock",
|
|
12
|
+
"bun-lock": "bun.lockb",
|
|
13
|
+
"package-json": "package.json",
|
|
14
|
+
"unknown": "lockfile",
|
|
15
|
+
};
|
|
16
|
+
export function deriveLockfileUri(scanInput) {
|
|
17
|
+
if (scanInput.filePath)
|
|
18
|
+
return path.basename(scanInput.filePath);
|
|
19
|
+
return LOCKFILE_NAMES[scanInput.source] ?? "lockfile";
|
|
20
|
+
}
|
|
21
|
+
export function buildSarifOutput(findings, lockfileUri, version, plan) {
|
|
22
|
+
const ruleMap = new Map();
|
|
23
|
+
const results = [];
|
|
24
|
+
for (const finding of findings) {
|
|
25
|
+
const level = severityToSarifLevel(finding.severity);
|
|
26
|
+
const action = getRecommendedAction(finding);
|
|
27
|
+
const runnableFixCommand = plan ? findSuggestedCommandForFinding(plan, finding) : null;
|
|
28
|
+
const location = {
|
|
29
|
+
physicalLocation: {
|
|
30
|
+
artifactLocation: { uri: lockfileUri, uriBaseId: "%SRCROOT%" },
|
|
31
|
+
region: { startLine: 1 },
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const ruleIds = finding.cveAliases.length > 0
|
|
35
|
+
? finding.cveAliases
|
|
36
|
+
: finding.vulnerabilities.map(v => v.id);
|
|
37
|
+
for (const ruleId of ruleIds) {
|
|
38
|
+
if (!ruleMap.has(ruleId)) {
|
|
39
|
+
ruleMap.set(ruleId, {
|
|
40
|
+
id: ruleId,
|
|
41
|
+
name: SARIF_RULE_NAME,
|
|
42
|
+
shortDescription: { text: ruleId },
|
|
43
|
+
fullDescription: { text: `Vulnerable dependency: ${ruleId}` },
|
|
44
|
+
helpUri: `https://osv.dev/vulnerability/${ruleId}`,
|
|
45
|
+
defaultConfiguration: { level },
|
|
46
|
+
properties: { tags: ["security", "dependency"] },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const result = {
|
|
50
|
+
ruleId,
|
|
51
|
+
level,
|
|
52
|
+
message: {
|
|
53
|
+
text: `${finding.pkg.name}@${finding.pkg.version} is vulnerable (${finding.severity}). ${action}`,
|
|
54
|
+
},
|
|
55
|
+
locations: [location],
|
|
56
|
+
};
|
|
57
|
+
if (runnableFixCommand) {
|
|
58
|
+
result.fixes = [{ description: { text: runnableFixCommand }, artifactChanges: [] }];
|
|
59
|
+
}
|
|
60
|
+
results.push(result);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
$schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
|
|
65
|
+
version: "2.1.0",
|
|
66
|
+
runs: [
|
|
67
|
+
{
|
|
68
|
+
tool: {
|
|
69
|
+
driver: {
|
|
70
|
+
name: "CVE Lite CLI",
|
|
71
|
+
version,
|
|
72
|
+
informationUri: "https://owasp.org/cve-lite-cli/",
|
|
73
|
+
rules: Array.from(ruleMap.values()),
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
results,
|
|
77
|
+
artifacts: [
|
|
78
|
+
{ location: { uri: lockfileUri, uriBaseId: "%SRCROOT%" } },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export function writeSarifReport(findings, lockfileUri, plan) {
|
|
85
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
86
|
+
const filename = `cve-lite-scan-${ts}.sarif`;
|
|
87
|
+
const outputPath = path.join(process.cwd(), filename);
|
|
88
|
+
const sarif = buildSarifOutput(findings, lockfileUri, getCliVersion(), plan);
|
|
89
|
+
fs.writeFileSync(outputPath, JSON.stringify(sarif, null, 2));
|
|
90
|
+
return filename;
|
|
91
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { chalk } from "../utils/chalk.js";
|
|
4
|
+
import { serializeFinding } from "./formatters.js";
|
|
5
|
+
import { writeSarifReport, deriveLockfileUri } from "./sarif.js";
|
|
6
|
+
import { writeCycloneDxReport } from "./cyclonedx.js";
|
|
7
|
+
function readProjectMeta(projectPath) {
|
|
8
|
+
try {
|
|
9
|
+
const pkgPath = path.join(projectPath, "package.json");
|
|
10
|
+
if (!fs.existsSync(pkgPath))
|
|
11
|
+
return null;
|
|
12
|
+
const raw = fs.readFileSync(pkgPath, "utf-8");
|
|
13
|
+
const parsed = JSON.parse(raw);
|
|
14
|
+
if (!parsed.name)
|
|
15
|
+
return null;
|
|
16
|
+
return {
|
|
17
|
+
name: typeof parsed.name === "string" ? parsed.name : undefined,
|
|
18
|
+
version: typeof parsed.version === "string" ? parsed.version : undefined,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function writeOutputs(options, scanState, scanInput, projectPath) {
|
|
26
|
+
if (options.json) {
|
|
27
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
28
|
+
const jsonFilename = `cve-lite-scan-${ts}.json`;
|
|
29
|
+
const jsonOutputPath = path.join(process.cwd(), jsonFilename);
|
|
30
|
+
fs.writeFileSync(jsonOutputPath, JSON.stringify({
|
|
31
|
+
projectPath,
|
|
32
|
+
mode: scanInput.mode,
|
|
33
|
+
source: scanInput.source,
|
|
34
|
+
packageCount: scanInput.packages.length,
|
|
35
|
+
findingCount: scanState.sorted.length,
|
|
36
|
+
suggestedFixCommands: scanState.suggestedFixCommands,
|
|
37
|
+
notes: [...scanInput.notes, ...scanState.coverage],
|
|
38
|
+
warnings: scanInput.warnings,
|
|
39
|
+
skippedDependencies: scanInput.skippedDependencies,
|
|
40
|
+
findings: scanState.sorted.map(finding => serializeFinding(finding, scanState.suggestedFixCommands)),
|
|
41
|
+
}, null, 2));
|
|
42
|
+
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(jsonFilename)}`);
|
|
43
|
+
}
|
|
44
|
+
if (options.sarif) {
|
|
45
|
+
const lockfileUri = deriveLockfileUri(scanInput);
|
|
46
|
+
const sarifFilename = writeSarifReport(scanState.sorted, lockfileUri, scanState.suggestedFixCommands);
|
|
47
|
+
console.log(`${chalk.gray("SARIF report written to")} ${chalk.cyan(sarifFilename)}`);
|
|
48
|
+
}
|
|
49
|
+
if (options.cdx) {
|
|
50
|
+
const projectMeta = readProjectMeta(projectPath);
|
|
51
|
+
const cdxFilename = writeCycloneDxReport(scanState.allPackages, scanState.sorted, scanState.suggestedFixCommands, projectMeta);
|
|
52
|
+
console.log(`${chalk.gray("CycloneDX BOM written to")} ${chalk.cyan(cdxFilename)}`);
|
|
53
|
+
}
|
|
54
|
+
}
|