cve-lite-cli 1.1.0 → 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 +72 -7
- package/dist/advisory/local-db.js +84 -33
- package/dist/advisory/osv-sync.js +10 -6
- package/dist/index.js +46 -0
- package/dist/scanner.js +15 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<img src="https://github.com/sonukapoor/cve-lite-cli/blob/main/assets/logo-with-title.png" alt="CVE Lite CLI" width="320"/>
|
|
9
9
|
|
|
10
10
|
<h1>CVE Lite CLI</h1>
|
|
11
|
-
<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>
|
|
12
12
|
|
|
13
13
|
<strong>Scan. Prioritize. Fix.</strong>
|
|
14
14
|
|
|
@@ -27,6 +27,13 @@
|
|
|
27
27
|
|
|
28
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.
|
|
29
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
|
+
|
|
30
37
|
## New: Offline advisory DB support
|
|
31
38
|
|
|
32
39
|
CVE Lite CLI now supports a local advisory database workflow for teams that cannot allow runtime outbound advisory API calls.
|
|
@@ -50,6 +57,19 @@ cve-lite /path/to/project --offline
|
|
|
50
57
|
cve-lite /path/to/project --offline-db /path/to/advisories.db
|
|
51
58
|
```
|
|
52
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
|
+
|
|
53
73
|
## Quick start
|
|
54
74
|
|
|
55
75
|
Install globally:
|
|
@@ -108,6 +128,34 @@ cve-lite /path/to/project --offline
|
|
|
108
128
|
cve-lite /path/to/project --offline-db /path/to/advisories.db
|
|
109
129
|
```
|
|
110
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
|
|
157
|
+
```
|
|
158
|
+
|
|
111
159
|
## What it looks like
|
|
112
160
|
|
|
113
161
|
CVE Lite CLI produces a clean, summary-first console view by default, designed for fast triage before release.
|
|
@@ -197,6 +245,8 @@ Its role is narrower and workflow-focused:
|
|
|
197
245
|
|
|
198
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.
|
|
199
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
|
+
|
|
200
250
|
## Network behavior and privacy
|
|
201
251
|
|
|
202
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.
|
|
@@ -219,6 +269,8 @@ Sync the local advisory database:
|
|
|
219
269
|
cve-lite advisories sync
|
|
220
270
|
```
|
|
221
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
|
+
|
|
222
274
|
Write the advisory database to a specific path:
|
|
223
275
|
|
|
224
276
|
```bash
|
|
@@ -255,17 +307,15 @@ cve-lite . --osv-url https://security.company.internal/osv
|
|
|
255
307
|
|
|
256
308
|
The local advisory DB is only as current as the last successful sync.
|
|
257
309
|
|
|
258
|
-
|
|
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:
|
|
259
313
|
|
|
260
314
|
- sync the advisory DB on a schedule using cron, CI, or another automation system
|
|
261
315
|
- distribute the refreshed DB where needed
|
|
262
316
|
- run offline scans against that updated DB
|
|
263
317
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
- last sync timestamp reporting
|
|
267
|
-
- a TTL-style warning when the DB is older than a recommended threshold
|
|
268
|
-
- clearer CLI guidance when a local advisory DB should be refreshed
|
|
318
|
+
This helps keep offline scan results current without requiring developers to manually track advisory update cadence.
|
|
269
319
|
|
|
270
320
|
## Detecting malicious package incidents
|
|
271
321
|
|
|
@@ -315,6 +365,8 @@ CVE Lite CLI is designed as a **local-first, metadata-only** scanner. Unlike tra
|
|
|
315
365
|
It reads your project locally and uses package/version matching against OSV advisories.
|
|
316
366
|
- **offline-capable**
|
|
317
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.
|
|
318
370
|
- **release-focused**
|
|
319
371
|
It is especially useful before a release, in CI, or during final dependency cleanup.
|
|
320
372
|
|
|
@@ -430,6 +482,7 @@ CVE Lite CLI is a good fit for:
|
|
|
430
482
|
- developers who want a second opinion alongside other tools
|
|
431
483
|
- OSS maintainers who need a practical scan before publishing
|
|
432
484
|
- teams that need offline or controlled-network dependency scanning
|
|
485
|
+
- security-conscious organizations that need clear advisory data control
|
|
433
486
|
|
|
434
487
|
## Supported workflows
|
|
435
488
|
|
|
@@ -507,6 +560,16 @@ Compared with other tools in this space, CVE Lite CLI focuses on:
|
|
|
507
560
|
| Snyk CLI | Broader enterprise security workflows | Broad | Strong ecosystem coverage | Strong commercial guidance | Strong | Teams adopting a larger security platform |
|
|
508
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 |
|
|
509
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
|
+
|
|
510
573
|
### CVE Lite CLI vs npm audit
|
|
511
574
|
|
|
512
575
|
`npm audit` is the built-in default for npm users, which makes it convenient when your workflow is entirely npm-based.
|
|
@@ -527,6 +590,7 @@ CVE Lite CLI stands out when you want:
|
|
|
527
590
|
- a narrower, easier-to-understand tool built specifically around JS/TS dependency workflows
|
|
528
591
|
- remediation-first output instead of a more general multi-ecosystem scanner experience
|
|
529
592
|
- a more approachable local workflow for everyday developers
|
|
593
|
+
- a more explicit local advisory DB workflow for offline or restricted environments
|
|
530
594
|
|
|
531
595
|
### CVE Lite CLI vs Snyk CLI
|
|
532
596
|
|
|
@@ -537,6 +601,7 @@ CVE Lite CLI stands out when you want:
|
|
|
537
601
|
- a simpler and lighter dependency CVE workflow
|
|
538
602
|
- an affordable option for small teams, startups, consultants, and independent developers
|
|
539
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
|
|
540
605
|
|
|
541
606
|
### CVE Lite CLI vs Socket CLI
|
|
542
607
|
|
|
@@ -26,10 +26,23 @@ const SCHEMA_SQL = `
|
|
|
26
26
|
|
|
27
27
|
CREATE INDEX IF NOT EXISTS idx_advisory_packages_advisory
|
|
28
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
|
+
);
|
|
29
35
|
`;
|
|
30
36
|
export class LocalAdvisoryDatabase {
|
|
31
37
|
dbPath;
|
|
32
38
|
db;
|
|
39
|
+
upsertAdvisoryStatement;
|
|
40
|
+
deleteRangesStatement;
|
|
41
|
+
insertRangeStatement;
|
|
42
|
+
setMetadataStatement;
|
|
43
|
+
getMetadataStatement;
|
|
44
|
+
getVulnerabilityStatement;
|
|
45
|
+
findMatchingIdsStatement;
|
|
33
46
|
constructor(dbPath, options) {
|
|
34
47
|
this.dbPath = dbPath;
|
|
35
48
|
const readonly = !!options?.readonly;
|
|
@@ -39,15 +52,7 @@ export class LocalAdvisoryDatabase {
|
|
|
39
52
|
this.db = new Database(dbPath, readonly ? { readonly: true, fileMustExist: true } : undefined);
|
|
40
53
|
this.db.pragma("foreign_keys = ON");
|
|
41
54
|
this.db.exec(SCHEMA_SQL);
|
|
42
|
-
|
|
43
|
-
close() {
|
|
44
|
-
this.db.close();
|
|
45
|
-
}
|
|
46
|
-
upsertVulnerability(vuln) {
|
|
47
|
-
const advisoryRows = deriveAdvisoryPackageRows(vuln);
|
|
48
|
-
const advisoryJson = JSON.stringify(vuln);
|
|
49
|
-
const aliasesJson = JSON.stringify(vuln.aliases ?? []);
|
|
50
|
-
const upsertAdvisory = this.db.prepare(`
|
|
55
|
+
this.upsertAdvisoryStatement = this.db.prepare(`
|
|
51
56
|
INSERT INTO advisories (id, modified_at, aliases_json, summary, osv_json)
|
|
52
57
|
VALUES (@id, @modified_at, @aliases_json, @summary, @osv_json)
|
|
53
58
|
ON CONFLICT(id) DO UPDATE SET
|
|
@@ -56,11 +61,11 @@ export class LocalAdvisoryDatabase {
|
|
|
56
61
|
summary = excluded.summary,
|
|
57
62
|
osv_json = excluded.osv_json
|
|
58
63
|
`);
|
|
59
|
-
|
|
64
|
+
this.deleteRangesStatement = this.db.prepare(`
|
|
60
65
|
DELETE FROM advisory_packages
|
|
61
66
|
WHERE advisory_id = ?
|
|
62
67
|
`);
|
|
63
|
-
|
|
68
|
+
this.insertRangeStatement = this.db.prepare(`
|
|
64
69
|
INSERT INTO advisory_packages (
|
|
65
70
|
advisory_id,
|
|
66
71
|
ecosystem,
|
|
@@ -77,27 +82,77 @@ export class LocalAdvisoryDatabase {
|
|
|
77
82
|
@last_affected
|
|
78
83
|
)
|
|
79
84
|
`);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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);
|
|
91
134
|
}
|
|
92
135
|
});
|
|
93
|
-
transaction();
|
|
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
|
+
}
|
|
94
153
|
}
|
|
95
154
|
getVulnerability(id) {
|
|
96
|
-
const row = this.
|
|
97
|
-
SELECT osv_json
|
|
98
|
-
FROM advisories
|
|
99
|
-
WHERE id = ?
|
|
100
|
-
`).get(id);
|
|
155
|
+
const row = this.getVulnerabilityStatement.get(id);
|
|
101
156
|
if (!row)
|
|
102
157
|
return null;
|
|
103
158
|
return JSON.parse(row.osv_json);
|
|
@@ -106,11 +161,7 @@ export class LocalAdvisoryDatabase {
|
|
|
106
161
|
if (!looksLikeVersion(pkg.version)) {
|
|
107
162
|
return [];
|
|
108
163
|
}
|
|
109
|
-
const rows = this.
|
|
110
|
-
SELECT advisory_id, introduced, fixed, last_affected
|
|
111
|
-
FROM advisory_packages
|
|
112
|
-
WHERE ecosystem = ? AND package_name = ?
|
|
113
|
-
`).all(pkg.ecosystem, pkg.name);
|
|
164
|
+
const rows = this.findMatchingIdsStatement.all(pkg.ecosystem, pkg.name);
|
|
114
165
|
const ids = new Set();
|
|
115
166
|
for (const row of rows) {
|
|
116
167
|
if (versionMatchesRange(pkg.version, row)) {
|
|
@@ -4,6 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { unzipSync } from "fflate";
|
|
5
5
|
import { LocalAdvisoryDatabase } from "./local-db.js";
|
|
6
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;
|
|
7
8
|
export function getDefaultAdvisoryDbPath(outputPath) {
|
|
8
9
|
if (outputPath) {
|
|
9
10
|
return path.resolve(outputPath);
|
|
@@ -55,7 +56,7 @@ export async function syncOsvAdvisories(options = {}) {
|
|
|
55
56
|
});
|
|
56
57
|
await yieldToEventLoop();
|
|
57
58
|
const archiveEntries = unzipSync(zippedBytes);
|
|
58
|
-
const advisoryEntries = Object.
|
|
59
|
+
const advisoryEntries = Object.entries(archiveEntries).filter(([entryName]) => entryName.endsWith(".json"));
|
|
59
60
|
onProgress?.({
|
|
60
61
|
phase: "extract",
|
|
61
62
|
totalEntries: Object.keys(archiveEntries).length,
|
|
@@ -65,18 +66,16 @@ export async function syncOsvAdvisories(options = {}) {
|
|
|
65
66
|
await yieldToEventLoop();
|
|
66
67
|
const db = new LocalAdvisoryDatabase(dbPath);
|
|
67
68
|
try {
|
|
69
|
+
const parsedVulns = [];
|
|
68
70
|
let advisoryCount = 0;
|
|
69
71
|
const progressInterval = 250;
|
|
70
|
-
for (const [
|
|
71
|
-
if (!entryName.endsWith(".json")) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
72
|
+
for (const [, bytes] of advisoryEntries) {
|
|
74
73
|
const text = Buffer.from(bytes).toString("utf8");
|
|
75
74
|
const vuln = JSON.parse(text);
|
|
76
75
|
if (!vuln.id) {
|
|
77
76
|
continue;
|
|
78
77
|
}
|
|
79
|
-
|
|
78
|
+
parsedVulns.push(vuln);
|
|
80
79
|
advisoryCount += 1;
|
|
81
80
|
if (advisoryCount === 1 ||
|
|
82
81
|
advisoryCount % progressInterval === 0 ||
|
|
@@ -90,6 +89,11 @@ export async function syncOsvAdvisories(options = {}) {
|
|
|
90
89
|
await yieldToEventLoop();
|
|
91
90
|
}
|
|
92
91
|
}
|
|
92
|
+
db.bulkUpsertVulnerabilities(parsedVulns);
|
|
93
|
+
db.setMetadata({
|
|
94
|
+
lastSyncAt: new Date().toISOString(),
|
|
95
|
+
sourceUrl,
|
|
96
|
+
});
|
|
93
97
|
onProgress?.({
|
|
94
98
|
phase: "complete",
|
|
95
99
|
advisoryCount,
|
package/dist/index.js
CHANGED
|
@@ -62,6 +62,8 @@ async function main() {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
let advisorySourceLine;
|
|
65
|
+
let advisoryDbFreshnessLine = null;
|
|
66
|
+
let advisoryDbWarning = null;
|
|
65
67
|
try {
|
|
66
68
|
const advisorySource = createAdvisorySource({
|
|
67
69
|
osvUrl: options.osvUrl,
|
|
@@ -69,6 +71,15 @@ async function main() {
|
|
|
69
71
|
offlineDb: options.offlineDb,
|
|
70
72
|
});
|
|
71
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
|
+
}
|
|
72
83
|
advisorySource.cleanup();
|
|
73
84
|
}
|
|
74
85
|
catch (error) {
|
|
@@ -81,6 +92,12 @@ async function main() {
|
|
|
81
92
|
console.log(chalk.gray("Offline mode:") + " " + chalk.yellow("enabled") + " " + chalk.gray("(no external advisory calls will be made)"));
|
|
82
93
|
}
|
|
83
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
|
+
}
|
|
84
101
|
const scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
85
102
|
const packages = scanInput.packages;
|
|
86
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);
|
|
@@ -155,3 +172,32 @@ function formatAdvisorySourceLine(sourceLabel) {
|
|
|
155
172
|
}
|
|
156
173
|
return `${match[1]} (${chalk.cyan(match[2])})`;
|
|
157
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/scanner.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createSpinner } from "./output/spinner.js";
|
|
|
6
6
|
import { OsvAdvisorySource } from "./advisory/osv-advisory-source.js";
|
|
7
7
|
import { LocalAdvisorySource } from "./advisory/local-advisory-source.js";
|
|
8
8
|
import { LocalAdvisoryDatabase } from "./advisory/local-db.js";
|
|
9
|
-
import { getDefaultAdvisoryDbPath } from "./advisory/osv-sync.js";
|
|
9
|
+
import { ADVISORY_DB_STALE_AFTER_MS, getDefaultAdvisoryDbPath } from "./advisory/osv-sync.js";
|
|
10
10
|
import { resolveRecommendedParentUpgrade } from "./remediation/parent-upgrade.js";
|
|
11
11
|
export function createAdvisorySource(options) {
|
|
12
12
|
const offline = !!options?.offline || !!options?.offlineDb;
|
|
@@ -17,6 +17,8 @@ export function createAdvisorySource(options) {
|
|
|
17
17
|
advisorySource: new LocalAdvisorySource(db),
|
|
18
18
|
offline: true,
|
|
19
19
|
sourceLabel: `local advisory database (${dbPath})`,
|
|
20
|
+
advisoryDbMetadata: db.getMetadata(),
|
|
21
|
+
advisoryDbIsStale: isAdvisoryDbStale(db.getMetadata()),
|
|
20
22
|
cleanup: () => db.close(),
|
|
21
23
|
};
|
|
22
24
|
}
|
|
@@ -26,6 +28,8 @@ export function createAdvisorySource(options) {
|
|
|
26
28
|
sourceLabel: options?.osvUrl
|
|
27
29
|
? `custom OSV endpoint (${options.osvUrl})`
|
|
28
30
|
: "OSV (https://api.osv.dev)",
|
|
31
|
+
advisoryDbMetadata: null,
|
|
32
|
+
advisoryDbIsStale: false,
|
|
29
33
|
cleanup: () => { },
|
|
30
34
|
};
|
|
31
35
|
}
|
|
@@ -193,6 +197,16 @@ export async function scanPackages(packages, batchSize, options) {
|
|
|
193
197
|
sourceContext.cleanup();
|
|
194
198
|
}
|
|
195
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;
|
|
209
|
+
}
|
|
196
210
|
function classifyRelationship(paths) {
|
|
197
211
|
if (paths.length === 0)
|
|
198
212
|
return "unknown";
|