cve-lite-cli 1.1.1 → 1.3.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 +216 -34
- package/dist/cli/args.js +8 -0
- package/dist/cli/help.js +6 -1
- package/dist/index.js +146 -134
- package/dist/output/printers.js +39 -3
- package/dist/remediation/fix-commands.js +121 -0
- package/dist/utils/version-info.js +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
[](https://www.npmjs.com/package/cve-lite-cli)
|
|
3
3
|
[](https://www.npmjs.com/package/cve-lite-cli)
|
|
4
4
|
[](https://github.com/sonukapoor/cve-lite-cli/actions)
|
|
5
|
+
[](https://github.com/marketplace/actions/cve-lite-cli)
|
|
5
6
|
[](https://github.com/sonukapoor/cve-lite-cli/blob/main/LICENSE)
|
|
6
7
|
|
|
7
8
|
<div align="center">
|
|
8
|
-
<img src="https://
|
|
9
|
+
<img src="https://raw.githubusercontent.com/sonukapoor/cve-lite-cli/main/assets/logo-with-title.png" alt="CVE Lite CLI" width="320"/>
|
|
9
10
|
|
|
10
11
|
<h1>CVE Lite CLI</h1>
|
|
11
12
|
<p>Fast, developer-friendly vulnerability scanning for JavaScript and TypeScript projects, with offline support for restricted environments.</p>
|
|
@@ -23,6 +24,48 @@
|
|
|
23
24
|
|
|
24
25
|
---
|
|
25
26
|
|
|
27
|
+
## Contents
|
|
28
|
+
|
|
29
|
+
<table>
|
|
30
|
+
<tr>
|
|
31
|
+
<td valign="top">
|
|
32
|
+
<strong>Overview</strong><br/>
|
|
33
|
+
<a href="#what-is-cve-lite-cli">What is CVE Lite CLI</a><br/>
|
|
34
|
+
<a href="#new-offline-advisory-db-support">Offline advisory DB support</a><br/>
|
|
35
|
+
<a href="#why-offline-mode-matters">Why offline mode matters</a><br/>
|
|
36
|
+
<a href="docs/case-studies/owasp-juice-shop.md">OWASP Juice Shop case study</a><br/>
|
|
37
|
+
<a href="#what-it-looks-like">What it looks like</a><br/>
|
|
38
|
+
<a href="#why-this-tool-exists">Why this tool exists</a><br/>
|
|
39
|
+
<a href="#project-scope-and-differentiation">Project scope and differentiation</a>
|
|
40
|
+
</td>
|
|
41
|
+
<td valign="top">
|
|
42
|
+
<strong>Usage</strong><br/>
|
|
43
|
+
<a href="#quick-start">Quick start</a><br/>
|
|
44
|
+
<a href="#usage">Usage</a><br/>
|
|
45
|
+
<a href="#workflow-modes">Workflow modes</a><br/>
|
|
46
|
+
<a href="#network-behavior-and-privacy">Network behavior and privacy</a><br/>
|
|
47
|
+
<a href="#features">Features</a><br/>
|
|
48
|
+
<a href="#supported-workflows">Supported workflows</a>
|
|
49
|
+
</td>
|
|
50
|
+
<td valign="top">
|
|
51
|
+
<strong>CI and Offline</strong><br/>
|
|
52
|
+
<a href="#dependency-footprint">Dependency footprint</a><br/>
|
|
53
|
+
<a href="#example-use-cases">Example use cases</a><br/>
|
|
54
|
+
<a href="#recommended-workflow-patterns">Recommended workflow patterns</a><br/>
|
|
55
|
+
<a href="#comparison-with-other-tools">Comparison with other tools</a><br/>
|
|
56
|
+
<a href="#current-limitations">Current limitations</a><br/>
|
|
57
|
+
<a href="#positioning">Positioning</a>
|
|
58
|
+
</td>
|
|
59
|
+
<td valign="top">
|
|
60
|
+
<strong>Project</strong><br/>
|
|
61
|
+
<a href="#roadmap">Roadmap</a><br/>
|
|
62
|
+
<a href="#contributing">Contributing</a><br/>
|
|
63
|
+
<a href="#community-and-support">Community and support</a><br/>
|
|
64
|
+
<a href="#license">License</a>
|
|
65
|
+
</td>
|
|
66
|
+
</tr>
|
|
67
|
+
</table>
|
|
68
|
+
|
|
26
69
|
## What is CVE Lite CLI
|
|
27
70
|
|
|
28
71
|
**CVE Lite CLI** helps developers scan their projects for known package vulnerabilities without signing up for an expensive platform. It is built for the moment right before release, when you want a clear answer, a practical fix plan, and a tool you can actually afford to use.
|
|
@@ -34,6 +77,8 @@ It is designed to be:
|
|
|
34
77
|
- usable in enterprise and restricted-network environments
|
|
35
78
|
- capable of zero-runtime-network scans through a local advisory database
|
|
36
79
|
|
|
80
|
+
For a real-world remediation example, see the [OWASP Juice Shop case study](docs/case-studies/owasp-juice-shop.md).
|
|
81
|
+
|
|
37
82
|
## New: Offline advisory DB support
|
|
38
83
|
|
|
39
84
|
CVE Lite CLI now supports a local advisory database workflow for teams that cannot allow runtime outbound advisory API calls.
|
|
@@ -70,6 +115,8 @@ Offline advisory DB support makes CVE Lite CLI more practical for:
|
|
|
70
115
|
|
|
71
116
|
This is one of the most important differentiators in the project today because it improves both trust and adoptability, not just convenience.
|
|
72
117
|
|
|
118
|
+
The project also ships a reusable first-party GitHub Action, now available on the [GitHub Marketplace](https://github.com/marketplace/actions/cve-lite-cli), for teams that want a low-friction CI integration path.
|
|
119
|
+
|
|
73
120
|
## Quick start
|
|
74
121
|
|
|
75
122
|
Install globally:
|
|
@@ -106,18 +153,21 @@ cve-lite /path/to/project --min-severity high
|
|
|
106
153
|
# Recommended for CI logs when you want full context
|
|
107
154
|
cve-lite /path/to/project --verbose
|
|
108
155
|
|
|
156
|
+
# Limit the scan to production dependencies where supported by the lockfile
|
|
157
|
+
cve-lite /path/to/project --prod-only
|
|
158
|
+
|
|
109
159
|
# Fail a build on high severity and above
|
|
110
160
|
cve-lite /path/to/project --fail-on high
|
|
111
161
|
|
|
112
162
|
# JSON output
|
|
113
163
|
cve-lite /path/to/project --json
|
|
114
164
|
|
|
115
|
-
# SARIF output
|
|
116
|
-
cve-lite /path/to/project --sarif --output reports/scan.sarif
|
|
117
|
-
|
|
118
165
|
# Use a custom advisory endpoint
|
|
119
166
|
cve-lite /path/to/project --osv-url https://security.company.internal/osv
|
|
120
167
|
|
|
168
|
+
# Show the CLI version
|
|
169
|
+
cve-lite --version
|
|
170
|
+
|
|
121
171
|
# Build the local advisory DB for offline scans
|
|
122
172
|
cve-lite advisories sync
|
|
123
173
|
|
|
@@ -160,7 +210,17 @@ cve-lite /path/to/project --offline
|
|
|
160
210
|
|
|
161
211
|
CVE Lite CLI produces a clean, summary-first console view by default, designed for fast triage before release.
|
|
162
212
|
|
|
163
|
-
|
|
213
|
+
The default output is designed to stay concise while still surfacing the most important next step, including package-manager-aware suggested fix commands when confident targets exist.
|
|
214
|
+
|
|
215
|
+
For example, the tool can now suggest a concrete next command such as:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
npm install jsonwebtoken@4.2.2 express-jwt@2.1.0 sanitize-html@2.17.2
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
The exact command adapts to the dependency file used for the scan, so `package-lock.json`, `pnpm-lock.yaml`, and `yarn.lock` can each produce a package-manager-specific suggestion.
|
|
222
|
+
|
|
223
|
+
For deeper investigation, running with `--verbose` provides the fuller remediation context, including dependency paths, parent upgrade guidance for transitive issues when available, a complete fix plan, skipped-item context for unresolved urgent findings, and a detailed table view.
|
|
164
224
|
|
|
165
225
|
That is the core idea: install it, point it at your project, and immediately get a practical fix plan instead of a wall of raw advisories.
|
|
166
226
|
|
|
@@ -168,6 +228,10 @@ The final status line also gives the scan a clear ending, which makes terminal u
|
|
|
168
228
|
|
|
169
229
|
See the example below using OWASP Juice Shop for real output samples.
|
|
170
230
|
|
|
231
|
+
For a real-world case study, see the [OWASP Juice Shop case study](docs/case-studies/owasp-juice-shop.md).
|
|
232
|
+
|
|
233
|
+
If you maintain an open-source JavaScript or TypeScript project and want CVE Lite CLI evaluated on it, open an issue and share the repository. Strong candidates may be turned into future public case studies.
|
|
234
|
+
|
|
171
235
|
## Example: Scanning OWASP Juice Shop (Real Output)
|
|
172
236
|
|
|
173
237
|
CVE Lite CLI can be used against real-world vulnerable applications such as the OWASP Juice Shop.
|
|
@@ -185,16 +249,15 @@ cve-lite .
|
|
|
185
249
|
```
|
|
186
250
|
|
|
187
251
|
<p align="center">
|
|
188
|
-
<img src="https://
|
|
252
|
+
<img src="https://raw.githubusercontent.com/sonukapoor/cve-lite-cli/main/assets/default-output.png" alt="CVE Lite CLI default output screenshot" width="900"/>
|
|
189
253
|
</p>
|
|
190
254
|
|
|
191
255
|
Verbose examples:
|
|
192
256
|
|
|
193
257
|
<p align="center">
|
|
194
|
-
<img src="https://
|
|
195
|
-
<img src="https://
|
|
196
|
-
<img src="https://
|
|
197
|
-
<img src="https://github.com/sonukapoor/cve-lite-cli/blob/main/assets/verbose-output-4.png" alt="CVE Lite CLI verbose output screenshot" width="900"/>
|
|
258
|
+
<img src="https://raw.githubusercontent.com/sonukapoor/cve-lite-cli/main/assets/verbose-output-1.png" alt="CVE Lite CLI verbose output screenshot" width="900"/>
|
|
259
|
+
<img src="https://raw.githubusercontent.com/sonukapoor/cve-lite-cli/main/assets/verbose-output-2.png" alt="CVE Lite CLI verbose output screenshot" width="900"/>
|
|
260
|
+
<img src="https://raw.githubusercontent.com/sonukapoor/cve-lite-cli/main/assets/verbose-output-3.png" alt="CVE Lite CLI verbose output screenshot" width="900"/>
|
|
198
261
|
</p>
|
|
199
262
|
|
|
200
263
|
## Why this tool exists
|
|
@@ -224,7 +287,7 @@ The project emphasizes:
|
|
|
224
287
|
- npm, pnpm, and Yarn lockfile support
|
|
225
288
|
- direct vs transitive visibility
|
|
226
289
|
- top-priority fixes and a suggested remediation plan
|
|
227
|
-
- JSON
|
|
290
|
+
- JSON output for automation
|
|
228
291
|
- offline scanning through a local advisory database
|
|
229
292
|
- configurable advisory endpoint support via `--osv-url` for internal proxies or mirrors
|
|
230
293
|
- a small, reviewable runtime footprint
|
|
@@ -243,7 +306,20 @@ Its role is narrower and workflow-focused:
|
|
|
243
306
|
- built to highlight top-priority fixes and a suggested remediation plan
|
|
244
307
|
- intentionally lightweight in runtime footprint and setup
|
|
245
308
|
|
|
246
|
-
|
|
309
|
+
The closest OWASP comparisons are:
|
|
310
|
+
|
|
311
|
+
- **OWASP Dependency-Check**
|
|
312
|
+
A broader dependency analysis tool that covers many ecosystems and use cases beyond the lockfile-first JavaScript/TypeScript workflow emphasized here.
|
|
313
|
+
|
|
314
|
+
- **OWASP dep-scan**
|
|
315
|
+
A broader dependency and security analysis tool with wider language and environment coverage than this project is trying to provide.
|
|
316
|
+
|
|
317
|
+
- **OWASP Dependency-Track**
|
|
318
|
+
More SBOM- and platform-oriented, with a different operational model than a lightweight local CLI focused on developer checks close to release time.
|
|
319
|
+
|
|
320
|
+
CVE Lite CLI is intentionally narrower: it is JavaScript/TypeScript focused, lockfile-first, local-first, designed for fast local checks and simple CI gates, and built to surface direct vs transitive visibility, top-priority fixes, suggested remediation guidance, offline advisory DB workflows, and a small, reviewable runtime footprint.
|
|
321
|
+
|
|
322
|
+
This section is here to make the scope clear. CVE Lite CLI is meant to complement the broader OWASP ecosystem by serving a practical developer workflow close to release time.
|
|
247
323
|
|
|
248
324
|
One of the clearest examples of that focus is offline support: CVE Lite CLI is built to let teams explicitly sync advisory data and then scan locally, instead of forcing every environment to depend on runtime outbound vulnerability API access.
|
|
249
325
|
|
|
@@ -338,7 +414,7 @@ So the practical model is: **local lockfile scan + advisory matching**. When mal
|
|
|
338
414
|
CVE Lite CLI is designed as a **local-first, metadata-only** scanner. Unlike traditional SaaS security platforms that require code uploads or heavy agent installations, this tool operates directly within the developer's environment. It focuses on the "moment of release"—providing a high-speed, low-noise assessment of the dependency tree by analyzing resolved versions in project lockfiles.
|
|
339
415
|
|
|
340
416
|
<p align="center">
|
|
341
|
-
<img src="https://
|
|
417
|
+
<img src="https://raw.githubusercontent.com/sonukapoor/cve-lite-cli/main/assets/diagram.png" alt="CVE Lite CLI Workflow" width="800"/>
|
|
342
418
|
</p>
|
|
343
419
|
|
|
344
420
|
### Workflow Specifications
|
|
@@ -354,7 +430,7 @@ CVE Lite CLI is designed as a **local-first, metadata-only** scanner. Unlike tra
|
|
|
354
430
|
- **fast, low-friction workflow**
|
|
355
431
|
Run it locally against a project without adopting a large security platform.
|
|
356
432
|
- **practical remediation guidance**
|
|
357
|
-
It does not stop at raw advisory output. It highlights top-priority fixes
|
|
433
|
+
It does not stop at raw advisory output. It highlights top-priority fixes, suggests a fix plan, and now generates package-manager-aware fix commands when confident upgrade targets exist.
|
|
358
434
|
- **direct vs transitive visibility**
|
|
359
435
|
The output makes it easier to see whether the risk comes from something you installed directly or from a nested package.
|
|
360
436
|
- **developer-first**
|
|
@@ -417,21 +493,11 @@ For transitive vulnerabilities, CVE Lite CLI can show the dependency path and, w
|
|
|
417
493
|
|
|
418
494
|
Structured JSON output makes it easier to integrate with scripts, logs, or pipeline artifacts.
|
|
419
495
|
|
|
420
|
-
### 7.
|
|
421
|
-
|
|
422
|
-
CVE Lite CLI supports SARIF (Static Analysis Results Interchange Format) output for security tooling and code-scanning workflows. SARIF is a standardized JSON-based format for security and code analysis results, which means CI systems, scanners, and code analysis platforms can all understand the same output without custom adapters. This is important because it makes CVE Lite CLI more than just a terminal tool: you can export findings into a format that fits modern DevSecOps workflows, archive results as build artifacts, and integrate vulnerability scans into automated release pipelines. For developers and teams, SARIF support helps security results travel cleanly from a local scan into CI/CD and other tooling, instead of being trapped in plain console output.
|
|
423
|
-
|
|
424
|
-
Example:
|
|
425
|
-
|
|
426
|
-
```bash
|
|
427
|
-
cve-lite /path/to/project --sarif --output reports/scan.sarif
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
### 8. CI-friendly behavior
|
|
496
|
+
### 7. CI-friendly behavior
|
|
431
497
|
|
|
432
498
|
The CLI can be used in CI/CD pipelines and can fail builds based on severity thresholds.
|
|
433
499
|
|
|
434
|
-
###
|
|
500
|
+
### 8. Offline advisory DB support
|
|
435
501
|
|
|
436
502
|
The CLI can sync the official OSV npm advisory dump into a local SQLite advisory database and scan against it later with zero runtime advisory API calls.
|
|
437
503
|
|
|
@@ -501,18 +567,55 @@ cve-lite . --offline
|
|
|
501
567
|
|
|
502
568
|
This repository also uses CVE Lite CLI in its own GitHub Actions workflow to scan itself as part of CI. See [`self-scan.yml`](https://github.com/sonukapoor/cve-lite-cli/blob/main/.github/workflows/self-scan.yml).
|
|
503
569
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
570
|
+
Use the reusable first-party GitHub Action in another repository:
|
|
571
|
+
|
|
572
|
+
```yaml
|
|
573
|
+
name: Dependency Scan
|
|
574
|
+
|
|
575
|
+
on:
|
|
576
|
+
pull_request:
|
|
577
|
+
push:
|
|
578
|
+
branches: [main]
|
|
579
|
+
|
|
580
|
+
jobs:
|
|
581
|
+
cve-lite:
|
|
582
|
+
runs-on: ubuntu-latest
|
|
583
|
+
steps:
|
|
584
|
+
- uses: actions/checkout@v4
|
|
585
|
+
- uses: sonukapoor/cve-lite-cli@v1.2.0
|
|
586
|
+
with:
|
|
587
|
+
verbose: "true"
|
|
588
|
+
fail-on: high
|
|
589
|
+
```
|
|
507
590
|
|
|
508
|
-
|
|
509
|
-
|
|
591
|
+
For an offline GitHub Actions workflow that refreshes the advisory DB first:
|
|
592
|
+
|
|
593
|
+
```yaml
|
|
594
|
+
name: Offline Dependency Scan
|
|
595
|
+
|
|
596
|
+
on:
|
|
597
|
+
pull_request:
|
|
598
|
+
|
|
599
|
+
jobs:
|
|
600
|
+
cve-lite:
|
|
601
|
+
runs-on: ubuntu-latest
|
|
602
|
+
steps:
|
|
603
|
+
- uses: actions/checkout@v4
|
|
604
|
+
- uses: sonukapoor/cve-lite-cli@v1.2.0
|
|
605
|
+
with:
|
|
606
|
+
sync-advisories: "true"
|
|
607
|
+
offline: "true"
|
|
608
|
+
offline-db: ./.cache/cve-lite/advisories.db
|
|
609
|
+
verbose: "true"
|
|
610
|
+
fail-on: high
|
|
510
611
|
```
|
|
511
612
|
|
|
512
|
-
|
|
613
|
+
For CI, we recommend using `--verbose` so build logs include the full fix plan, dependency paths, detailed table output, and suggested fix commands when a scan fails.
|
|
614
|
+
|
|
615
|
+
Use it as a release gate in CI:
|
|
513
616
|
|
|
514
617
|
```bash
|
|
515
|
-
cve-lite . --verbose --
|
|
618
|
+
cve-lite . --verbose --fail-on high
|
|
516
619
|
```
|
|
517
620
|
|
|
518
621
|
### Scripted automation
|
|
@@ -530,6 +633,86 @@ cve-lite advisories sync --output ./.cache/advisories.db
|
|
|
530
633
|
cve-lite . --offline-db ./.cache/advisories.db --json > cve-lite-report.json
|
|
531
634
|
```
|
|
532
635
|
|
|
636
|
+
## Recommended workflow patterns
|
|
637
|
+
|
|
638
|
+
CVE Lite CLI is most useful when teams make it part of an explicit workflow instead of relying on developers to remember a one-off command.
|
|
639
|
+
|
|
640
|
+
The recommended pattern is:
|
|
641
|
+
|
|
642
|
+
1. choose a scan command that matches your environment
|
|
643
|
+
2. wire it into scripts, hooks, CI, or scheduled refresh jobs
|
|
644
|
+
3. keep the behavior explicit so developers and security reviewers can see exactly when scans run and whether network access is involved
|
|
645
|
+
|
|
646
|
+
### Package scripts
|
|
647
|
+
|
|
648
|
+
Add a simple script to the consuming project so developers have a memorable command:
|
|
649
|
+
|
|
650
|
+
```json
|
|
651
|
+
{
|
|
652
|
+
"scripts": {
|
|
653
|
+
"security:scan": "cve-lite .",
|
|
654
|
+
"security:scan:offline": "cve-lite . --offline"
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
This is the best default for most teams because it is visible, easy to document, and easy to reuse in local development and CI.
|
|
660
|
+
|
|
661
|
+
### Opt-in postinstall usage
|
|
662
|
+
|
|
663
|
+
Some teams want dependency scanning to run immediately after packages are installed. CVE Lite CLI supports that workflow, but it is recommended as an explicit opt-in in the consuming project rather than hidden default behavior in the tool itself.
|
|
664
|
+
|
|
665
|
+
For example:
|
|
666
|
+
|
|
667
|
+
```json
|
|
668
|
+
{
|
|
669
|
+
"scripts": {
|
|
670
|
+
"postinstall": "cve-lite . --offline || true"
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
Why this is opt-in:
|
|
676
|
+
|
|
677
|
+
- install hooks should be visible to the team using them
|
|
678
|
+
- controlled environments often prefer offline scanning for install-time checks
|
|
679
|
+
- explicit project scripts are easier to review, tune, and disable than implicit package behavior
|
|
680
|
+
|
|
681
|
+
### Git hooks
|
|
682
|
+
|
|
683
|
+
For teams that want a lightweight local gate before code leaves a workstation, a git hook can be a good fit:
|
|
684
|
+
|
|
685
|
+
```bash
|
|
686
|
+
cve-lite . --fail-on high
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
This works well in `pre-push` or another team-approved hook if you want to catch high-severity dependency issues before changes are shared.
|
|
690
|
+
|
|
691
|
+
### CI pipelines
|
|
692
|
+
|
|
693
|
+
For CI, a strong baseline is:
|
|
694
|
+
|
|
695
|
+
```bash
|
|
696
|
+
cve-lite . --verbose --fail-on high
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
For controlled or restricted environments, sync the advisory DB separately and then scan offline:
|
|
700
|
+
|
|
701
|
+
```bash
|
|
702
|
+
cve-lite advisories sync --output ./.cache/advisories.db
|
|
703
|
+
cve-lite . --offline-db ./.cache/advisories.db --verbose --fail-on high
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
### Scheduled advisory DB refresh
|
|
707
|
+
|
|
708
|
+
If you use offline mode, keep the advisory DB fresh with a scheduler such as cron, CI, or an internal automation system:
|
|
709
|
+
|
|
710
|
+
```bash
|
|
711
|
+
cve-lite advisories sync --output /path/to/advisories.db
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
This keeps offline scans current without forcing every developer machine or build runner to make live advisory API calls during the scan itself.
|
|
715
|
+
|
|
533
716
|
## Comparison with other tools
|
|
534
717
|
|
|
535
718
|
CVE Lite CLI is not trying to be everything for everyone. It is designed to be one of the easiest and most actionable vulnerability scanners for JavaScript and TypeScript developers who want fast release-time checks without the cost and complexity of a full security platform.
|
|
@@ -653,7 +836,6 @@ CVE Lite CLI is evolving from a vulnerability scanner into a comprehensive remed
|
|
|
653
836
|
* **Deduplication Analysis:** Identify instances where multiple versions of the same vulnerable package exist and suggest a single version for consolidation.
|
|
654
837
|
|
|
655
838
|
### Phase 2: Ecosystem & Integration (Mid-Term)
|
|
656
|
-
* **Official GitHub Action:** Create a dedicated Action for one-line setup in CI/CD pipelines.
|
|
657
839
|
* **Expanded Lockfile Support:** Introduce parsers for emerging JS/TS ecosystems, including `bun.lockb`.
|
|
658
840
|
* **IDE Integration:** Develop a lightweight extension to highlight vulnerable packages directly within the code editor.
|
|
659
841
|
* **Workflow Integration Guidance:** Expand official workflow patterns for local scripts, hooks, CI, and offline developer adoption.
|
package/dist/cli/args.js
CHANGED
|
@@ -12,6 +12,10 @@ export function parseArgs(argv) {
|
|
|
12
12
|
options.help = true;
|
|
13
13
|
continue;
|
|
14
14
|
}
|
|
15
|
+
if (arg === "-v" || arg === "--version") {
|
|
16
|
+
options.version = true;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
15
19
|
if (arg === "--output") {
|
|
16
20
|
options.output = argv[++i];
|
|
17
21
|
continue;
|
|
@@ -33,6 +37,10 @@ export function parseArgs(argv) {
|
|
|
33
37
|
options.help = true;
|
|
34
38
|
continue;
|
|
35
39
|
}
|
|
40
|
+
if (arg === "-v" || arg === "--version") {
|
|
41
|
+
options.version = true;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
36
44
|
if (arg === "--json") {
|
|
37
45
|
options.json = true;
|
|
38
46
|
continue;
|
package/dist/cli/help.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { chalk } from "../utils/chalk.js";
|
|
2
|
+
import { getCliVersion } from "../utils/version-info.js";
|
|
3
|
+
const CLI_VERSION = getCliVersion();
|
|
2
4
|
const CLI_BANNER = [
|
|
3
|
-
`${chalk.green(">_")} ${chalk.bold.whiteBright(
|
|
5
|
+
`${chalk.green(">_")} ${chalk.bold.whiteBright(`CVE Lite CLI (${CLI_VERSION})`)}`,
|
|
4
6
|
chalk.gray("────────────────────────────────"),
|
|
5
7
|
`${chalk.green("✔")} Scan dependencies`,
|
|
6
8
|
`${chalk.green("✔")} Highlight critical issues`,
|
|
@@ -21,6 +23,8 @@ export function printHelp() {
|
|
|
21
23
|
"",
|
|
22
24
|
"Fast local-first CVE scanner for JS/TS projects using lockfiles + OSV",
|
|
23
25
|
"",
|
|
26
|
+
`Version: ${CLI_VERSION}`,
|
|
27
|
+
"",
|
|
24
28
|
"Usage:",
|
|
25
29
|
" cve-lite [projectPath] [options]",
|
|
26
30
|
" cve-lite advisories sync [options]",
|
|
@@ -42,6 +46,7 @@ export function printHelp() {
|
|
|
42
46
|
"Advisory sync options:",
|
|
43
47
|
" --output <path> Write the local advisory database to this path",
|
|
44
48
|
"",
|
|
49
|
+
" -v, --version Show the CLI version",
|
|
45
50
|
" -h, --help Show this help message"
|
|
46
51
|
];
|
|
47
52
|
console.log(lines.join("\n"));
|
package/dist/index.js
CHANGED
|
@@ -10,161 +10,173 @@ import { normalizeSeverity } from "./osv/severity.js";
|
|
|
10
10
|
import { severityOrder } from "./constants.js";
|
|
11
11
|
import { chalk } from "./utils/chalk.js";
|
|
12
12
|
import { createSpinner } from "./output/spinner.js";
|
|
13
|
+
import { buildSuggestedFixCommandPlan } from "./remediation/fix-commands.js";
|
|
14
|
+
import { getCliVersion } from "./utils/version-info.js";
|
|
13
15
|
import { logInfo, logWarn, printCacheSummary, serializeFinding } from "./output/formatters.js";
|
|
14
|
-
import { printSummary, printActionSummary, printPriorityFixes, printFixPlan, printCoverage, printSkippedDependencies, printGroupSummary, printTable, printPathHints, printFinalStatus, printCompactOutput } from "./output/printers.js";
|
|
16
|
+
import { printSummary, printActionSummary, printPriorityFixes, printFixPlan, printSuggestedFixCommands, printCoverage, printSkippedDependencies, printGroupSummary, printTable, printPathHints, printFinalStatus, printCompactOutput } from "./output/printers.js";
|
|
15
17
|
const { command, options, projectArg } = parseArgs(process.argv.slice(2));
|
|
18
|
+
const cliVersion = getCliVersion();
|
|
16
19
|
if (options.help) {
|
|
17
20
|
printHelp();
|
|
18
21
|
process.exit(0);
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
outputPath: options.output,
|
|
32
|
-
onProgress: event => {
|
|
33
|
-
if (event.phase === "complete") {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (usePlainProgressLogs) {
|
|
37
|
-
console.log(event.message);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
spinner.update(event.message);
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
if (usePlainProgressLogs) {
|
|
44
|
-
console.log(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
23
|
+
else if (options.version) {
|
|
24
|
+
printBanner();
|
|
25
|
+
process.exit(0);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const projectPath = path.resolve(projectArg || ".");
|
|
29
|
+
const batchSize = Number(options.batchSize || 100);
|
|
30
|
+
const searchDepth = Math.max(0, Number(options.searchDepth || 4));
|
|
31
|
+
async function main() {
|
|
32
|
+
if (!options.json) {
|
|
33
|
+
printBanner();
|
|
45
34
|
}
|
|
46
|
-
|
|
47
|
-
spinner
|
|
35
|
+
if (command === "advisories-sync") {
|
|
36
|
+
const spinner = createSpinner("Preparing advisory sync...", options);
|
|
37
|
+
const usePlainProgressLogs = !process.stdout.isTTY || !!options.json;
|
|
38
|
+
const result = await syncOsvAdvisories({
|
|
39
|
+
outputPath: options.output,
|
|
40
|
+
onProgress: event => {
|
|
41
|
+
if (event.phase === "complete") {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (usePlainProgressLogs) {
|
|
45
|
+
console.log(event.message);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
spinner.update(event.message);
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
if (usePlainProgressLogs) {
|
|
52
|
+
console.log(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
spinner.succeed(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
56
|
+
}
|
|
57
|
+
console.log(`${chalk.gray("Advisory database:")} synced ${result.advisoryCount} record${result.advisoryCount === 1 ? "" : "s"} to ${chalk.cyan(result.dbPath)}`);
|
|
58
|
+
process.exit(0);
|
|
59
|
+
return;
|
|
48
60
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if ((options.offline || options.offlineDb) && options.osvUrl) {
|
|
54
|
-
throw new Error("--offline/--offline-db cannot be used with --osv-url");
|
|
55
|
-
}
|
|
56
|
-
if (options.osvUrl) {
|
|
57
|
-
try {
|
|
58
|
-
new URL(options.osvUrl);
|
|
61
|
+
if ((options.offline || options.offlineDb) && options.osvUrl) {
|
|
62
|
+
throw new Error("--offline/--offline-db cannot be used with --osv-url");
|
|
59
63
|
}
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
if (options.osvUrl) {
|
|
65
|
+
try {
|
|
66
|
+
new URL(options.osvUrl);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
throw new Error(`Invalid value for --osv-url: ${options.osvUrl}`);
|
|
70
|
+
}
|
|
62
71
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
let advisorySourceLine;
|
|
73
|
+
let advisoryDbFreshnessLine = null;
|
|
74
|
+
let advisoryDbWarning = null;
|
|
75
|
+
try {
|
|
76
|
+
const advisorySource = createAdvisorySource({
|
|
77
|
+
osvUrl: options.osvUrl,
|
|
78
|
+
offline: options.offline,
|
|
79
|
+
offlineDb: options.offlineDb,
|
|
80
|
+
});
|
|
81
|
+
advisorySourceLine = advisorySource.sourceLabel;
|
|
82
|
+
if (advisorySource.offline) {
|
|
83
|
+
const metadata = advisorySource.advisoryDbMetadata;
|
|
84
|
+
advisoryDbFreshnessLine = formatAdvisoryDbFreshness(metadata?.lastSyncAt ?? null);
|
|
85
|
+
if (advisorySource.advisoryDbIsStale) {
|
|
86
|
+
advisoryDbWarning = metadata?.lastSyncAt
|
|
87
|
+
? "The local advisory DB appears stale. Re-run `cve-lite advisories sync` to refresh it."
|
|
88
|
+
: "The local advisory DB has no recorded sync timestamp. Re-run `cve-lite advisories sync` to refresh it.";
|
|
89
|
+
}
|
|
81
90
|
}
|
|
91
|
+
advisorySource.cleanup();
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (options.offline || options.offlineDb) {
|
|
95
|
+
throw new Error(`Offline advisory database is not available: ${error instanceof Error ? error.message : String(error)}`);
|
|
96
|
+
}
|
|
97
|
+
throw error;
|
|
82
98
|
}
|
|
83
|
-
advisorySource.cleanup();
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
99
|
if (options.offline || options.offlineDb) {
|
|
87
|
-
|
|
100
|
+
console.log(chalk.gray("Offline mode:") + " " + chalk.yellow("enabled") + " " + chalk.gray("(no external advisory calls will be made)"));
|
|
88
101
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
console.log(chalk.gray("Offline mode:") + " " + chalk.yellow("enabled") + " " + chalk.gray("(no external advisory calls will be made)"));
|
|
93
|
-
}
|
|
94
|
-
console.log(`${chalk.gray("Advisory source:")} ${formatAdvisorySourceLine(advisorySourceLine)}`);
|
|
95
|
-
if (advisoryDbFreshnessLine) {
|
|
96
|
-
console.log(`${chalk.gray("Advisory DB freshness:")} ${advisoryDbFreshnessLine}`);
|
|
97
|
-
}
|
|
98
|
-
if (advisoryDbWarning) {
|
|
99
|
-
logWarn(advisoryDbWarning, options);
|
|
100
|
-
}
|
|
101
|
-
const scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
102
|
-
const packages = scanInput.packages;
|
|
103
|
-
logInfo(`Parsed ${packages.length} package${packages.length === 1 ? "" : "s"} from ${scanInput.source}${scanInput.filePath ? ` (${path.relative(projectPath, scanInput.filePath) || path.basename(scanInput.filePath)})` : ""}`, options);
|
|
104
|
-
printCacheSummary(options.cacheDir, options);
|
|
105
|
-
if (scanInput.warnings.length > 0) {
|
|
106
|
-
for (const warning of scanInput.warnings) {
|
|
107
|
-
logWarn(warning, options);
|
|
102
|
+
console.log(`${chalk.gray("Advisory source:")} ${formatAdvisorySourceLine(advisorySourceLine)}`);
|
|
103
|
+
if (advisoryDbFreshnessLine) {
|
|
104
|
+
console.log(`${chalk.gray("Advisory DB freshness:")} ${advisoryDbFreshnessLine}`);
|
|
108
105
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
112
|
-
process.exit(0);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const findings = await scanPackages(packages, batchSize, options);
|
|
116
|
-
const sorted = findings.sort((a, b) => severityOrder[b.severity] - severityOrder[a.severity]);
|
|
117
|
-
const coverage = buildCoverageNotes(scanInput, !!options.offline || !!options.offlineDb);
|
|
118
|
-
const minSeverity = normalizeSeverity(options.minSeverity || "medium");
|
|
119
|
-
const tableFindings = options.all ? sorted : sorted.filter(f => severityOrder[f.severity] >= severityOrder[minSeverity]);
|
|
120
|
-
if (options.json) {
|
|
121
|
-
console.log(JSON.stringify({
|
|
122
|
-
projectPath,
|
|
123
|
-
mode: scanInput.mode,
|
|
124
|
-
source: scanInput.source,
|
|
125
|
-
packageCount: packages.length,
|
|
126
|
-
findingCount: sorted.length,
|
|
127
|
-
notes: [...scanInput.notes, ...coverage],
|
|
128
|
-
warnings: scanInput.warnings,
|
|
129
|
-
skippedDependencies: scanInput.skippedDependencies,
|
|
130
|
-
findings: sorted.map(serializeFinding)
|
|
131
|
-
}, null, 2));
|
|
132
|
-
}
|
|
133
|
-
else if (options.verbose) {
|
|
134
|
-
// Verbose output - show all details
|
|
135
|
-
printSummary(sorted, packages.length, scanInput);
|
|
136
|
-
printActionSummary(sorted);
|
|
137
|
-
printPriorityFixes(sorted);
|
|
138
|
-
printFixPlan(sorted);
|
|
139
|
-
printCoverage([...scanInput.notes, ...coverage]);
|
|
140
|
-
if (scanInput.skippedDependencies.length > 0) {
|
|
141
|
-
printSkippedDependencies(scanInput.skippedDependencies);
|
|
106
|
+
if (advisoryDbWarning) {
|
|
107
|
+
logWarn(advisoryDbWarning, options);
|
|
142
108
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
109
|
+
const scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
110
|
+
const packages = scanInput.packages;
|
|
111
|
+
logInfo(`Parsed ${packages.length} package${packages.length === 1 ? "" : "s"} from ${scanInput.source}${scanInput.filePath ? ` (${path.relative(projectPath, scanInput.filePath) || path.basename(scanInput.filePath)})` : ""}`, options);
|
|
112
|
+
printCacheSummary(options.cacheDir, options);
|
|
113
|
+
if (scanInput.warnings.length > 0) {
|
|
114
|
+
for (const warning of scanInput.warnings) {
|
|
115
|
+
logWarn(warning, options);
|
|
148
116
|
}
|
|
149
|
-
|
|
150
|
-
|
|
117
|
+
}
|
|
118
|
+
if (packages.length === 0) {
|
|
119
|
+
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
120
|
+
process.exit(0);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const findings = await scanPackages(packages, batchSize, options);
|
|
124
|
+
const sorted = findings.sort((a, b) => severityOrder[b.severity] - severityOrder[a.severity]);
|
|
125
|
+
const coverage = buildCoverageNotes(scanInput, !!options.offline || !!options.offlineDb);
|
|
126
|
+
const minSeverity = normalizeSeverity(options.minSeverity || "medium");
|
|
127
|
+
const tableFindings = options.all ? sorted : sorted.filter(f => severityOrder[f.severity] >= severityOrder[minSeverity]);
|
|
128
|
+
const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, scanInput);
|
|
129
|
+
if (options.json) {
|
|
130
|
+
console.log(JSON.stringify({
|
|
131
|
+
projectPath,
|
|
132
|
+
mode: scanInput.mode,
|
|
133
|
+
source: scanInput.source,
|
|
134
|
+
packageCount: packages.length,
|
|
135
|
+
findingCount: sorted.length,
|
|
136
|
+
suggestedFixCommands,
|
|
137
|
+
notes: [...scanInput.notes, ...coverage],
|
|
138
|
+
warnings: scanInput.warnings,
|
|
139
|
+
skippedDependencies: scanInput.skippedDependencies,
|
|
140
|
+
findings: sorted.map(serializeFinding)
|
|
141
|
+
}, null, 2));
|
|
142
|
+
}
|
|
143
|
+
else if (options.verbose) {
|
|
144
|
+
// Verbose output - show all details
|
|
145
|
+
printSummary(sorted, packages.length, scanInput);
|
|
146
|
+
printActionSummary(sorted);
|
|
147
|
+
printPriorityFixes(sorted);
|
|
148
|
+
printSuggestedFixCommands(sorted, scanInput);
|
|
149
|
+
printFixPlan(sorted);
|
|
150
|
+
printCoverage([...scanInput.notes, ...coverage]);
|
|
151
|
+
if (scanInput.skippedDependencies.length > 0) {
|
|
152
|
+
printSkippedDependencies(scanInput.skippedDependencies);
|
|
153
|
+
}
|
|
154
|
+
if (sorted.length > 0) {
|
|
155
|
+
printGroupSummary(sorted);
|
|
156
|
+
if (tableFindings.length > 0) {
|
|
157
|
+
printTable(tableFindings, options.all ? null : minSeverity);
|
|
158
|
+
printPathHints(tableFindings);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
logInfo(`No findings met the table threshold of ${minSeverity}. Re-run with --all to show everything.`, options);
|
|
162
|
+
}
|
|
151
163
|
}
|
|
164
|
+
printFinalStatus(sorted);
|
|
152
165
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
166
|
+
else {
|
|
167
|
+
// Simplified output - cleaner, focused view
|
|
168
|
+
printCompactOutput(sorted, scanInput);
|
|
169
|
+
}
|
|
170
|
+
const failLevel = normalizeSeverity(options.failOn);
|
|
171
|
+
const shouldFail = sorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
172
|
+
process.exit(shouldFail ? 1 : 0);
|
|
173
|
+
return;
|
|
158
174
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
175
|
+
main().catch((error) => {
|
|
176
|
+
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
177
|
+
process.exit(1);
|
|
178
|
+
});
|
|
163
179
|
}
|
|
164
|
-
main().catch((error) => {
|
|
165
|
-
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
166
|
-
process.exit(1);
|
|
167
|
-
});
|
|
168
180
|
function formatAdvisorySourceLine(sourceLabel) {
|
|
169
181
|
const match = sourceLabel.match(/^(.*) \((.*)\)$/);
|
|
170
182
|
if (!match) {
|
package/dist/output/printers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { chalk, stripAnsi } from "../utils/chalk.js";
|
|
2
2
|
import { severityOrder } from "../constants.js";
|
|
3
|
+
import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
|
|
3
4
|
import { formatSeverityLabel, formatRelationshipLabel, getPrimaryParent, getRecommendedAction, summarizeRisk, summarizeNextAction } from "./formatters.js";
|
|
4
5
|
export function printSummary(findings, packageCount, scanInput) {
|
|
5
6
|
if (findings.length === 0) {
|
|
@@ -57,7 +58,7 @@ export function printPriorityFixes(findings) {
|
|
|
57
58
|
});
|
|
58
59
|
const top = scored.slice(0, 5);
|
|
59
60
|
console.log("");
|
|
60
|
-
console.log(chalk.bold.magenta("Top priority fixes"));
|
|
61
|
+
console.log(chalk.bold.magenta("🚀 Top priority fixes"));
|
|
61
62
|
for (const finding of top) {
|
|
62
63
|
console.log(`- ${chalk.whiteBright(finding.pkg.name)}@${chalk.white(finding.pkg.version)} (${formatSeverityLabel(finding.severity)}, ${formatRelationshipLabel(finding.relationship)})`);
|
|
63
64
|
console.log(` Risk: ${summarizeRisk(finding)}`);
|
|
@@ -77,7 +78,7 @@ export function printFixPlan(findings) {
|
|
|
77
78
|
const transitiveUrgent = findings.filter(f => f.relationship === "transitive" && (f.severity === "critical" || f.severity === "high"));
|
|
78
79
|
const directMedium = findings.filter(f => f.relationship === "direct" && f.severity === "medium");
|
|
79
80
|
console.log("");
|
|
80
|
-
console.log(chalk.bold.green("Suggested fix plan"));
|
|
81
|
+
console.log(chalk.bold.green("📋 Suggested fix plan"));
|
|
81
82
|
if (directUrgent.length > 0) {
|
|
82
83
|
console.log(chalk.green("1) Upgrade these direct critical/high dependencies first:"));
|
|
83
84
|
for (const finding of directUrgent.slice(0, 5)) {
|
|
@@ -114,6 +115,31 @@ export function printFixPlan(findings) {
|
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
}
|
|
118
|
+
export function printSuggestedFixCommands(findings, scanInput) {
|
|
119
|
+
const plan = buildSuggestedFixCommandPlan(findings, scanInput);
|
|
120
|
+
if (!plan)
|
|
121
|
+
return;
|
|
122
|
+
if (!plan.command && plan.skipped.length === 0)
|
|
123
|
+
return;
|
|
124
|
+
console.log("");
|
|
125
|
+
console.log(chalk.bold.green("🛠 Suggested fix command"));
|
|
126
|
+
console.log(`${chalk.gray("Detected package manager:")} ${chalk.cyan(plan.packageManager)} ${chalk.gray(`(${plan.sourceLabel})`)}`);
|
|
127
|
+
if (plan.command) {
|
|
128
|
+
console.log(chalk.cyan(plan.command));
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
console.log(chalk.gray("No confident package-manager command could be generated for the urgent findings."));
|
|
132
|
+
}
|
|
133
|
+
if (plan.skipped.length > 0) {
|
|
134
|
+
console.log(chalk.gray("Not included automatically:"));
|
|
135
|
+
for (const skipped of plan.skipped.slice(0, 5)) {
|
|
136
|
+
console.log(`- ${skipped.package}@${skipped.version}: ${skipped.reason}`);
|
|
137
|
+
}
|
|
138
|
+
if (plan.skipped.length > 5) {
|
|
139
|
+
console.log(`- ...and ${plan.skipped.length - 5} more`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
117
143
|
export function printCoverage(notes) {
|
|
118
144
|
if (notes.length === 0)
|
|
119
145
|
return;
|
|
@@ -224,7 +250,7 @@ function truncate(value, width) {
|
|
|
224
250
|
return value;
|
|
225
251
|
return plain.slice(0, Math.max(0, width - 1)) + "…";
|
|
226
252
|
}
|
|
227
|
-
export function printCompactOutput(findings) {
|
|
253
|
+
export function printCompactOutput(findings, scanInput) {
|
|
228
254
|
console.log("");
|
|
229
255
|
if (findings.length === 0) {
|
|
230
256
|
console.log(chalk.greenBright("✔ Scan complete. No known vulnerabilities found."));
|
|
@@ -291,6 +317,16 @@ export function printCompactOutput(findings) {
|
|
|
291
317
|
}
|
|
292
318
|
console.log("");
|
|
293
319
|
}
|
|
320
|
+
if (scanInput) {
|
|
321
|
+
const plan = buildSuggestedFixCommandPlan(findings, scanInput);
|
|
322
|
+
if (plan?.command) {
|
|
323
|
+
console.log("────────────────────────────────");
|
|
324
|
+
console.log(chalk.bold("🛠 Suggested Fix Command"));
|
|
325
|
+
console.log("────────────────────────────────\n");
|
|
326
|
+
console.log(plan.command);
|
|
327
|
+
console.log("");
|
|
328
|
+
}
|
|
329
|
+
}
|
|
294
330
|
// Summary
|
|
295
331
|
console.log("────────────────────────────────");
|
|
296
332
|
console.log("Summary");
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { severityOrder } from "../constants.js";
|
|
2
|
+
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
3
|
+
export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
4
|
+
const packageManager = inferPackageManager(scanInput);
|
|
5
|
+
if (!packageManager)
|
|
6
|
+
return null;
|
|
7
|
+
const urgentFindings = [...findings]
|
|
8
|
+
.filter(f => f.severity === "critical" || f.severity === "high")
|
|
9
|
+
.sort((a, b) => {
|
|
10
|
+
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
11
|
+
if (sevDelta !== 0)
|
|
12
|
+
return sevDelta;
|
|
13
|
+
const relScore = (finding) => finding.relationship === "direct" ? 1 : 0;
|
|
14
|
+
const relDelta = relScore(b) - relScore(a);
|
|
15
|
+
if (relDelta !== 0)
|
|
16
|
+
return relDelta;
|
|
17
|
+
return a.pkg.name.localeCompare(b.pkg.name);
|
|
18
|
+
});
|
|
19
|
+
const targetsByPackage = new Map();
|
|
20
|
+
const skippedByKey = new Map();
|
|
21
|
+
for (const finding of urgentFindings) {
|
|
22
|
+
if (finding.relationship === "direct") {
|
|
23
|
+
if (finding.firstFixedVersion) {
|
|
24
|
+
upsertTarget(targetsByPackage, {
|
|
25
|
+
package: finding.pkg.name,
|
|
26
|
+
targetVersion: finding.firstFixedVersion,
|
|
27
|
+
kind: "direct",
|
|
28
|
+
reason: `Direct upgrade target for ${finding.pkg.name}@${finding.pkg.version}`,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
33
|
+
package: finding.pkg.name,
|
|
34
|
+
version: finding.pkg.version,
|
|
35
|
+
relationship: finding.relationship,
|
|
36
|
+
reason: "No safe upgrade target is known for this urgent direct dependency.",
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (finding.relationship === "transitive" && finding.recommendedParentUpgrade) {
|
|
42
|
+
upsertTarget(targetsByPackage, {
|
|
43
|
+
package: finding.recommendedParentUpgrade.package,
|
|
44
|
+
targetVersion: finding.recommendedParentUpgrade.targetVersion,
|
|
45
|
+
kind: "parent-upgrade",
|
|
46
|
+
reason: `Parent upgrade for vulnerable ${finding.pkg.name}@${finding.pkg.version}`,
|
|
47
|
+
});
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
51
|
+
package: finding.pkg.name,
|
|
52
|
+
version: finding.pkg.version,
|
|
53
|
+
relationship: finding.relationship,
|
|
54
|
+
reason: finding.relationship === "transitive"
|
|
55
|
+
? "No specific parent upgrade target was found for this urgent transitive issue."
|
|
56
|
+
: "No confident automatic fix command could be generated for this issue.",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const targets = [...targetsByPackage.values()].sort((a, b) => {
|
|
60
|
+
const kindScore = (target) => target.kind === "direct" ? 1 : 0;
|
|
61
|
+
const kindDelta = kindScore(b) - kindScore(a);
|
|
62
|
+
if (kindDelta !== 0)
|
|
63
|
+
return kindDelta;
|
|
64
|
+
return a.package.localeCompare(b.package);
|
|
65
|
+
});
|
|
66
|
+
const skipped = [...skippedByKey.values()].sort((a, b) => a.package.localeCompare(b.package));
|
|
67
|
+
const command = targets.length > 0
|
|
68
|
+
? `${commandPrefix(packageManager)} ${targets.map(target => `${target.package}@${target.targetVersion}`).join(" ")}`
|
|
69
|
+
: null;
|
|
70
|
+
return {
|
|
71
|
+
packageManager,
|
|
72
|
+
sourceLabel: packageManagerSourceLabel(scanInput),
|
|
73
|
+
command,
|
|
74
|
+
targets,
|
|
75
|
+
skipped,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function inferPackageManager(scanInput) {
|
|
79
|
+
if (scanInput.source === "package-lock")
|
|
80
|
+
return "npm";
|
|
81
|
+
if (scanInput.source === "pnpm-lock")
|
|
82
|
+
return "pnpm";
|
|
83
|
+
if (scanInput.source === "yarn-lock")
|
|
84
|
+
return "yarn";
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
function commandPrefix(packageManager) {
|
|
88
|
+
if (packageManager === "npm")
|
|
89
|
+
return "npm install";
|
|
90
|
+
if (packageManager === "pnpm")
|
|
91
|
+
return "pnpm add";
|
|
92
|
+
return "yarn add";
|
|
93
|
+
}
|
|
94
|
+
function packageManagerSourceLabel(scanInput) {
|
|
95
|
+
if (scanInput.filePath) {
|
|
96
|
+
return scanInput.filePath.split(/[/\\]/).pop() ?? scanInput.source;
|
|
97
|
+
}
|
|
98
|
+
if (scanInput.source === "package-lock")
|
|
99
|
+
return "package-lock.json";
|
|
100
|
+
if (scanInput.source === "pnpm-lock")
|
|
101
|
+
return "pnpm-lock.yaml";
|
|
102
|
+
if (scanInput.source === "yarn-lock")
|
|
103
|
+
return "yarn.lock";
|
|
104
|
+
return scanInput.source;
|
|
105
|
+
}
|
|
106
|
+
function upsertTarget(targetsByPackage, next) {
|
|
107
|
+
const existing = targetsByPackage.get(next.package);
|
|
108
|
+
if (!existing) {
|
|
109
|
+
targetsByPackage.set(next.package, next);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (looksLikeVersion(existing.targetVersion) && looksLikeVersion(next.targetVersion)) {
|
|
113
|
+
if (compareVersions(next.targetVersion, existing.targetVersion) > 0) {
|
|
114
|
+
targetsByPackage.set(next.package, next);
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (next.kind === "direct" && existing.kind !== "direct") {
|
|
119
|
+
targetsByPackage.set(next.package, next);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
export function getCliVersion() {
|
|
3
|
+
try {
|
|
4
|
+
const packageJsonPath = new URL("../../package.json", import.meta.url);
|
|
5
|
+
const raw = fs.readFileSync(packageJsonPath, "utf8");
|
|
6
|
+
const parsed = JSON.parse(raw);
|
|
7
|
+
return parsed.version ?? "0.0.0";
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return "0.0.0";
|
|
11
|
+
}
|
|
12
|
+
}
|