cve-lite-cli 1.0.6 → 1.1.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 +202 -10
- package/dist/advisory/local-advisory-source.js +21 -0
- package/dist/advisory/local-db.js +239 -0
- package/dist/advisory/osv-sync.js +169 -0
- package/dist/cli/args.js +38 -1
- package/dist/cli/help.js +9 -3
- package/dist/index.js +107 -14
- package/dist/osv/cache.js +12 -4
- package/dist/output/formatters.js +3 -2
- package/dist/output/spinner.js +1 -0
- package/dist/scanner.js +112 -12
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
[](https://www.npmjs.com/package/cve-lite-cli)
|
|
3
|
+
[](https://www.npmjs.com/package/cve-lite-cli)
|
|
4
|
+
[](https://github.com/sonukapoor/cve-lite-cli/actions)
|
|
5
|
+
[](https://github.com/sonukapoor/cve-lite-cli/blob/main/LICENSE)
|
|
6
|
+
|
|
1
7
|
<div align="center">
|
|
2
8
|
<img src="https://github.com/sonukapoor/cve-lite-cli/blob/main/assets/logo-with-title.png" alt="CVE Lite CLI" width="320"/>
|
|
3
9
|
|
|
4
10
|
<h1>CVE Lite CLI</h1>
|
|
5
|
-
<p>Fast, developer-friendly vulnerability scanning for JavaScript and TypeScript projects.</p>
|
|
11
|
+
<p>Fast, developer-friendly vulnerability scanning for JavaScript and TypeScript projects, with offline support for restricted environments.</p>
|
|
6
12
|
|
|
7
13
|
<strong>Scan. Prioritize. Fix.</strong>
|
|
8
14
|
|
|
@@ -21,6 +27,49 @@
|
|
|
21
27
|
|
|
22
28
|
**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.
|
|
23
29
|
|
|
30
|
+
It is designed to be:
|
|
31
|
+
|
|
32
|
+
- developer-friendly in day-to-day workflows
|
|
33
|
+
- local-first and transparent about network behavior
|
|
34
|
+
- usable in enterprise and restricted-network environments
|
|
35
|
+
- capable of zero-runtime-network scans through a local advisory database
|
|
36
|
+
|
|
37
|
+
## New: Offline advisory DB support
|
|
38
|
+
|
|
39
|
+
CVE Lite CLI now supports a local advisory database workflow for teams that cannot allow runtime outbound advisory API calls.
|
|
40
|
+
|
|
41
|
+
That means you can:
|
|
42
|
+
|
|
43
|
+
- sync advisory data ahead of time
|
|
44
|
+
- scan projects fully offline
|
|
45
|
+
- use the tool in restricted, enterprise, or air-gapped environments more easily
|
|
46
|
+
|
|
47
|
+
Example offline workflow:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Build the local advisory database
|
|
51
|
+
cve-lite advisories sync
|
|
52
|
+
|
|
53
|
+
# Scan using the default local advisory DB
|
|
54
|
+
cve-lite /path/to/project --offline
|
|
55
|
+
|
|
56
|
+
# Or scan using a specific local advisory DB file
|
|
57
|
+
cve-lite /path/to/project --offline-db /path/to/advisories.db
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Why offline mode matters
|
|
61
|
+
|
|
62
|
+
For many teams, “works locally” is not enough. They also need a scanner that can fit into environments where runtime outbound calls are restricted, reviewed closely, or disallowed entirely.
|
|
63
|
+
|
|
64
|
+
Offline advisory DB support makes CVE Lite CLI more practical for:
|
|
65
|
+
|
|
66
|
+
- enterprise environments with strict network controls
|
|
67
|
+
- regulated teams that need explicit advisory data handling
|
|
68
|
+
- internal CI systems that should not depend on public runtime API access
|
|
69
|
+
- air-gapped or partially connected workflows
|
|
70
|
+
|
|
71
|
+
This is one of the most important differentiators in the project today because it improves both trust and adoptability, not just convenience.
|
|
72
|
+
|
|
24
73
|
## Quick start
|
|
25
74
|
|
|
26
75
|
Install globally:
|
|
@@ -68,6 +117,43 @@ cve-lite /path/to/project --sarif --output reports/scan.sarif
|
|
|
68
117
|
|
|
69
118
|
# Use a custom advisory endpoint
|
|
70
119
|
cve-lite /path/to/project --osv-url https://security.company.internal/osv
|
|
120
|
+
|
|
121
|
+
# Build the local advisory DB for offline scans
|
|
122
|
+
cve-lite advisories sync
|
|
123
|
+
|
|
124
|
+
# Scan with zero runtime advisory API calls
|
|
125
|
+
cve-lite /path/to/project --offline
|
|
126
|
+
|
|
127
|
+
# Use a specific local advisory DB file
|
|
128
|
+
cve-lite /path/to/project --offline-db /path/to/advisories.db
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Workflow modes
|
|
132
|
+
|
|
133
|
+
CVE Lite CLI now supports three clear advisory workflows:
|
|
134
|
+
|
|
135
|
+
### 1. Standard online scan
|
|
136
|
+
|
|
137
|
+
Use the default OSV-backed mode when runtime advisory API access is acceptable:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
cve-lite /path/to/project
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### 2. Advisory DB sync
|
|
144
|
+
|
|
145
|
+
Build or refresh the local advisory database ahead of time:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
cve-lite advisories sync
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 3. Offline local DB scan
|
|
152
|
+
|
|
153
|
+
Scan against the local advisory DB with zero runtime advisory API calls:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
cve-lite /path/to/project --offline
|
|
71
157
|
```
|
|
72
158
|
|
|
73
159
|
## What it looks like
|
|
@@ -139,6 +225,7 @@ The project emphasizes:
|
|
|
139
225
|
- direct vs transitive visibility
|
|
140
226
|
- top-priority fixes and a suggested remediation plan
|
|
141
227
|
- JSON and SARIF output for automation
|
|
228
|
+
- offline scanning through a local advisory database
|
|
142
229
|
- configurable advisory endpoint support via `--osv-url` for internal proxies or mirrors
|
|
143
230
|
- a small, reviewable runtime footprint
|
|
144
231
|
|
|
@@ -158,21 +245,77 @@ Its role is narrower and workflow-focused:
|
|
|
158
245
|
|
|
159
246
|
This section is here to make the scope clear. CVE Lite CLI aims to complement the broader security ecosystem by being a practical, low-friction option for JS/TS dependency checks close to release time.
|
|
160
247
|
|
|
248
|
+
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
|
+
|
|
161
250
|
## Network behavior and privacy
|
|
162
251
|
|
|
163
|
-
CVE Lite CLI is a local-first scanner. It parses dependency information locally, uses local caching to reduce repeated lookups, and in standard mode queries OSV for advisory data needed for matching.
|
|
252
|
+
CVE Lite CLI is a local-first scanner. It parses dependency information locally, uses local caching to reduce repeated lookups, and in standard mode queries OSV for advisory data needed for matching. It also now supports a local advisory database workflow for offline scans with zero runtime advisory API calls.
|
|
164
253
|
|
|
165
254
|
It does not require a hosted account, cloud dashboard, or source code upload.
|
|
166
255
|
|
|
167
256
|
For the full explanation, see [Network Behavior and Privacy](https://github.com/sonukapoor/cve-lite-cli/blob/main/src/docs/network-and-privacy.md).
|
|
168
257
|
|
|
169
|
-
###
|
|
258
|
+
### Offline workflow
|
|
259
|
+
|
|
260
|
+
For teams in controlled or restricted environments, the intended model is:
|
|
170
261
|
|
|
171
|
-
|
|
262
|
+
1. sync advisory data into a local database
|
|
263
|
+
2. distribute that database as needed
|
|
264
|
+
3. scan projects using the local DB instead of runtime OSV API calls
|
|
172
265
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
266
|
+
Sync the local advisory database:
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
cve-lite advisories sync
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
In our local benchmark on the same machine, syncing the OSV npm dump with about `217,065` advisory records improved from `87.53s` to `8.84s` after bulk SQLite ingestion optimizations, or about `9.9x` faster end-to-end. Results will vary by machine and network conditions.
|
|
273
|
+
|
|
274
|
+
Write the advisory database to a specific path:
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
cve-lite advisories sync --output /path/to/advisories.db
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Scan using the default local advisory DB:
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
cve-lite . --offline
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Scan using an explicit local advisory DB file:
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
cve-lite . --offline-db /path/to/advisories.db
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Keep the local advisory DB fresh with a scheduled job when needed. For example, teams can run a cron job, CI job, or other scheduler to refresh the advisory DB periodically:
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
cve-lite advisories sync --output /path/to/advisories.db
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
That helps ensure offline scans continue using current advisory data without requiring developers to remember to refresh the DB manually every time.
|
|
299
|
+
|
|
300
|
+
Standard online mode remains available when you want live OSV-backed scans:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
cve-lite . --osv-url https://security.company.internal/osv
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Advisory DB freshness
|
|
307
|
+
|
|
308
|
+
The local advisory DB is only as current as the last successful sync.
|
|
309
|
+
|
|
310
|
+
Offline scans now report advisory DB freshness and warn when the local DB appears stale or is missing sync metadata.
|
|
311
|
+
|
|
312
|
+
The recommended model is:
|
|
313
|
+
|
|
314
|
+
- sync the advisory DB on a schedule using cron, CI, or another automation system
|
|
315
|
+
- distribute the refreshed DB where needed
|
|
316
|
+
- run offline scans against that updated DB
|
|
317
|
+
|
|
318
|
+
This helps keep offline scan results current without requiring developers to manually track advisory update cadence.
|
|
176
319
|
|
|
177
320
|
## Detecting malicious package incidents
|
|
178
321
|
|
|
@@ -203,6 +346,7 @@ CVE Lite CLI is designed as a **local-first, metadata-only** scanner. Unlike tra
|
|
|
203
346
|
* **Lockfile-Driven Accuracy:** By parsing `package-lock.json`, `pnpm-lock.yaml`, or `yarn.lock`, the tool avoids the "it works on my machine" discrepancy. It scans the *exact* dependency tree that will be deployed.
|
|
204
347
|
* **Intelligent Triage:** The Analysis engine utilizes the lockfile's graph structure to distinguish between dependencies you manage directly and those brought in by third-party packages (transitive). This allows for a "Fix the Root" strategy rather than chasing individual nested vulnerabilities.
|
|
205
348
|
* **Performance Optimization:** A local TTL (Time-To-Live) cache stores advisory results. This ensures that subsequent scans—common in iterative development or CI/CD retry loops—are near-instant and respect external API rate limits.
|
|
349
|
+
* **Offline-Capable Advisory Flow:** Advisory data can be synced into a local SQLite database and reused for offline scans with zero runtime advisory API calls.
|
|
206
350
|
* **Standards-Based Output:** Results are natively available in **SARIF (Static Analysis Results Interchange Format)** and **JSON**, ensuring compatibility with modern DevSecOps dashboards and IDE integrations.
|
|
207
351
|
|
|
208
352
|
## What makes it stand out
|
|
@@ -219,6 +363,10 @@ CVE Lite CLI is designed as a **local-first, metadata-only** scanner. Unlike tra
|
|
|
219
363
|
It is intended for developers and teams who want useful security checks without paying for a large commercial product.
|
|
220
364
|
- **local-first**
|
|
221
365
|
It reads your project locally and uses package/version matching against OSV advisories.
|
|
366
|
+
- **offline-capable**
|
|
367
|
+
It can sync and scan against a local advisory database for zero-runtime-network workflows.
|
|
368
|
+
- **enterprise-friendly network model**
|
|
369
|
+
Teams can control when advisory data is synced and where offline scans run, which is valuable in restricted environments.
|
|
222
370
|
- **release-focused**
|
|
223
371
|
It is especially useful before a release, in CI, or during final dependency cleanup.
|
|
224
372
|
|
|
@@ -283,15 +431,26 @@ cve-lite /path/to/project --sarif --output reports/scan.sarif
|
|
|
283
431
|
|
|
284
432
|
The CLI can be used in CI/CD pipelines and can fail builds based on severity thresholds.
|
|
285
433
|
|
|
286
|
-
### 9.
|
|
434
|
+
### 9. Offline advisory DB support
|
|
435
|
+
|
|
436
|
+
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
|
+
|
|
438
|
+
That makes it more practical for:
|
|
439
|
+
|
|
440
|
+
- enterprise environments
|
|
441
|
+
- restricted CI systems
|
|
442
|
+
- air-gapped workflows
|
|
443
|
+
- teams that want explicit local advisory control
|
|
444
|
+
|
|
445
|
+
### 10. Local cache
|
|
287
446
|
|
|
288
447
|
It caches advisory detail results locally so repeated scans are faster and make fewer repeated requests.
|
|
289
448
|
|
|
290
|
-
###
|
|
449
|
+
### 11. Clear final scan status
|
|
291
450
|
|
|
292
451
|
At the end of each run, CVE Lite CLI prints a short final status line so users immediately know whether the scan was clean or whether they should start with the priority fixes above.
|
|
293
452
|
|
|
294
|
-
###
|
|
453
|
+
### 12. Small runtime footprint
|
|
295
454
|
|
|
296
455
|
This project intentionally keeps runtime dependencies minimal to reduce attack surface and keep the tool easier to review.
|
|
297
456
|
|
|
@@ -302,6 +461,8 @@ CVE Lite CLI is intentionally designed with a very small dependency surface.
|
|
|
302
461
|
**Runtime dependencies**
|
|
303
462
|
- `yaml`
|
|
304
463
|
- `yarn-lockfile`
|
|
464
|
+
- `better-sqlite3`
|
|
465
|
+
- `fflate`
|
|
305
466
|
|
|
306
467
|
**Development dependencies**
|
|
307
468
|
- `@types/node`
|
|
@@ -320,6 +481,8 @@ CVE Lite CLI is a good fit for:
|
|
|
320
481
|
- teams that want a lightweight dependency scan in CI
|
|
321
482
|
- developers who want a second opinion alongside other tools
|
|
322
483
|
- OSS maintainers who need a practical scan before publishing
|
|
484
|
+
- teams that need offline or controlled-network dependency scanning
|
|
485
|
+
- security-conscious organizations that need clear advisory data control
|
|
323
486
|
|
|
324
487
|
## Supported workflows
|
|
325
488
|
|
|
@@ -327,6 +490,13 @@ CVE Lite CLI is a good fit for:
|
|
|
327
490
|
|
|
328
491
|
Run it before a release, during dependency cleanup, or after a major package upgrade.
|
|
329
492
|
|
|
493
|
+
For offline-capable local workflows:
|
|
494
|
+
|
|
495
|
+
```bash
|
|
496
|
+
cve-lite advisories sync
|
|
497
|
+
cve-lite . --offline
|
|
498
|
+
```
|
|
499
|
+
|
|
330
500
|
### CI/CD
|
|
331
501
|
|
|
332
502
|
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).
|
|
@@ -353,6 +523,13 @@ Use JSON output for custom reporting:
|
|
|
353
523
|
cve-lite . --json > cve-lite-report.json
|
|
354
524
|
```
|
|
355
525
|
|
|
526
|
+
Use an offline local advisory DB in controlled environments:
|
|
527
|
+
|
|
528
|
+
```bash
|
|
529
|
+
cve-lite advisories sync --output ./.cache/advisories.db
|
|
530
|
+
cve-lite . --offline-db ./.cache/advisories.db --json > cve-lite-report.json
|
|
531
|
+
```
|
|
532
|
+
|
|
356
533
|
## Comparison with other tools
|
|
357
534
|
|
|
358
535
|
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.
|
|
@@ -370,6 +547,7 @@ Compared with other tools in this space, CVE Lite CLI focuses on:
|
|
|
370
547
|
- support for **npm**, **pnpm**, and **Yarn** lockfiles
|
|
371
548
|
- **SARIF** and **JSON** output for CI and automation
|
|
372
549
|
- a **lightweight**, **security-conscious** dependency footprint
|
|
550
|
+
- **offline local advisory DB support** for controlled environments
|
|
373
551
|
- a **developer-friendly** option for teams that want useful **CVE scanning without paying for a larger commercial product**
|
|
374
552
|
|
|
375
553
|
### At a glance
|
|
@@ -382,6 +560,16 @@ Compared with other tools in this space, CVE Lite CLI focuses on:
|
|
|
382
560
|
| Snyk CLI | Broader enterprise security workflows | Broad | Strong ecosystem coverage | Strong commercial guidance | Strong | Teams adopting a larger security platform |
|
|
383
561
|
| Socket CLI | Broader package and supply-chain risk visibility | Broad | Multi-ecosystem/package-risk focus | Strong for package risk workflows | Strong | Teams that want more than CVE scanning alone |
|
|
384
562
|
|
|
563
|
+
### Offline support at a glance
|
|
564
|
+
|
|
565
|
+
| Tool | Local advisory DB workflow | Zero runtime advisory API calls |
|
|
566
|
+
|---|---|---|
|
|
567
|
+
| **CVE Lite CLI** | **Yes** | **Yes** |
|
|
568
|
+
| `npm audit` | No built-in local advisory DB workflow | No |
|
|
569
|
+
| OSV-Scanner | Depends on broader workflow setup rather than the local DB pattern emphasized here | Varies by setup |
|
|
570
|
+
| Snyk CLI | Not the primary workflow emphasis | Varies by product/workflow |
|
|
571
|
+
| Socket CLI | Not the primary workflow emphasis | Varies by product/workflow |
|
|
572
|
+
|
|
385
573
|
### CVE Lite CLI vs npm audit
|
|
386
574
|
|
|
387
575
|
`npm audit` is the built-in default for npm users, which makes it convenient when your workflow is entirely npm-based.
|
|
@@ -402,6 +590,7 @@ CVE Lite CLI stands out when you want:
|
|
|
402
590
|
- a narrower, easier-to-understand tool built specifically around JS/TS dependency workflows
|
|
403
591
|
- remediation-first output instead of a more general multi-ecosystem scanner experience
|
|
404
592
|
- a more approachable local workflow for everyday developers
|
|
593
|
+
- a more explicit local advisory DB workflow for offline or restricted environments
|
|
405
594
|
|
|
406
595
|
### CVE Lite CLI vs Snyk CLI
|
|
407
596
|
|
|
@@ -412,6 +601,7 @@ CVE Lite CLI stands out when you want:
|
|
|
412
601
|
- a simpler and lighter dependency CVE workflow
|
|
413
602
|
- an affordable option for small teams, startups, consultants, and independent developers
|
|
414
603
|
- a focused tool for lockfile-based release checks without adopting a larger platform
|
|
604
|
+
- a more explicit offline scanning model with local advisory DB control
|
|
415
605
|
|
|
416
606
|
### CVE Lite CLI vs Socket CLI
|
|
417
607
|
|
|
@@ -445,6 +635,7 @@ To keep the project honest, here is what it does **not** do in the current versi
|
|
|
445
635
|
- it does not scan container images, binaries, secrets, or IaC
|
|
446
636
|
- it does not replace a full application security program
|
|
447
637
|
- it is currently focused on JS/TS dependency scanning
|
|
638
|
+
- local advisory sync performance will need continued optimization as the advisory dataset grows
|
|
448
639
|
|
|
449
640
|
## Positioning
|
|
450
641
|
|
|
@@ -465,6 +656,7 @@ CVE Lite CLI is evolving from a vulnerability scanner into a comprehensive remed
|
|
|
465
656
|
* **Official GitHub Action:** Create a dedicated Action for one-line setup in CI/CD pipelines.
|
|
466
657
|
* **Expanded Lockfile Support:** Introduce parsers for emerging JS/TS ecosystems, including `bun.lockb`.
|
|
467
658
|
* **IDE Integration:** Develop a lightweight extension to highlight vulnerable packages directly within the code editor.
|
|
659
|
+
* **Workflow Integration Guidance:** Expand official workflow patterns for local scripts, hooks, CI, and offline developer adoption.
|
|
468
660
|
|
|
469
661
|
### Phase 3: Maturity & Compliance (Long-Term)
|
|
470
662
|
* **Standardized SBOM Support:** Add the ability to export findings as an **SBOM (Software Bill of Materials)** in CycloneDX or SPDX formats.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class LocalAdvisorySource {
|
|
2
|
+
db;
|
|
3
|
+
constructor(db) {
|
|
4
|
+
this.db = db;
|
|
5
|
+
}
|
|
6
|
+
queryBatch(packages) {
|
|
7
|
+
const results = packages.map(pkg => ({
|
|
8
|
+
package: pkg.name,
|
|
9
|
+
version: pkg.version,
|
|
10
|
+
vulnerabilities: this.db.findMatchingVulnerabilityIds(pkg).map(id => ({ id })),
|
|
11
|
+
}));
|
|
12
|
+
return Promise.resolve(results);
|
|
13
|
+
}
|
|
14
|
+
getVuln(id) {
|
|
15
|
+
const vuln = this.db.getVulnerability(id);
|
|
16
|
+
if (!vuln) {
|
|
17
|
+
return Promise.reject(new Error(`Local advisory database lookup failed for ${id}`));
|
|
18
|
+
}
|
|
19
|
+
return Promise.resolve(vuln);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import Database from "better-sqlite3";
|
|
4
|
+
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
5
|
+
const SCHEMA_SQL = `
|
|
6
|
+
CREATE TABLE IF NOT EXISTS advisories (
|
|
7
|
+
id TEXT PRIMARY KEY,
|
|
8
|
+
modified_at TEXT,
|
|
9
|
+
aliases_json TEXT NOT NULL,
|
|
10
|
+
summary TEXT,
|
|
11
|
+
osv_json TEXT NOT NULL
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
CREATE TABLE IF NOT EXISTS advisory_packages (
|
|
15
|
+
advisory_id TEXT NOT NULL,
|
|
16
|
+
ecosystem TEXT NOT NULL,
|
|
17
|
+
package_name TEXT NOT NULL,
|
|
18
|
+
introduced TEXT,
|
|
19
|
+
fixed TEXT,
|
|
20
|
+
last_affected TEXT,
|
|
21
|
+
FOREIGN KEY (advisory_id) REFERENCES advisories(id) ON DELETE CASCADE
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
CREATE INDEX IF NOT EXISTS idx_advisory_packages_lookup
|
|
25
|
+
ON advisory_packages (ecosystem, package_name);
|
|
26
|
+
|
|
27
|
+
CREATE INDEX IF NOT EXISTS idx_advisory_packages_advisory
|
|
28
|
+
ON advisory_packages (advisory_id);
|
|
29
|
+
|
|
30
|
+
CREATE TABLE IF NOT EXISTS advisory_db_metadata (
|
|
31
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
32
|
+
last_sync_at TEXT,
|
|
33
|
+
source_url TEXT
|
|
34
|
+
);
|
|
35
|
+
`;
|
|
36
|
+
export class LocalAdvisoryDatabase {
|
|
37
|
+
dbPath;
|
|
38
|
+
db;
|
|
39
|
+
upsertAdvisoryStatement;
|
|
40
|
+
deleteRangesStatement;
|
|
41
|
+
insertRangeStatement;
|
|
42
|
+
setMetadataStatement;
|
|
43
|
+
getMetadataStatement;
|
|
44
|
+
getVulnerabilityStatement;
|
|
45
|
+
findMatchingIdsStatement;
|
|
46
|
+
constructor(dbPath, options) {
|
|
47
|
+
this.dbPath = dbPath;
|
|
48
|
+
const readonly = !!options?.readonly;
|
|
49
|
+
if (!readonly) {
|
|
50
|
+
fs.mkdirSync(path.dirname(dbPath), { recursive: true });
|
|
51
|
+
}
|
|
52
|
+
this.db = new Database(dbPath, readonly ? { readonly: true, fileMustExist: true } : undefined);
|
|
53
|
+
this.db.pragma("foreign_keys = ON");
|
|
54
|
+
this.db.exec(SCHEMA_SQL);
|
|
55
|
+
this.upsertAdvisoryStatement = this.db.prepare(`
|
|
56
|
+
INSERT INTO advisories (id, modified_at, aliases_json, summary, osv_json)
|
|
57
|
+
VALUES (@id, @modified_at, @aliases_json, @summary, @osv_json)
|
|
58
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
59
|
+
modified_at = excluded.modified_at,
|
|
60
|
+
aliases_json = excluded.aliases_json,
|
|
61
|
+
summary = excluded.summary,
|
|
62
|
+
osv_json = excluded.osv_json
|
|
63
|
+
`);
|
|
64
|
+
this.deleteRangesStatement = this.db.prepare(`
|
|
65
|
+
DELETE FROM advisory_packages
|
|
66
|
+
WHERE advisory_id = ?
|
|
67
|
+
`);
|
|
68
|
+
this.insertRangeStatement = this.db.prepare(`
|
|
69
|
+
INSERT INTO advisory_packages (
|
|
70
|
+
advisory_id,
|
|
71
|
+
ecosystem,
|
|
72
|
+
package_name,
|
|
73
|
+
introduced,
|
|
74
|
+
fixed,
|
|
75
|
+
last_affected
|
|
76
|
+
) VALUES (
|
|
77
|
+
@advisory_id,
|
|
78
|
+
@ecosystem,
|
|
79
|
+
@package_name,
|
|
80
|
+
@introduced,
|
|
81
|
+
@fixed,
|
|
82
|
+
@last_affected
|
|
83
|
+
)
|
|
84
|
+
`);
|
|
85
|
+
this.setMetadataStatement = this.db.prepare(`
|
|
86
|
+
INSERT INTO advisory_db_metadata (id, last_sync_at, source_url)
|
|
87
|
+
VALUES (1, @last_sync_at, @source_url)
|
|
88
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
89
|
+
last_sync_at = excluded.last_sync_at,
|
|
90
|
+
source_url = excluded.source_url
|
|
91
|
+
`);
|
|
92
|
+
this.getMetadataStatement = this.db.prepare(`
|
|
93
|
+
SELECT last_sync_at, source_url
|
|
94
|
+
FROM advisory_db_metadata
|
|
95
|
+
WHERE id = 1
|
|
96
|
+
`);
|
|
97
|
+
this.getVulnerabilityStatement = this.db.prepare(`
|
|
98
|
+
SELECT osv_json
|
|
99
|
+
FROM advisories
|
|
100
|
+
WHERE id = ?
|
|
101
|
+
`);
|
|
102
|
+
this.findMatchingIdsStatement = this.db.prepare(`
|
|
103
|
+
SELECT advisory_id, introduced, fixed, last_affected
|
|
104
|
+
FROM advisory_packages
|
|
105
|
+
WHERE ecosystem = ? AND package_name = ?
|
|
106
|
+
`);
|
|
107
|
+
}
|
|
108
|
+
close() {
|
|
109
|
+
this.db.close();
|
|
110
|
+
}
|
|
111
|
+
setMetadata(metadata) {
|
|
112
|
+
this.setMetadataStatement.run({
|
|
113
|
+
last_sync_at: metadata.lastSyncAt,
|
|
114
|
+
source_url: metadata.sourceUrl,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
getMetadata() {
|
|
118
|
+
const row = this.getMetadataStatement.get();
|
|
119
|
+
return {
|
|
120
|
+
lastSyncAt: row?.last_sync_at ?? null,
|
|
121
|
+
sourceUrl: row?.source_url ?? null,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
upsertVulnerability(vuln) {
|
|
125
|
+
const transaction = this.db.transaction((item) => {
|
|
126
|
+
this.upsertVulnerabilityInternal(item);
|
|
127
|
+
});
|
|
128
|
+
transaction(vuln);
|
|
129
|
+
}
|
|
130
|
+
bulkUpsertVulnerabilities(vulns) {
|
|
131
|
+
const transaction = this.db.transaction((items) => {
|
|
132
|
+
for (const item of items) {
|
|
133
|
+
this.upsertVulnerabilityInternal(item);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
transaction([...vulns]);
|
|
137
|
+
}
|
|
138
|
+
upsertVulnerabilityInternal(vuln) {
|
|
139
|
+
const advisoryRows = deriveAdvisoryPackageRows(vuln);
|
|
140
|
+
const advisoryJson = JSON.stringify(vuln);
|
|
141
|
+
const aliasesJson = JSON.stringify(vuln.aliases ?? []);
|
|
142
|
+
this.upsertAdvisoryStatement.run({
|
|
143
|
+
id: vuln.id,
|
|
144
|
+
modified_at: null,
|
|
145
|
+
aliases_json: aliasesJson,
|
|
146
|
+
summary: vuln.summary ?? null,
|
|
147
|
+
osv_json: advisoryJson,
|
|
148
|
+
});
|
|
149
|
+
this.deleteRangesStatement.run(vuln.id);
|
|
150
|
+
for (const row of advisoryRows) {
|
|
151
|
+
this.insertRangeStatement.run(row);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
getVulnerability(id) {
|
|
155
|
+
const row = this.getVulnerabilityStatement.get(id);
|
|
156
|
+
if (!row)
|
|
157
|
+
return null;
|
|
158
|
+
return JSON.parse(row.osv_json);
|
|
159
|
+
}
|
|
160
|
+
findMatchingVulnerabilityIds(pkg) {
|
|
161
|
+
if (!looksLikeVersion(pkg.version)) {
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
const rows = this.findMatchingIdsStatement.all(pkg.ecosystem, pkg.name);
|
|
165
|
+
const ids = new Set();
|
|
166
|
+
for (const row of rows) {
|
|
167
|
+
if (versionMatchesRange(pkg.version, row)) {
|
|
168
|
+
ids.add(row.advisory_id);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return [...ids];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function versionMatchesRange(version, row) {
|
|
175
|
+
const introduced = row.introduced;
|
|
176
|
+
const fixed = row.fixed;
|
|
177
|
+
const lastAffected = row.last_affected;
|
|
178
|
+
if (introduced && introduced !== "0" && compareVersions(version, introduced) < 0) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
if (fixed && compareVersions(version, fixed) >= 0) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
if (lastAffected && compareVersions(version, lastAffected) > 0) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
function deriveAdvisoryPackageRows(vuln) {
|
|
190
|
+
const rows = [];
|
|
191
|
+
for (const affected of vuln.affected ?? []) {
|
|
192
|
+
const ecosystem = affected.package?.ecosystem;
|
|
193
|
+
const packageName = affected.package?.name;
|
|
194
|
+
if (!ecosystem || !packageName) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
for (const range of affected.ranges ?? []) {
|
|
198
|
+
const events = range.events ?? [];
|
|
199
|
+
let introduced = null;
|
|
200
|
+
for (const event of events) {
|
|
201
|
+
if (event.introduced) {
|
|
202
|
+
introduced = event.introduced;
|
|
203
|
+
}
|
|
204
|
+
if (event.fixed || event.last_affected) {
|
|
205
|
+
rows.push({
|
|
206
|
+
advisory_id: vuln.id,
|
|
207
|
+
ecosystem,
|
|
208
|
+
package_name: packageName,
|
|
209
|
+
introduced,
|
|
210
|
+
fixed: event.fixed ?? null,
|
|
211
|
+
last_affected: event.last_affected ?? null,
|
|
212
|
+
});
|
|
213
|
+
introduced = null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (events.length === 0) {
|
|
217
|
+
rows.push({
|
|
218
|
+
advisory_id: vuln.id,
|
|
219
|
+
ecosystem,
|
|
220
|
+
package_name: packageName,
|
|
221
|
+
introduced: null,
|
|
222
|
+
fixed: null,
|
|
223
|
+
last_affected: null,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
else if (introduced !== null) {
|
|
227
|
+
rows.push({
|
|
228
|
+
advisory_id: vuln.id,
|
|
229
|
+
ecosystem,
|
|
230
|
+
package_name: packageName,
|
|
231
|
+
introduced,
|
|
232
|
+
fixed: null,
|
|
233
|
+
last_affected: null,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return rows;
|
|
239
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { unzipSync } from "fflate";
|
|
5
|
+
import { LocalAdvisoryDatabase } from "./local-db.js";
|
|
6
|
+
const DEFAULT_OSV_NPM_DUMP_URL = "https://storage.googleapis.com/osv-vulnerabilities/npm/all.zip";
|
|
7
|
+
export const ADVISORY_DB_STALE_AFTER_MS = 7 * 24 * 60 * 60 * 1000;
|
|
8
|
+
export function getDefaultAdvisoryDbPath(outputPath) {
|
|
9
|
+
if (outputPath) {
|
|
10
|
+
return path.resolve(outputPath);
|
|
11
|
+
}
|
|
12
|
+
if (process.platform === "win32") {
|
|
13
|
+
const appData = process.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local");
|
|
14
|
+
return path.join(appData, "cve-lite", "advisories.db");
|
|
15
|
+
}
|
|
16
|
+
return path.join(os.homedir(), ".cache", "cve-lite", "advisories.db");
|
|
17
|
+
}
|
|
18
|
+
export async function syncOsvAdvisories(options = {}) {
|
|
19
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
20
|
+
const onProgress = options.onProgress;
|
|
21
|
+
const sourceUrl = options.sourceUrl ?? DEFAULT_OSV_NPM_DUMP_URL;
|
|
22
|
+
const dbPath = getDefaultAdvisoryDbPath(options.outputPath);
|
|
23
|
+
onProgress?.({
|
|
24
|
+
phase: "init",
|
|
25
|
+
sourceUrl,
|
|
26
|
+
dbPath,
|
|
27
|
+
message: `Sync initiated. Downloading advisory dump from ${sourceUrl}`,
|
|
28
|
+
});
|
|
29
|
+
fs.mkdirSync(path.dirname(dbPath), { recursive: true });
|
|
30
|
+
if (fs.existsSync(dbPath)) {
|
|
31
|
+
fs.rmSync(dbPath, { force: true });
|
|
32
|
+
}
|
|
33
|
+
const response = await fetchImpl(sourceUrl);
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
throw new Error(`OSV dump download failed: ${response.status} ${response.statusText}`);
|
|
36
|
+
}
|
|
37
|
+
const totalBytesHeader = response.headers.get("content-length");
|
|
38
|
+
const totalBytes = totalBytesHeader ? Number(totalBytesHeader) : null;
|
|
39
|
+
const zippedBytes = await readResponseBytes(response, (bytesReceived) => {
|
|
40
|
+
onProgress?.({
|
|
41
|
+
phase: "download",
|
|
42
|
+
bytesReceived,
|
|
43
|
+
totalBytes,
|
|
44
|
+
message: totalBytes && totalBytes > 0
|
|
45
|
+
? `Downloading advisory dump: ${formatBytes(bytesReceived)} / ${formatBytes(totalBytes)}`
|
|
46
|
+
: `Downloading advisory dump: ${formatBytes(bytesReceived)}`,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
onProgress?.({
|
|
50
|
+
phase: "download-complete",
|
|
51
|
+
bytesReceived: zippedBytes.byteLength,
|
|
52
|
+
totalBytes,
|
|
53
|
+
message: totalBytes && totalBytes > 0
|
|
54
|
+
? `Download complete: ${formatBytes(zippedBytes.byteLength)} / ${formatBytes(totalBytes)}`
|
|
55
|
+
: `Download complete: ${formatBytes(zippedBytes.byteLength)}`,
|
|
56
|
+
});
|
|
57
|
+
await yieldToEventLoop();
|
|
58
|
+
const archiveEntries = unzipSync(zippedBytes);
|
|
59
|
+
const advisoryEntries = Object.entries(archiveEntries).filter(([entryName]) => entryName.endsWith(".json"));
|
|
60
|
+
onProgress?.({
|
|
61
|
+
phase: "extract",
|
|
62
|
+
totalEntries: Object.keys(archiveEntries).length,
|
|
63
|
+
advisoryEntries: advisoryEntries.length,
|
|
64
|
+
message: `Archive loaded. Processing ${advisoryEntries.length} advisory record${advisoryEntries.length === 1 ? "" : "s"}`,
|
|
65
|
+
});
|
|
66
|
+
await yieldToEventLoop();
|
|
67
|
+
const db = new LocalAdvisoryDatabase(dbPath);
|
|
68
|
+
try {
|
|
69
|
+
const parsedVulns = [];
|
|
70
|
+
let advisoryCount = 0;
|
|
71
|
+
const progressInterval = 250;
|
|
72
|
+
for (const [, bytes] of advisoryEntries) {
|
|
73
|
+
const text = Buffer.from(bytes).toString("utf8");
|
|
74
|
+
const vuln = JSON.parse(text);
|
|
75
|
+
if (!vuln.id) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
parsedVulns.push(vuln);
|
|
79
|
+
advisoryCount += 1;
|
|
80
|
+
if (advisoryCount === 1 ||
|
|
81
|
+
advisoryCount % progressInterval === 0 ||
|
|
82
|
+
advisoryCount === advisoryEntries.length) {
|
|
83
|
+
onProgress?.({
|
|
84
|
+
phase: "ingest",
|
|
85
|
+
processedAdvisories: advisoryCount,
|
|
86
|
+
totalAdvisories: advisoryEntries.length,
|
|
87
|
+
message: `Processing advisory records: ${advisoryCount} / ${advisoryEntries.length}`,
|
|
88
|
+
});
|
|
89
|
+
await yieldToEventLoop();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
db.bulkUpsertVulnerabilities(parsedVulns);
|
|
93
|
+
db.setMetadata({
|
|
94
|
+
lastSyncAt: new Date().toISOString(),
|
|
95
|
+
sourceUrl,
|
|
96
|
+
});
|
|
97
|
+
onProgress?.({
|
|
98
|
+
phase: "complete",
|
|
99
|
+
advisoryCount,
|
|
100
|
+
dbPath,
|
|
101
|
+
message: `Sync complete. Stored ${advisoryCount} advisory record${advisoryCount === 1 ? "" : "s"} in ${dbPath}`,
|
|
102
|
+
});
|
|
103
|
+
return { advisoryCount, dbPath, sourceUrl };
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
try {
|
|
107
|
+
db.close();
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
if (fs.existsSync(dbPath)) {
|
|
111
|
+
fs.rmSync(dbPath, { force: true });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
try {
|
|
118
|
+
db.close();
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// ignore close errors during sync cleanup
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function readResponseBytes(response, onChunk) {
|
|
126
|
+
if (!response.body) {
|
|
127
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
128
|
+
onChunk(bytes.byteLength);
|
|
129
|
+
return bytes;
|
|
130
|
+
}
|
|
131
|
+
const reader = response.body.getReader();
|
|
132
|
+
const chunks = [];
|
|
133
|
+
let bytesReceived = 0;
|
|
134
|
+
while (true) {
|
|
135
|
+
const { done, value } = await reader.read();
|
|
136
|
+
if (done) {
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
if (value) {
|
|
140
|
+
chunks.push(value);
|
|
141
|
+
bytesReceived += value.byteLength;
|
|
142
|
+
onChunk(bytesReceived);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const combined = new Uint8Array(bytesReceived);
|
|
146
|
+
let offset = 0;
|
|
147
|
+
for (const chunk of chunks) {
|
|
148
|
+
combined.set(chunk, offset);
|
|
149
|
+
offset += chunk.byteLength;
|
|
150
|
+
}
|
|
151
|
+
return combined;
|
|
152
|
+
}
|
|
153
|
+
function formatBytes(bytes) {
|
|
154
|
+
if (bytes < 1024)
|
|
155
|
+
return `${bytes} B`;
|
|
156
|
+
const units = ["KB", "MB", "GB"];
|
|
157
|
+
let value = bytes / 1024;
|
|
158
|
+
let unitIndex = 0;
|
|
159
|
+
while (value >= 1024 && unitIndex < units.length - 1) {
|
|
160
|
+
value /= 1024;
|
|
161
|
+
unitIndex += 1;
|
|
162
|
+
}
|
|
163
|
+
return `${value.toFixed(value >= 10 ? 0 : 1)} ${units[unitIndex]}`;
|
|
164
|
+
}
|
|
165
|
+
async function yieldToEventLoop() {
|
|
166
|
+
await new Promise(resolve => {
|
|
167
|
+
setImmediate(resolve);
|
|
168
|
+
});
|
|
169
|
+
}
|
package/dist/cli/args.js
CHANGED
|
@@ -5,6 +5,27 @@ export function parseArgs(argv) {
|
|
|
5
5
|
searchDepth: "4",
|
|
6
6
|
minSeverity: "medium"
|
|
7
7
|
};
|
|
8
|
+
if (argv[0] === "advisories" && argv[1] === "sync") {
|
|
9
|
+
for (let i = 2; i < argv.length; i++) {
|
|
10
|
+
const arg = argv[i];
|
|
11
|
+
if (arg === "-h" || arg === "--help") {
|
|
12
|
+
options.help = true;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (arg === "--output") {
|
|
16
|
+
options.output = argv[++i];
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (arg.startsWith("--output=")) {
|
|
20
|
+
options.output = arg.slice("--output=".length);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (arg.startsWith("-"))
|
|
24
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
25
|
+
throw new Error(`Unexpected argument: ${arg}`);
|
|
26
|
+
}
|
|
27
|
+
return { command: "advisories-sync", options };
|
|
28
|
+
}
|
|
8
29
|
let projectArg;
|
|
9
30
|
for (let i = 0; i < argv.length; i++) {
|
|
10
31
|
const arg = argv[i];
|
|
@@ -28,6 +49,14 @@ export function parseArgs(argv) {
|
|
|
28
49
|
options.offline = true;
|
|
29
50
|
continue;
|
|
30
51
|
}
|
|
52
|
+
if (arg === "--offline-db") {
|
|
53
|
+
options.offlineDb = argv[++i];
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (arg.startsWith("--offline-db=")) {
|
|
57
|
+
options.offlineDb = arg.slice("--offline-db=".length);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
31
60
|
if (arg === "--all") {
|
|
32
61
|
options.all = true;
|
|
33
62
|
continue;
|
|
@@ -64,6 +93,14 @@ export function parseArgs(argv) {
|
|
|
64
93
|
options.osvUrl = arg.slice("--osv-url=".length);
|
|
65
94
|
continue;
|
|
66
95
|
}
|
|
96
|
+
if (arg === "--output") {
|
|
97
|
+
options.output = argv[++i];
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (arg.startsWith("--output=")) {
|
|
101
|
+
options.output = arg.slice("--output=".length);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
67
104
|
if (arg === "--search-depth") {
|
|
68
105
|
options.searchDepth = argv[++i] ?? options.searchDepth;
|
|
69
106
|
continue;
|
|
@@ -88,5 +125,5 @@ export function parseArgs(argv) {
|
|
|
88
125
|
}
|
|
89
126
|
throw new Error(`Unexpected argument: ${arg}`);
|
|
90
127
|
}
|
|
91
|
-
return { options, projectArg };
|
|
128
|
+
return { command: "scan", options, projectArg };
|
|
92
129
|
}
|
package/dist/cli/help.js
CHANGED
|
@@ -23,19 +23,25 @@ export function printHelp() {
|
|
|
23
23
|
"",
|
|
24
24
|
"Usage:",
|
|
25
25
|
" cve-lite [projectPath] [options]",
|
|
26
|
+
" cve-lite advisories sync [options]",
|
|
26
27
|
"",
|
|
27
|
-
"
|
|
28
|
+
"Scan options:",
|
|
28
29
|
" --json Print JSON output",
|
|
29
|
-
" --osv-url <url>
|
|
30
|
+
" --osv-url <url> Use a custom OSV-compatible advisory endpoint",
|
|
30
31
|
" --verbose Show detailed output with fix plan, paths, and full table",
|
|
31
32
|
" --prod-only Exclude dev dependencies where available",
|
|
32
33
|
" --fail-on <severity> Exit non-zero at or above severity (default: critical)",
|
|
33
34
|
" --batch-size <number> OSV batch size (default: 100)",
|
|
34
|
-
" --offline
|
|
35
|
+
" --offline Scan using the local advisory database",
|
|
36
|
+
" --offline-db <path> Use a specific local advisory database file",
|
|
35
37
|
" --cache-dir <path> Override cache directory",
|
|
36
38
|
" --search-depth <number> Recursive search depth (default: 4)",
|
|
37
39
|
" --all Show all findings in the main table",
|
|
38
40
|
" --min-severity <level> Minimum severity shown in table (default: medium)",
|
|
41
|
+
"",
|
|
42
|
+
"Advisory sync options:",
|
|
43
|
+
" --output <path> Write the local advisory database to this path",
|
|
44
|
+
"",
|
|
39
45
|
" -h, --help Show this help message"
|
|
40
46
|
];
|
|
41
47
|
console.log(lines.join("\n"));
|
package/dist/index.js
CHANGED
|
@@ -4,13 +4,15 @@ import process from "node:process";
|
|
|
4
4
|
import { parseArgs } from "./cli/args.js";
|
|
5
5
|
import { printBanner, printHelp } from "./cli/help.js";
|
|
6
6
|
import { loadPackages, buildNoPackagesMessage } from "./parsers/index.js";
|
|
7
|
-
import { scanPackages, buildCoverageNotes } from "./scanner.js";
|
|
7
|
+
import { scanPackages, buildCoverageNotes, createAdvisorySource } from "./scanner.js";
|
|
8
|
+
import { syncOsvAdvisories } from "./advisory/osv-sync.js";
|
|
8
9
|
import { normalizeSeverity } from "./osv/severity.js";
|
|
9
10
|
import { severityOrder } from "./constants.js";
|
|
10
11
|
import { chalk } from "./utils/chalk.js";
|
|
12
|
+
import { createSpinner } from "./output/spinner.js";
|
|
11
13
|
import { logInfo, logWarn, printCacheSummary, serializeFinding } from "./output/formatters.js";
|
|
12
14
|
import { printSummary, printActionSummary, printPriorityFixes, printFixPlan, printCoverage, printSkippedDependencies, printGroupSummary, printTable, printPathHints, printFinalStatus, printCompactOutput } from "./output/printers.js";
|
|
13
|
-
const { options, projectArg } = parseArgs(process.argv.slice(2));
|
|
15
|
+
const { command, options, projectArg } = parseArgs(process.argv.slice(2));
|
|
14
16
|
if (options.help) {
|
|
15
17
|
printHelp();
|
|
16
18
|
process.exit(0);
|
|
@@ -22,18 +24,34 @@ async function main() {
|
|
|
22
24
|
if (!options.json) {
|
|
23
25
|
printBanner();
|
|
24
26
|
}
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
if (command === "advisories-sync") {
|
|
28
|
+
const spinner = createSpinner("Preparing advisory sync...", options);
|
|
29
|
+
const usePlainProgressLogs = !process.stdout.isTTY || !!options.json;
|
|
30
|
+
const result = await syncOsvAdvisories({
|
|
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)`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
spinner.succeed(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
48
|
+
}
|
|
49
|
+
console.log(`${chalk.gray("Advisory database:")} synced ${result.advisoryCount} record${result.advisoryCount === 1 ? "" : "s"} to ${chalk.cyan(result.dbPath)}`);
|
|
50
|
+
process.exit(0);
|
|
51
|
+
return;
|
|
34
52
|
}
|
|
35
|
-
|
|
36
|
-
|
|
53
|
+
if ((options.offline || options.offlineDb) && options.osvUrl) {
|
|
54
|
+
throw new Error("--offline/--offline-db cannot be used with --osv-url");
|
|
37
55
|
}
|
|
38
56
|
if (options.osvUrl) {
|
|
39
57
|
try {
|
|
@@ -43,6 +61,43 @@ async function main() {
|
|
|
43
61
|
throw new Error(`Invalid value for --osv-url: ${options.osvUrl}`);
|
|
44
62
|
}
|
|
45
63
|
}
|
|
64
|
+
let advisorySourceLine;
|
|
65
|
+
let advisoryDbFreshnessLine = null;
|
|
66
|
+
let advisoryDbWarning = null;
|
|
67
|
+
try {
|
|
68
|
+
const advisorySource = createAdvisorySource({
|
|
69
|
+
osvUrl: options.osvUrl,
|
|
70
|
+
offline: options.offline,
|
|
71
|
+
offlineDb: options.offlineDb,
|
|
72
|
+
});
|
|
73
|
+
advisorySourceLine = advisorySource.sourceLabel;
|
|
74
|
+
if (advisorySource.offline) {
|
|
75
|
+
const metadata = advisorySource.advisoryDbMetadata;
|
|
76
|
+
advisoryDbFreshnessLine = formatAdvisoryDbFreshness(metadata?.lastSyncAt ?? null);
|
|
77
|
+
if (advisorySource.advisoryDbIsStale) {
|
|
78
|
+
advisoryDbWarning = metadata?.lastSyncAt
|
|
79
|
+
? "The local advisory DB appears stale. Re-run `cve-lite advisories sync` to refresh it."
|
|
80
|
+
: "The local advisory DB has no recorded sync timestamp. Re-run `cve-lite advisories sync` to refresh it.";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
advisorySource.cleanup();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (options.offline || options.offlineDb) {
|
|
87
|
+
throw new Error(`Offline advisory database is not available: ${error instanceof Error ? error.message : String(error)}`);
|
|
88
|
+
}
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
if (options.offline || options.offlineDb) {
|
|
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
|
+
}
|
|
46
101
|
const scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
47
102
|
const packages = scanInput.packages;
|
|
48
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);
|
|
@@ -55,10 +110,11 @@ async function main() {
|
|
|
55
110
|
if (packages.length === 0) {
|
|
56
111
|
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
57
112
|
process.exit(0);
|
|
113
|
+
return;
|
|
58
114
|
}
|
|
59
115
|
const findings = await scanPackages(packages, batchSize, options);
|
|
60
116
|
const sorted = findings.sort((a, b) => severityOrder[b.severity] - severityOrder[a.severity]);
|
|
61
|
-
const coverage = buildCoverageNotes(scanInput, !!options.offline);
|
|
117
|
+
const coverage = buildCoverageNotes(scanInput, !!options.offline || !!options.offlineDb);
|
|
62
118
|
const minSeverity = normalizeSeverity(options.minSeverity || "medium");
|
|
63
119
|
const tableFindings = options.all ? sorted : sorted.filter(f => severityOrder[f.severity] >= severityOrder[minSeverity]);
|
|
64
120
|
if (options.json) {
|
|
@@ -103,8 +159,45 @@ async function main() {
|
|
|
103
159
|
const failLevel = normalizeSeverity(options.failOn);
|
|
104
160
|
const shouldFail = sorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
105
161
|
process.exit(shouldFail ? 1 : 0);
|
|
162
|
+
return;
|
|
106
163
|
}
|
|
107
164
|
main().catch((error) => {
|
|
108
165
|
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
109
166
|
process.exit(1);
|
|
110
167
|
});
|
|
168
|
+
function formatAdvisorySourceLine(sourceLabel) {
|
|
169
|
+
const match = sourceLabel.match(/^(.*) \((.*)\)$/);
|
|
170
|
+
if (!match) {
|
|
171
|
+
return sourceLabel;
|
|
172
|
+
}
|
|
173
|
+
return `${match[1]} (${chalk.cyan(match[2])})`;
|
|
174
|
+
}
|
|
175
|
+
function formatAdvisoryDbFreshness(lastSyncAt) {
|
|
176
|
+
if (!lastSyncAt) {
|
|
177
|
+
return chalk.yellow("unknown");
|
|
178
|
+
}
|
|
179
|
+
const timestamp = Date.parse(lastSyncAt);
|
|
180
|
+
if (Number.isNaN(timestamp)) {
|
|
181
|
+
return chalk.yellow("unknown");
|
|
182
|
+
}
|
|
183
|
+
return `${relativeAge(timestamp)} ${chalk.gray(`(${lastSyncAt})`)}`;
|
|
184
|
+
}
|
|
185
|
+
function relativeAge(timestamp) {
|
|
186
|
+
const deltaMs = Math.max(0, Date.now() - timestamp);
|
|
187
|
+
const minute = 60 * 1000;
|
|
188
|
+
const hour = 60 * minute;
|
|
189
|
+
const day = 24 * hour;
|
|
190
|
+
if (deltaMs < minute) {
|
|
191
|
+
return "just synced";
|
|
192
|
+
}
|
|
193
|
+
if (deltaMs < hour) {
|
|
194
|
+
const minutes = Math.floor(deltaMs / minute);
|
|
195
|
+
return `synced ${minutes} minute${minutes === 1 ? "" : "s"} ago`;
|
|
196
|
+
}
|
|
197
|
+
if (deltaMs < day) {
|
|
198
|
+
const hours = Math.floor(deltaMs / hour);
|
|
199
|
+
return `synced ${hours} hour${hours === 1 ? "" : "s"} ago`;
|
|
200
|
+
}
|
|
201
|
+
const days = Math.floor(deltaMs / day);
|
|
202
|
+
return `synced ${days} day${days === 1 ? "" : "s"} ago`;
|
|
203
|
+
}
|
package/dist/osv/cache.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import os from "node:os";
|
|
4
|
+
function createEmptyCache() {
|
|
5
|
+
return { version: 2, createdAt: new Date().toISOString(), entries: {}, queryEntries: {} };
|
|
6
|
+
}
|
|
4
7
|
export function getCacheFilePath(cacheDirOverride) {
|
|
5
8
|
const baseDir = cacheDirOverride
|
|
6
9
|
? path.resolve(cacheDirOverride)
|
|
@@ -11,18 +14,23 @@ export function getCacheFilePath(cacheDirOverride) {
|
|
|
11
14
|
export function loadCache(cacheDirOverride) {
|
|
12
15
|
const filePath = getCacheFilePath(cacheDirOverride);
|
|
13
16
|
if (!fs.existsSync(filePath)) {
|
|
14
|
-
return
|
|
17
|
+
return createEmptyCache();
|
|
15
18
|
}
|
|
16
19
|
try {
|
|
17
20
|
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
18
|
-
if (parsed.
|
|
19
|
-
return
|
|
21
|
+
if (parsed.entries && typeof parsed.entries === "object") {
|
|
22
|
+
return {
|
|
23
|
+
version: 2,
|
|
24
|
+
createdAt: parsed.createdAt ?? new Date().toISOString(),
|
|
25
|
+
entries: parsed.entries,
|
|
26
|
+
queryEntries: parsed.queryEntries && typeof parsed.queryEntries === "object" ? parsed.queryEntries : {},
|
|
27
|
+
};
|
|
20
28
|
}
|
|
21
29
|
}
|
|
22
30
|
catch (_error) {
|
|
23
31
|
// ignore corrupt cache
|
|
24
32
|
}
|
|
25
|
-
return
|
|
33
|
+
return createEmptyCache();
|
|
26
34
|
}
|
|
27
35
|
export function saveCache(cache, cacheDirOverride) {
|
|
28
36
|
const filePath = getCacheFilePath(cacheDirOverride);
|
|
@@ -113,10 +113,11 @@ export function printCacheSummary(cacheDirOverride, options) {
|
|
|
113
113
|
const cache = loadCache(cacheDirOverride);
|
|
114
114
|
const advisoryCount = Object.entries(cache.entries).filter(([, value]) => Boolean(value)).length;
|
|
115
115
|
const emptyCount = Object.entries(cache.entries).filter(([, value]) => value === null).length;
|
|
116
|
+
const packageQueryCount = Object.keys(cache.queryEntries).length;
|
|
116
117
|
const totalCount = advisoryCount + emptyCount;
|
|
117
|
-
if (totalCount === 0)
|
|
118
|
+
if (totalCount === 0 && packageQueryCount === 0)
|
|
118
119
|
return;
|
|
119
|
-
console.log(chalk.gray(`Cache: ${advisoryCount} advisory detail record${advisoryCount === 1 ? "" : "s"}`) +
|
|
120
|
+
console.log(chalk.gray(`Cache: ${packageQueryCount} package match record${packageQueryCount === 1 ? "" : "s"}, ${advisoryCount} advisory detail record${advisoryCount === 1 ? "" : "s"}`) +
|
|
120
121
|
(emptyCount > 0
|
|
121
122
|
? chalk.gray(`, ${emptyCount} empty lookup${emptyCount === 1 ? "" : "s"}`)
|
|
122
123
|
: ""));
|
package/dist/output/spinner.js
CHANGED
package/dist/scanner.js
CHANGED
|
@@ -4,19 +4,67 @@ import { loadCache, saveCache } from "./osv/cache.js";
|
|
|
4
4
|
import { maxSeverity } from "./osv/severity.js";
|
|
5
5
|
import { createSpinner } from "./output/spinner.js";
|
|
6
6
|
import { OsvAdvisorySource } from "./advisory/osv-advisory-source.js";
|
|
7
|
+
import { LocalAdvisorySource } from "./advisory/local-advisory-source.js";
|
|
8
|
+
import { LocalAdvisoryDatabase } from "./advisory/local-db.js";
|
|
9
|
+
import { ADVISORY_DB_STALE_AFTER_MS, getDefaultAdvisoryDbPath } from "./advisory/osv-sync.js";
|
|
7
10
|
import { resolveRecommendedParentUpgrade } from "./remediation/parent-upgrade.js";
|
|
8
11
|
export function createAdvisorySource(options) {
|
|
9
|
-
|
|
12
|
+
const offline = !!options?.offline || !!options?.offlineDb;
|
|
13
|
+
if (offline) {
|
|
14
|
+
const dbPath = getDefaultAdvisoryDbPath(options?.offlineDb);
|
|
15
|
+
const db = new LocalAdvisoryDatabase(dbPath, { readonly: true });
|
|
16
|
+
return {
|
|
17
|
+
advisorySource: new LocalAdvisorySource(db),
|
|
18
|
+
offline: true,
|
|
19
|
+
sourceLabel: `local advisory database (${dbPath})`,
|
|
20
|
+
advisoryDbMetadata: db.getMetadata(),
|
|
21
|
+
advisoryDbIsStale: isAdvisoryDbStale(db.getMetadata()),
|
|
22
|
+
cleanup: () => db.close(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
advisorySource: new OsvAdvisorySource(options?.osvUrl),
|
|
27
|
+
offline: false,
|
|
28
|
+
sourceLabel: options?.osvUrl
|
|
29
|
+
? `custom OSV endpoint (${options.osvUrl})`
|
|
30
|
+
: "OSV (https://api.osv.dev)",
|
|
31
|
+
advisoryDbMetadata: null,
|
|
32
|
+
advisoryDbIsStale: false,
|
|
33
|
+
cleanup: () => { },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function getPackageCacheKey(pkg) {
|
|
37
|
+
return `${pkg.ecosystem}:${pkg.name}@${pkg.version}`;
|
|
10
38
|
}
|
|
11
39
|
export async function scanPackages(packages, batchSize, options) {
|
|
12
|
-
const
|
|
40
|
+
const sourceContext = createAdvisorySource({
|
|
41
|
+
osvUrl: options.osvUrl,
|
|
42
|
+
offline: options.offline,
|
|
43
|
+
offlineDb: options.offlineDb,
|
|
44
|
+
});
|
|
45
|
+
const offline = sourceContext.offline;
|
|
13
46
|
const cacheDirOverride = options.cacheDir;
|
|
14
|
-
const spinner = createSpinner(
|
|
15
|
-
|
|
47
|
+
const spinner = createSpinner(offline
|
|
48
|
+
? "Scanning dependencies against the local advisory database..."
|
|
49
|
+
: "Scanning dependencies against OSV...", options);
|
|
50
|
+
const advisorySource = sourceContext.advisorySource;
|
|
51
|
+
const cache = loadCache(cacheDirOverride);
|
|
16
52
|
try {
|
|
17
|
-
const chunks = chunk(packages, batchSize);
|
|
18
53
|
const results = [];
|
|
54
|
+
const uncachedPackages = [];
|
|
19
55
|
if (!offline) {
|
|
56
|
+
for (const pkg of packages) {
|
|
57
|
+
const cacheKey = getPackageCacheKey(pkg);
|
|
58
|
+
if (cacheKey in cache.queryEntries) {
|
|
59
|
+
const vulnIds = cache.queryEntries[cacheKey] ?? [];
|
|
60
|
+
if (vulnIds.length > 0) {
|
|
61
|
+
results.push({ pkg, vulnIds });
|
|
62
|
+
}
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
uncachedPackages.push(pkg);
|
|
66
|
+
}
|
|
67
|
+
const chunks = chunk(uncachedPackages, batchSize);
|
|
20
68
|
for (let i = 0; i < chunks.length; i++) {
|
|
21
69
|
spinner.update(`Scanning OSV batch ${i + 1}/${chunks.length}...`);
|
|
22
70
|
const chunkItems = chunks[i];
|
|
@@ -26,17 +74,32 @@ export async function scanPackages(packages, batchSize, options) {
|
|
|
26
74
|
const pkg = chunkItems[j];
|
|
27
75
|
const row = rows[j];
|
|
28
76
|
const vulnIds = (row?.vulnerabilities ?? []).map(v => v.id).filter(Boolean);
|
|
77
|
+
cache.queryEntries[getPackageCacheKey(pkg)] = vulnIds;
|
|
29
78
|
if (vulnIds.length > 0) {
|
|
30
79
|
results.push({ pkg, vulnIds });
|
|
31
80
|
}
|
|
32
81
|
}
|
|
33
82
|
}
|
|
34
|
-
|
|
83
|
+
if (chunks.length === 0) {
|
|
84
|
+
spinner.succeed("Loaded package matches from cache");
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
spinner.succeed(`Queried OSV in ${chunks.length} batch${chunks.length === 1 ? "" : "es"}`);
|
|
88
|
+
}
|
|
35
89
|
}
|
|
36
90
|
else {
|
|
37
|
-
|
|
91
|
+
const advisoryResult = await advisorySource.queryBatch(packages);
|
|
92
|
+
const rows = advisoryResult ?? [];
|
|
93
|
+
for (let i = 0; i < packages.length; i++) {
|
|
94
|
+
const pkg = packages[i];
|
|
95
|
+
const row = rows[i];
|
|
96
|
+
const vulnIds = (row?.vulnerabilities ?? []).map(v => v.id).filter(Boolean);
|
|
97
|
+
if (vulnIds.length > 0) {
|
|
98
|
+
results.push({ pkg, vulnIds });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
spinner.succeed("Loaded package matches from the local advisory database");
|
|
38
102
|
}
|
|
39
|
-
const cache = loadCache(cacheDirOverride);
|
|
40
103
|
const idSet = new Set(results.flatMap(r => r.vulnIds));
|
|
41
104
|
const vulnMap = new Map();
|
|
42
105
|
if (idSet.size > 0 && !offline) {
|
|
@@ -46,9 +109,11 @@ export async function scanPackages(packages, batchSize, options) {
|
|
|
46
109
|
for (let i = 0; i < ids.length; i++) {
|
|
47
110
|
const id = ids[i];
|
|
48
111
|
detailSpinner.update(`Fetching vulnerability details ${i + 1}/${ids.length}...`);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
112
|
+
if (id in cache.entries) {
|
|
113
|
+
const cached = cache.entries[id];
|
|
114
|
+
if (cached) {
|
|
115
|
+
vulnMap.set(id, cached);
|
|
116
|
+
}
|
|
52
117
|
continue;
|
|
53
118
|
}
|
|
54
119
|
try {
|
|
@@ -67,6 +132,28 @@ export async function scanPackages(packages, batchSize, options) {
|
|
|
67
132
|
throw error;
|
|
68
133
|
}
|
|
69
134
|
}
|
|
135
|
+
else if (idSet.size > 0 && offline) {
|
|
136
|
+
const ids = [...idSet];
|
|
137
|
+
const detailSpinner = createSpinner("Loading local advisory details...", options);
|
|
138
|
+
try {
|
|
139
|
+
for (let i = 0; i < ids.length; i++) {
|
|
140
|
+
const id = ids[i];
|
|
141
|
+
detailSpinner.update(`Loading local advisory details ${i + 1}/${ids.length}...`);
|
|
142
|
+
try {
|
|
143
|
+
const detail = await advisorySource.getVuln(id);
|
|
144
|
+
vulnMap.set(id, detail);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
// ignore missing local records so scans remain resilient to partial DB state
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
detailSpinner.succeed(`Loaded ${ids.length} local advisory detail record${ids.length === 1 ? "" : "s"}`);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
detailSpinner.fail("Failed while loading local advisory details");
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
70
157
|
if (!offline && idSet.size > 0) {
|
|
71
158
|
saveCache(cache, cacheDirOverride);
|
|
72
159
|
}
|
|
@@ -106,6 +193,19 @@ export async function scanPackages(packages, batchSize, options) {
|
|
|
106
193
|
spinner.fail("Scan failed");
|
|
107
194
|
throw error;
|
|
108
195
|
}
|
|
196
|
+
finally {
|
|
197
|
+
sourceContext.cleanup();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function isAdvisoryDbStale(metadata) {
|
|
201
|
+
if (!metadata.lastSyncAt) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
const timestamp = Date.parse(metadata.lastSyncAt);
|
|
205
|
+
if (Number.isNaN(timestamp)) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
return Date.now() - timestamp > ADVISORY_DB_STALE_AFTER_MS;
|
|
109
209
|
}
|
|
110
210
|
function classifyRelationship(paths) {
|
|
111
211
|
if (paths.length === 0)
|
|
@@ -144,7 +244,7 @@ export function buildCoverageNotes(scanInput, offline) {
|
|
|
144
244
|
notes.push("Manifest fallback is limited to direct dependencies pinned to exact versions. It does not resolve transitive dependencies from package.json alone.");
|
|
145
245
|
}
|
|
146
246
|
if (offline) {
|
|
147
|
-
notes.push("Offline mode
|
|
247
|
+
notes.push("Offline mode uses the local advisory database and does not make outbound advisory API calls.");
|
|
148
248
|
}
|
|
149
249
|
return notes;
|
|
150
250
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cve-lite-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.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": {
|
|
@@ -9,14 +9,22 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc -p tsconfig.json",
|
|
11
11
|
"dev": "tsx src/index.ts .",
|
|
12
|
-
"start": "node dist/index.js ."
|
|
12
|
+
"start": "node dist/index.js .",
|
|
13
|
+
"test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --passWithNoTests",
|
|
14
|
+
"test:watch": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch --passWithNoTests"
|
|
13
15
|
},
|
|
14
16
|
"dependencies": {
|
|
17
|
+
"better-sqlite3": "^12.8.0",
|
|
18
|
+
"fflate": "^0.8.2",
|
|
15
19
|
"yaml": "^2.7.1",
|
|
16
20
|
"yarn-lockfile": "^1.1.0"
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
23
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
24
|
+
"@types/jest": "^30.0.0",
|
|
19
25
|
"@types/node": "^24.0.0",
|
|
26
|
+
"jest": "^30.3.0",
|
|
27
|
+
"ts-jest": "^29.4.9",
|
|
20
28
|
"tsx": "^4.19.2",
|
|
21
29
|
"typescript": "^5.8.2"
|
|
22
30
|
},
|