vigievuln 1.1.2 → 1.2.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/CHANGELOG.md +25 -0
- package/README.md +51 -141
- package/completions/vigievuln.bash +1 -1
- package/completions/vigievuln.zsh +1 -0
- package/lib/account-client.js +21 -14
- package/lib/account-session.js +6 -2
- package/lib/advisory-compression.js +25 -0
- package/lib/advisory-fixes.js +21 -0
- package/lib/advisory-store-sqlite.js +156 -0
- package/lib/advisory-store.js +484 -0
- package/lib/airgap-project.js +117 -0
- package/lib/application-plugins/runner.js +22 -13
- package/lib/application-plugins/wordpress.js +4 -3
- package/lib/application-providers/live-snapshot.js +1 -12
- package/lib/application-providers/snapshot-cache.js +27 -0
- package/lib/application-providers/wordfence-client.js +3 -3
- package/lib/attribution.js +2 -2
- package/lib/cache-archive-sqlite.js +215 -0
- package/lib/cache-archive.js +357 -26
- package/lib/cache-db.js +142 -0
- package/lib/cache-directory.js +18 -74
- package/lib/cache-policy.js +25 -0
- package/lib/cache-repository.js +48 -0
- package/lib/cache-startup.js +54 -0
- package/lib/certfr.js +9 -9
- package/lib/cli-command-routing.js +29 -6
- package/lib/cli-groups.js +32 -3
- package/lib/cli-project-commands.js +47 -6
- package/lib/cli-setup.js +300 -0
- package/lib/codecs/binary/pe-metadata.js +79 -0
- package/lib/codecs/binary/scan.js +4 -3
- package/lib/codecs/binary.codec.js +4 -2
- package/lib/codecs/composer/registry.js +8 -6
- package/lib/codecs/go/parse.js +7 -9
- package/lib/codecs/go/registry.js +7 -5
- package/lib/codecs/go.codec.js +5 -0
- package/lib/codecs/maven.codec.js +73 -8
- package/lib/codecs/npm/collect.js +12 -5
- package/lib/codecs/npm/parse.js +12 -5
- package/lib/codecs/npm/registry.js +42 -12
- package/lib/codecs/nuget/registry.js +8 -6
- package/lib/codecs/pypi/registry.js +8 -6
- package/lib/codecs/ruby/registry.js +7 -5
- package/lib/compression-dictionary.js +5 -0
- package/lib/coverage-diagnostics.js +26 -0
- package/lib/cve-download.js +157 -41
- package/lib/cve-legacy-ranges.js +59 -0
- package/lib/cve-match.js +85 -17
- package/lib/cve-npm-proxy.js +29 -0
- package/lib/cve-report.js +145 -58
- package/lib/cve-version-verdict.js +77 -0
- package/lib/deps-descriptor.js +8 -3
- package/lib/epss.js +13 -8
- package/lib/euvd.js +32 -8
- package/lib/gcve-feed.js +103 -0
- package/lib/gcve-index.js +181 -0
- package/lib/gcve.js +1 -1
- package/lib/github-publisher-maven.js +40 -0
- package/lib/hash-id.js +5 -5
- package/lib/hosted-proxy.js +6 -1
- package/lib/i18n.js +31 -8
- package/lib/json-cache.js +18 -0
- package/lib/json-export.js +16 -2
- package/lib/kev.js +7 -8
- package/lib/line-stream.js +23 -0
- package/lib/maven-airgap.js +80 -0
- package/lib/maven-cache.js +21 -0
- package/lib/maven-license.js +2 -1
- package/lib/maven-presence.js +2 -2
- package/lib/maven-reactor.js +23 -14
- package/lib/maven-repo.js +11 -6
- package/lib/merge-sources.js +25 -18
- package/lib/native-advisories.js +268 -0
- package/lib/nvd-bulk.js +145 -0
- package/lib/nvd-package-ranges.js +109 -0
- package/lib/nvd.js +52 -24
- package/lib/osv-db.js +253 -59
- package/lib/osv-legacy.js +57 -0
- package/lib/osv.js +241 -168
- package/lib/outdated.js +11 -12
- package/lib/package-metadata.js +141 -0
- package/lib/package-versions.js +52 -0
- package/lib/packagist-audit.js +6 -6
- package/lib/provenance.js +73 -19
- package/lib/providers/common.js +11 -1
- package/lib/providers/gcve.js +17 -0
- package/lib/providers/github.js +1 -0
- package/lib/providers/index.js +49 -26
- package/lib/providers/vigievuln.js +7 -0
- package/lib/proxy-cache.js +1 -1
- package/lib/proxy-scope.js +59 -0
- package/lib/proxy-throttle.js +71 -0
- package/lib/resource-cache/engine.js +36 -9
- package/lib/resource-cache/sqlite-store.js +95 -0
- package/lib/resource-cache/validate.js +5 -0
- package/lib/retire.js +24 -24
- package/lib/ruby-version.js +36 -0
- package/lib/sarif-export.js +1 -1
- package/lib/sbom-export.js +11 -7
- package/lib/snyk.js +32 -20
- package/lib/source-profile.js +67 -0
- package/lib/sqlite-driver.js +46 -0
- package/lib/transitive.js +69 -34
- package/lib/unmanaged.js +2 -1
- package/lib/vigievuln-advisories.js +47 -0
- package/package.json +7 -6
- package/vigievuln.js +380 -107
package/lib/osv.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* POST /v1/query for a single dep
|
|
12
12
|
* GET /v1/vulns/{id} to fetch full details
|
|
13
13
|
*
|
|
14
|
-
* Cached responses live in ~/.fad-checker/osv-cache/ for
|
|
14
|
+
* Cached responses live in ~/.fad-checker/osv-cache/ for 4h.
|
|
15
15
|
*
|
|
16
16
|
* @author: N.BRAUN
|
|
17
17
|
* @email: pp9ping@gmail.com
|
|
@@ -21,7 +21,6 @@ const path = require("path");
|
|
|
21
21
|
const os = require("os");
|
|
22
22
|
|
|
23
23
|
const OSV_CACHE_DIR = path.join(require("./cache-directory").getCacheDir(), "osv-cache");
|
|
24
|
-
const OSV_CACHE_TTL_MS = 12 * 3600 * 1000;
|
|
25
24
|
const OSV_BASE = "https://api.osv.dev";
|
|
26
25
|
const BATCH_SIZE = 800; // OSV limit is 1000; stay under for safety
|
|
27
26
|
|
|
@@ -34,32 +33,8 @@ const BATCH_SIZE = 800; // OSV limit is 1000; stay under for safety
|
|
|
34
33
|
* contains `_`; `%` keeps distinct versions distinct.
|
|
35
34
|
*/
|
|
36
35
|
function cacheKey(g, a, v, ecosystem = "maven") {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const safeV = String(v == null ? "none" : v).replace(/[^A-Za-z0-9._+-]/g, "%");
|
|
40
|
-
return `${ecosystem}__${safeG}__${safeA}__${safeV}.json`;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// OFFLINE bypasses the TTL (same rule as lib/nvd.js): the warmed cache is the
|
|
44
|
-
// ONLY source on an air-gapped box, so a >12h-old entry must still be served —
|
|
45
|
-
// expiring it there silently reported "0 OSV vulns" for every ecosystem.
|
|
46
|
-
// Online keeps enforcing the TTL so entries refresh normally.
|
|
47
|
-
function readCache(name, { ignoreTtl = false, cacheDir = OSV_CACHE_DIR } = {}) {
|
|
48
|
-
const p = path.join(cacheDir, name);
|
|
49
|
-
if (!fs.existsSync(p)) return null;
|
|
50
|
-
try {
|
|
51
|
-
const data = JSON.parse(fs.readFileSync(p, "utf8"));
|
|
52
|
-
// Before schema 2 an empty list could be a failed HTTP request. It is
|
|
53
|
-
// unknown, not proof of a clean package. Keep legacy positive findings.
|
|
54
|
-
if (Array.isArray(data.body) && !data.body.length && data._schema !== 2) return null;
|
|
55
|
-
if (ignoreTtl || Date.now() - data._fetchedAt < OSV_CACHE_TTL_MS) return data.body;
|
|
56
|
-
} catch { /* ignore */ }
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function writeCache(name, body, { cacheDir = OSV_CACHE_DIR } = {}) {
|
|
61
|
-
fs.mkdirSync(cacheDir, { recursive: true });
|
|
62
|
-
fs.writeFileSync(path.join(cacheDir, name), JSON.stringify({ _schema: 2, _fetchedAt: Date.now(), body }));
|
|
36
|
+
const tuple = JSON.stringify([ecosystem, g || "", a || "", String(v == null ? "" : v)]);
|
|
37
|
+
return `query-${require('node:crypto').createHash('sha256').update(tuple).digest('hex')}.json`;
|
|
63
38
|
}
|
|
64
39
|
|
|
65
40
|
const SEVERITY_ALIASES = { MODERATE: "MEDIUM", IMPORTANT: "HIGH", SEVERE: "HIGH", INFO: "LOW" };
|
|
@@ -181,6 +156,50 @@ function branchFixFromOsv(vuln, depKey, depVersion) {
|
|
|
181
156
|
return {};
|
|
182
157
|
}
|
|
183
158
|
|
|
159
|
+
function fixForDependency(dep, vuln, { source } = {}) {
|
|
160
|
+
const maven=dep.ecosystem === 'maven' || dep.ecosystem === 'gradle';
|
|
161
|
+
const ecosystem=osvEcosystemFor(dep);
|
|
162
|
+
if (!maven && !['npm','Go'].includes(ecosystem)) return {fixVersion:null};
|
|
163
|
+
const {compareSemver,vulnVerdict,rangeVerdict,packageKey}=require('./osv-db');
|
|
164
|
+
const name=osvPkgName(dep);
|
|
165
|
+
const affected=(vuln.affected || []).filter(a=>a?.package?.ecosystem===ecosystem &&
|
|
166
|
+
(maven ? a.package.name===name : packageKey(a.package.name,ecosystem)===packageKey(name,ecosystem)));
|
|
167
|
+
const compare=maven ? (a,b)=>{
|
|
168
|
+
// Maven's comparator uses Numbers for numeric components. Never replace
|
|
169
|
+
// an indeterminate comparison with lexical ordering or a rounded number.
|
|
170
|
+
if (!a || !b || /\$\{|\d{16}/.test(a) || /\$\{|\d{16}/.test(b)) return null;
|
|
171
|
+
try { return require('./maven-version').compareMavenVersions(a,b); } catch { return null; }
|
|
172
|
+
} : compareSemver;
|
|
173
|
+
if (!affected.length || !dep.version || compare(String(dep.version),String(dep.version)) !== 0) return {fixVersion:null};
|
|
174
|
+
const candidates=[];
|
|
175
|
+
for(const a of affected) for(const r of (Array.isArray(a.ranges) ? a.ranges : [])) for(const event of (Array.isArray(r?.events) ? r.events : []))
|
|
176
|
+
if(typeof event?.fixed==='string' && compare(event.fixed,String(dep.version)) > 0) candidates.push(event.fixed);
|
|
177
|
+
// Reviewed VV records may prove individual safe versions without proving a
|
|
178
|
+
// continuous range. Never apply this extension to third-party OSV records.
|
|
179
|
+
const exact = new Set();
|
|
180
|
+
if (source === 'vigievuln') for (const a of affected) {
|
|
181
|
+
if (a.database_specific?.vigievuln_partial_versions !== true) continue;
|
|
182
|
+
for (const v of Array.isArray(a.database_specific.unaffected_versions) ? a.database_specific.unaffected_versions : []) {
|
|
183
|
+
if (typeof v === 'string' && compare(v, String(dep.version)) > 0) { candidates.push(v); exact.add(v); }
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
candidates.sort((a,b)=>compare(a,b));
|
|
187
|
+
// A negative must cover every applicable entry, not only the entry that
|
|
188
|
+
// supplied the candidate. In particular unknown/conflicting evidence fails.
|
|
189
|
+
const fixed=candidates.find(v=>vulnVerdict(v,{affected},ecosystem,source === 'vigievuln' ? {source} : {})===false) || null;
|
|
190
|
+
const evidence = fixed && exact.has(fixed) ? {fixEvidence:'explicit-unaffected-version'} : {};
|
|
191
|
+
if (!maven || !fixed) return {fixVersion:fixed,...evidence};
|
|
192
|
+
for(const a of affected) for(const r of (Array.isArray(a.ranges) ? a.ranges : [])) {
|
|
193
|
+
if (rangeVerdict(String(dep.version),r,ecosystem)!==true) continue;
|
|
194
|
+
const branch=branchFixFromOsv({affected:[{...a,ranges:[r]}]},name,dep.version).branchFix;
|
|
195
|
+
if (branch?.fixed && compare(branch.fixed,fixed)===0)
|
|
196
|
+
return {fixVersion:fixed,branchFix:{fixed},...evidence};
|
|
197
|
+
}
|
|
198
|
+
// last_affected only names an affected boundary. It does not identify a
|
|
199
|
+
// concrete release whose safety can be checked against all other ranges.
|
|
200
|
+
return {fixVersion:fixed,...evidence};
|
|
201
|
+
}
|
|
202
|
+
|
|
184
203
|
/** Pick the best CVE id from an OSV vuln (prefer CVE-* aliases over GHSA-*). */
|
|
185
204
|
function pickPrimaryId(vuln) {
|
|
186
205
|
if (vuln.id?.startsWith("CVE-")) return vuln.id;
|
|
@@ -204,10 +223,11 @@ function osvPkgName(dep) {
|
|
|
204
223
|
}
|
|
205
224
|
|
|
206
225
|
/** Convert one OSV vuln to vigievuln match shape. */
|
|
207
|
-
function vulnToMatch(dep, vuln) {
|
|
226
|
+
function vulnToMatch(dep, vuln, opts = {}) {
|
|
208
227
|
const id = pickPrimaryId(vuln);
|
|
209
228
|
const { severity, score } = severityFromOsv(vuln);
|
|
210
229
|
const cvss = cvssInfoFromVuln(vuln);
|
|
230
|
+
const fix = fixForDependency(dep, vuln, opts);
|
|
211
231
|
// `details` (long markdown) is the substantive description; `summary` is just the title.
|
|
212
232
|
// We keep them both: summary as headline, details as body.
|
|
213
233
|
const summary = (vuln.summary || "").trim();
|
|
@@ -234,8 +254,8 @@ function vulnToMatch(dep, vuln) {
|
|
|
234
254
|
...(cvss.version ? { cvssVersion: `CVSS:${cvss.version}` } : {}),
|
|
235
255
|
description,
|
|
236
256
|
summary,
|
|
237
|
-
|
|
238
|
-
|
|
257
|
+
...fix,
|
|
258
|
+
fixEvaluation: fix.fixVersion ? 'verified' : 'unknown',
|
|
239
259
|
ghsa: (vuln.aliases || []).find(a => a.startsWith("GHSA-")) || (vuln.id?.startsWith("GHSA-") ? vuln.id : null),
|
|
240
260
|
published: vuln.published || null,
|
|
241
261
|
modified: vuln.modified || null,
|
|
@@ -254,10 +274,21 @@ function incompleteOsv(message) {
|
|
|
254
274
|
return error;
|
|
255
275
|
}
|
|
256
276
|
|
|
277
|
+
// Preserve the collection time supplied by a proxy instead of presenting a
|
|
278
|
+
// stale snapshot as freshly observed. A proxy without a date is unknown-age.
|
|
279
|
+
function observation(response) {
|
|
280
|
+
const headers = response?.headers;
|
|
281
|
+
const status = headers?.get?.('x-fad-proxy');
|
|
282
|
+
const stamp = Date.parse(headers?.get?.('x-fad-proxy-fetched-at') || '');
|
|
283
|
+
const isProxy = require('./providers').hasProxyRoute();
|
|
284
|
+
const valid = Number.isFinite(stamp) && stamp > 0 && stamp <= Date.now() + 300000;
|
|
285
|
+
return { fetchedAt: valid ? stamp : isProxy ? 1 : Date.now(), stale: status === 'stale' || (isProxy && (!valid || Date.now()-stamp >= require('./cache-policy').DEFAULT_TTL_MS)) };
|
|
286
|
+
}
|
|
287
|
+
|
|
257
288
|
// querybatch can paginate EACH query independently. An empty object is a valid
|
|
258
289
|
// no-findings result; a missing result, an error or an unfinished page is not.
|
|
259
290
|
async function fetchBatchPages(batch, fetcher) {
|
|
260
|
-
const results = batch.map(() => ({ vulns: [] }));
|
|
291
|
+
const results = batch.map(() => ({ vulns: [], fetchedAt: Date.now(), stale: false }));
|
|
261
292
|
let pending = batch.map((query, index) => ({ query, index, seen: new Set() }));
|
|
262
293
|
while (pending.length) {
|
|
263
294
|
const res = await require("./providers").getResource("osv", "packages", {
|
|
@@ -265,14 +296,17 @@ async function fetchBatchPages(batch, fetcher) {
|
|
|
265
296
|
ecosystem: query.package.ecosystem, name: query.package.name, version: query.version,
|
|
266
297
|
...(query.page_token ? { page_token: query.page_token } : {}),
|
|
267
298
|
})),
|
|
268
|
-
}, { fetcher, headers: { "User-Agent": "vigievuln-osv" } });
|
|
299
|
+
}, { fetcher, forceRefresh:true, headers: { "User-Agent": "vigievuln-osv" } });
|
|
269
300
|
if (!res.ok) throw incompleteOsv(`querybatch HTTP ${res.status}`);
|
|
301
|
+
const observed = observation(res);
|
|
270
302
|
const data = await res.json();
|
|
271
303
|
if (!Array.isArray(data?.results) || data.results.length !== pending.length)
|
|
272
304
|
throw incompleteOsv("querybatch returned a missing or truncated result list");
|
|
273
305
|
const next = [];
|
|
274
306
|
for (let i = 0; i < pending.length; i++) {
|
|
275
307
|
const item = data.results[i], slot = pending[i];
|
|
308
|
+
results[slot.index].fetchedAt = Math.min(results[slot.index].fetchedAt, observed.fetchedAt);
|
|
309
|
+
results[slot.index].stale ||= observed.stale;
|
|
276
310
|
if (!item || typeof item !== "object" || Array.isArray(item) || item.error
|
|
277
311
|
|| (item.vulns !== undefined && (!Array.isArray(item.vulns) || !item.vulns.every(v => validVulnId(v?.id)))))
|
|
278
312
|
throw incompleteOsv("querybatch returned an invalid result");
|
|
@@ -291,156 +325,194 @@ async function fetchBatchPages(batch, fetcher) {
|
|
|
291
325
|
}
|
|
292
326
|
|
|
293
327
|
async function queryBatch(deps, opts = {}) {
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (Array.isArray(hit) && hit.every(validVulnId)) {
|
|
308
|
-
indexMap[i] = { cached: hit };
|
|
309
|
-
} else {
|
|
310
|
-
if (offline) missingPackages++;
|
|
311
|
-
indexMap[i] = { queryIdx: queries.length, cacheKey: ck };
|
|
312
|
-
// Ecosystem + package name are both derived from the dep's codec, so
|
|
313
|
-
// adding a new ecosystem (NuGet/Packagist/PyPI) needs no change here.
|
|
314
|
-
const ecosystem = osvEcosystemFor(d);
|
|
315
|
-
const pkgName = osvPkgName(d);
|
|
316
|
-
queries.push({
|
|
317
|
-
package: { name: pkgName, ecosystem },
|
|
318
|
-
version: d.version,
|
|
319
|
-
});
|
|
320
|
-
}
|
|
328
|
+
if (!deps.length) return [];
|
|
329
|
+
const { offline, fetcher = globalThis.fetch, onProgress, onWarning, queryTtlMs = 4 * 3600 * 1000 } = opts;
|
|
330
|
+
const root = opts.cacheDir || require('./cache-directory').getCacheDir();
|
|
331
|
+
const store = opts.store || require('./advisory-store').openAdvisoryStore({cacheDir:root});
|
|
332
|
+
try {
|
|
333
|
+
const tuple = d => ({source:'osv', ecosystem:osvEcosystemFor(d), name:osvPkgName(d), version:String(d.version).trim()});
|
|
334
|
+
const views = [], pending = [], output = new Array(deps.length), warnings = [], reviewedFreshnessNotices = new Set();
|
|
335
|
+
const warn = (type, message) => warnings.push({type,message});
|
|
336
|
+
for (let i=0; i<deps.length; i++) {
|
|
337
|
+
const q=tuple(deps[i]);
|
|
338
|
+
const view=store.getPackageView(q,{ttlMs:queryTtlMs});
|
|
339
|
+
views[i]=view;
|
|
340
|
+
if (!offline && (require('./cache-policy').shouldForceUpdate() || !view.query || !view.query.fresh || view.querySuperseded)) pending.push({index:i, tuple:q});
|
|
321
341
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
342
|
+
if (pending.length) {
|
|
343
|
+
try {
|
|
344
|
+
const fetched=[];
|
|
345
|
+
for (let i=0;i<pending.length;i+=BATCH_SIZE) {
|
|
346
|
+
if (onProgress) onProgress(Math.floor(i/BATCH_SIZE)+1,Math.ceil(pending.length/BATCH_SIZE));
|
|
347
|
+
const part=pending.slice(i,i+BATCH_SIZE);
|
|
348
|
+
try {
|
|
349
|
+
const results=await fetchBatchPages(part.map(({tuple:q})=>({package:{ecosystem:q.ecosystem,name:q.name},version:q.version})),fetcher);
|
|
350
|
+
fetched.push(...results);
|
|
351
|
+
} catch(error) { throw error.code === 'OSV_INCOMPLETE' ? error : incompleteOsv(error.message); }
|
|
330
352
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
353
|
+
const ids=[...new Set(fetched.flatMap(x=>x.vulns.map(v=>v.id)))], details=new Map(), failures=[];
|
|
354
|
+
let cursor=0,done=0;
|
|
355
|
+
await Promise.all(Array.from({length:Math.min(10,ids.length)},async()=>{
|
|
356
|
+
while(cursor<ids.length) {
|
|
357
|
+
const id=ids[cursor++];
|
|
358
|
+
try {
|
|
359
|
+
const r=await require('./providers').getResource('osv','vuln',{id},{fetcher,forceRefresh:true,headers:{'User-Agent':'vigievuln-osv'}});
|
|
360
|
+
if (!r.ok) throw Error(`HTTP ${r.status}`);
|
|
361
|
+
const body=await r.json(); if (body?.id!==id) throw Error('invalid advisory detail');
|
|
362
|
+
details.set(id,{body,...observation(r)});
|
|
363
|
+
} catch(error) { failures.push(`${id}: ${error.message}`); }
|
|
364
|
+
if(onProgress)onProgress(++done,ids.length);
|
|
342
365
|
}
|
|
366
|
+
}));
|
|
367
|
+
if(failures.length)throw incompleteOsv(`${failures.length} advisory detail(s) unavailable (${failures[0]})`);
|
|
368
|
+
const transport=require('./providers').hasProxyRoute()?'proxy':'direct';
|
|
369
|
+
const records=[...details.values()].map(d=>({source:'osv',document:d.body,fetchedAt:d.fetchedAt,provenance:{transport,stale:d.stale}}));
|
|
370
|
+
// Keep revision evidence independently of the write transaction: a full
|
|
371
|
+
// disk must not allow an older API payload to resurrect a known withdrawal.
|
|
372
|
+
const existingRecords=new Map(ids.map(id=>[id,store.getRecord('osv',id)]));
|
|
373
|
+
const incomingRecords=new Map(records.map(record=>[record.document.id,record]));
|
|
374
|
+
const queries=[];
|
|
375
|
+
for(let i=0;i<pending.length;i++) {
|
|
376
|
+
const entry=pending[i], result=fetched[i], ids=[...new Set(result.vulns.map(v=>v.id))];
|
|
377
|
+
const relevant=ids.map(id=>details.get(id));
|
|
378
|
+
const fetchedAt=Math.min(result.fetchedAt,...relevant.map(d=>d.fetchedAt));
|
|
379
|
+
const stale=result.stale || relevant.some(d=>d.stale);
|
|
380
|
+
const documentHashes=Object.fromEntries(ids.map(id=>[id,require('node:crypto').createHash('sha256').update(JSON.stringify(details.get(id).body)).digest('hex')]));
|
|
381
|
+
queries.push({...entry.tuple,ids,fetchedAt,complete:true,provenance:{transport,stale,documentHashes}});
|
|
343
382
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
383
|
+
try {
|
|
384
|
+
// A query is committed only after all its details are durable. Partial
|
|
385
|
+
// failure leaves no new evidence of a clean package.
|
|
386
|
+
if(records.length)await store.importEnvelopes(records);
|
|
387
|
+
for(let i=0;i<queries.length;i+=200)store.commit({queries:queries.slice(i,i+200)});
|
|
388
|
+
} catch(error) {warn('source-unavailable',`OSV: live results could not be saved for offline use (${error.message}).`);}
|
|
389
|
+
const {vulnVerdict,packageKey}=require('./osv-db');
|
|
390
|
+
for(let i=0;i<pending.length;i++) {
|
|
391
|
+
const entry=pending[i],query=queries[i],found=[];
|
|
392
|
+
let savedView=views[entry.index];
|
|
393
|
+
try { savedView=store.getPackageView(entry.tuple,{ttlMs:queryTtlMs}); }
|
|
394
|
+
catch(error) { warn('source-unavailable',`OSV: saved consultation could not be reread (${error.message}); previously read evidence is retained.`); }
|
|
395
|
+
if(savedView.query && savedView.query.fetchedAt>query.fetchedAt) {
|
|
396
|
+
views[entry.index]=savedView;
|
|
397
|
+
if (!savedView.query.fresh) warn('source-stale',`OSV: the response for ${entry.tuple.name}@${entry.tuple.version} predates its saved consultation; newer local evidence is used.`);
|
|
398
|
+
continue;
|
|
357
399
|
}
|
|
400
|
+
if(query.provenance.stale)warn('source-stale',`OSV: the source response was stale or its collection date is unknown for ${entry.tuple.name}@${entry.tuple.version}.`);
|
|
401
|
+
for(const id of query.ids) {
|
|
402
|
+
const fetched=details.get(id).body;
|
|
403
|
+
let existing=existingRecords.get(id);
|
|
404
|
+
try { existing=store.getRecord('osv',id) || existing; }
|
|
405
|
+
catch(error) { warn('source-unavailable',`OSV: saved revision of ${id} could not be reread (${error.message}); previously read revision evidence is retained.`); }
|
|
406
|
+
const winner=require('./advisory-store').selectAdvisoryRecord(incomingRecords.get(id),existing).document;
|
|
407
|
+
if(winner.withdrawn)continue;
|
|
408
|
+
if(JSON.stringify(winner)!==JSON.stringify(fetched)) {
|
|
409
|
+
const relevant=(winner.affected || []).filter(a=>a?.package?.ecosystem===entry.tuple.ecosystem && (entry.tuple.ecosystem === 'Maven' ? a.package.name === entry.tuple.name : packageKey(a.package.name,entry.tuple.ecosystem)===packageKey(entry.tuple.name,entry.tuple.ecosystem)));
|
|
410
|
+
const verdict=relevant.length ? vulnVerdict(entry.tuple.version,{...winner,affected:relevant},entry.tuple.ecosystem) : null;
|
|
411
|
+
if(verdict===null) {warn('osv-coverage',`OSV: a newer revision of ${id} cannot be evaluated for ${entry.tuple.name}@${entry.tuple.version}.`);continue;}
|
|
412
|
+
if(!verdict)continue;
|
|
413
|
+
}
|
|
414
|
+
found.push(vulnToMatch(deps[entry.index],winner));
|
|
415
|
+
}
|
|
416
|
+
output[entry.index]=found;
|
|
358
417
|
}
|
|
418
|
+
} catch(error) {
|
|
419
|
+
if (!opts.allowStaleFallback) throw error;
|
|
420
|
+
warn('source-unavailable',`OSV: refresh failed; cached advisories are used with incomplete coverage (${error.message}).`);
|
|
421
|
+
}
|
|
359
422
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
if (
|
|
375
|
-
|
|
376
|
-
|
|
423
|
+
const {vulnVerdict,packageKey}=require('./osv-db');
|
|
424
|
+
const unverified = new Map();
|
|
425
|
+
for(let i=0;i<deps.length;i++) {
|
|
426
|
+
if(output[i])continue;
|
|
427
|
+
const d=deps[i],q=tuple(d),view=views[i], query=view.query;
|
|
428
|
+
if (query && !query.fresh)
|
|
429
|
+
warn('source-stale',`OSV: package/version consultation for ${q.name}@${q.version} is from ${new Date(query.fetchedAt).toISOString()}.`);
|
|
430
|
+
if (!query && (!view.coverage?.complete || opts.useStoredRanges === false)) {
|
|
431
|
+
if (!unverified.has(q.ecosystem)) unverified.set(q.ecosystem, new Set());
|
|
432
|
+
unverified.get(q.ecosystem).add(`${q.name}@${q.version}`);
|
|
433
|
+
}
|
|
434
|
+
// An exact consultation already covers the package/version. When a
|
|
435
|
+
// newer advisory supersedes it, evaluate that advisory below; the age
|
|
436
|
+
// of an unrelated older catalogue does not make the query stale.
|
|
437
|
+
if (view.coverage && !view.coverage.fresh && !query) warn('source-stale',`OSV: ${q.ecosystem} seed is from ${new Date(view.coverage.fetchedAt).toISOString()}.`);
|
|
438
|
+
const ids=new Set(query?.ids || []), found=[]; let unknown=false;
|
|
439
|
+
for(const item of view.records) {
|
|
440
|
+
const v=item.document;if(v.withdrawn)continue;
|
|
441
|
+
if(item.source==='osv-legacy-maven')warn('osv-coverage',`OSV: legacy Maven advisory ${v.id} is partial; its withdrawal status is unknown.`);
|
|
442
|
+
let affected;
|
|
443
|
+
if(query && require('./advisory-store').queryCoversRecord(query,item)) affected=ids.has(v.id);
|
|
444
|
+
else if(opts.useStoredRanges === false) { unknown=true; continue; }
|
|
445
|
+
else {
|
|
446
|
+
const relevant=(v.affected || []).filter(a=>a?.package?.ecosystem===q.ecosystem && (q.ecosystem === 'Maven' ? a.package.name === q.name : packageKey(a.package.name,q.ecosystem)===packageKey(q.name,q.ecosystem)));
|
|
447
|
+
affected=relevant.length ? vulnVerdict(q.version,{...v,affected:relevant},q.ecosystem) : ids.has(v.id) ? true : false;
|
|
448
|
+
}
|
|
449
|
+
if(affected===null)unknown=true;else if(affected)found.push(vulnToMatch(d,v));
|
|
450
|
+
}
|
|
451
|
+
if(unknown)warn('osv-coverage',`OSV: at least one advisory for ${q.name}@${q.version} has a version range that cannot be evaluated.`);
|
|
452
|
+
output[i]=found;
|
|
377
453
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
{ fetcher, headers: { "User-Agent": "vigievuln-osv" } });
|
|
401
|
-
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
402
|
-
const body = await r.json();
|
|
403
|
-
if (body?.id !== id) throw new Error("invalid advisory detail");
|
|
404
|
-
detailById.set(id, body);
|
|
405
|
-
writeCache(detailCacheKey, body, { cacheDir });
|
|
406
|
-
} catch (error) { failures.push(`${id}: ${error.message}`); }
|
|
407
|
-
fetched++;
|
|
408
|
-
if (fetched % 5 === 0 || fetched === liveIds.length) printOsvProgress();
|
|
454
|
+
for(const [ecosystem,packages] of unverified) {
|
|
455
|
+
const examples=[...packages].slice(0,3).join(', ');
|
|
456
|
+
warn('osv-coverage',`OSV: offline coverage is incomplete for ${packages.size} ${ecosystem} package/version(s) without a verified consultation (${examples}${packages.size>3?', …':''}). Available advisory ranges were still matched; no finding does not prove those versions clean.`);
|
|
457
|
+
}
|
|
458
|
+
// VigieVuln's reviewed advisories are an independent source in the local
|
|
459
|
+
// advisory journal. They remain available offline and never inherit OSV's
|
|
460
|
+
// coverage claims or source identity.
|
|
461
|
+
for(let i=0;i<deps.length;i++) {
|
|
462
|
+
const d=deps[i],q=tuple(d);
|
|
463
|
+
const ownQuery=store.getQuery({source:'vigievuln',ecosystem:q.ecosystem,name:q.name,version:'*'},{ttlMs:queryTtlMs});
|
|
464
|
+
const ownKey=`${q.ecosystem}\0${q.name}`;
|
|
465
|
+
if(ownQuery&&!ownQuery.fresh&&!reviewedFreshnessNotices.has(ownKey)){reviewedFreshnessNotices.add(ownKey);onWarning?.({type:'source-stale',message:`VigieVuln: reviewed advisory consultation for ${q.name} is from ${new Date(ownQuery.fetchedAt).toISOString()}.`});}
|
|
466
|
+
for(const item of store.getPackageRecords(q.ecosystem,q.name,{source:'vigievuln'})) {
|
|
467
|
+
const v=item.document;
|
|
468
|
+
if(v.withdrawn)continue;
|
|
469
|
+
if(!require('./vigievuln-advisories').isCurrentForPackage(store,q,item))continue;
|
|
470
|
+
const relevant=(v.affected||[]).filter(a=>a?.package?.ecosystem===q.ecosystem && typeof a.package.name==='string' && (q.ecosystem==='Maven' ? a.package.name===q.name : packageKey(a.package.name,q.ecosystem)===packageKey(q.name,q.ecosystem)));
|
|
471
|
+
const verdict=relevant.length ? vulnVerdict(q.version,{...v,affected:relevant},q.ecosystem,{source:'vigievuln'}) : null;
|
|
472
|
+
if(verdict===null && relevant.length) warn('source-unavailable',`VigieVuln: ${v.id} has only partial version evidence for ${q.name}@${q.version}.`);
|
|
473
|
+
if(verdict===true){
|
|
474
|
+
const match=vulnToMatch(d,v,{source:'vigievuln'});match.source='vigievuln';if(/^VV:CVE-\d{4}-\d{4,}$/.test(v.id||''))match.cve.aliases=[...new Set([...match.cve.aliases,v.id])];match.cve.curation=relevant[0]?.database_specific?.vigievuln_curation || v.curation;
|
|
475
|
+
output[i].push(match);
|
|
409
476
|
}
|
|
410
|
-
}
|
|
411
|
-
await Promise.all(workers);
|
|
412
|
-
printOsvProgress(true);
|
|
413
|
-
if (failures.length) throw incompleteOsv(`${failures.length} advisory detail(s) unavailable (${failures[0]})`);
|
|
477
|
+
}
|
|
414
478
|
}
|
|
415
|
-
|
|
416
|
-
for
|
|
417
|
-
if
|
|
418
|
-
|
|
419
|
-
message
|
|
420
|
-
|
|
421
|
-
|
|
479
|
+
const staleWarnings=warnings.filter(w=>w.type==='source-stale');
|
|
480
|
+
for(const warning of warnings)if(warning.type!=='source-stale')onWarning?.(warning);
|
|
481
|
+
if(staleWarnings.length===1)onWarning?.(staleWarnings[0]);
|
|
482
|
+
else if(staleWarnings.length>1) {
|
|
483
|
+
const dates=staleWarnings.flatMap(w=>w.message.match(/\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z/g)||[]).sort();
|
|
484
|
+
const age=dates.length ? ` Oldest saved data: ${dates[0]}.` : '';
|
|
485
|
+
const older=staleWarnings.some(w=>w.message.includes('predates')) ? ' A response predates a newer saved consultation.' : '';
|
|
486
|
+
onWarning?.({type:'source-stale',message:`OSV: ${staleWarnings.length} freshness notices; cached advisory data is used${offline ? ' offline' : ''}.${age}${older}`});
|
|
487
|
+
}
|
|
488
|
+
return output.flat();
|
|
489
|
+
} finally { if (!opts.store) store.close(); }
|
|
422
490
|
}
|
|
423
491
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
492
|
+
/** Reviewed-source matching also works when OSV is explicitly disabled. */
|
|
493
|
+
function queryReviewedForDeps(resolvedDeps,opts={}) {
|
|
494
|
+
const store=opts.store||require('./advisory-store').openAdvisoryStore({cacheDir:opts.cacheDir||require('./cache-directory').getCacheDir()});
|
|
495
|
+
try {
|
|
496
|
+
const {vulnVerdict,packageKey}=require('./osv-db');const matches=[],warned=new Set();
|
|
497
|
+
for(const d of resolvedDeps.values()) {
|
|
498
|
+
if(!d || d.scope==='parent' || d.provenance==='binary')continue;
|
|
499
|
+
const ecosystem=osvEcosystemFor(d),name=osvPkgName(d);if(!name)continue;
|
|
500
|
+
const ownQuery=store.getQuery({source:'vigievuln',ecosystem,name,version:'*'},{ttlMs:opts.queryTtlMs ?? 4 * 3600000});
|
|
501
|
+
if(ownQuery&&!ownQuery.fresh&&!warned.has(`${ecosystem}\0${name}`)){warned.add(`${ecosystem}\0${name}`);opts.onWarning?.({type:'source-stale',message:`VigieVuln: reviewed advisory consultation for ${name} is from ${new Date(ownQuery.fetchedAt).toISOString()}.`});}
|
|
502
|
+
for(const version of d.versions?.length?d.versions:[d.version]) {
|
|
503
|
+
if(!version||/\$\{|SNAPSHOT/i.test(version))continue;
|
|
504
|
+
for(const item of store.getPackageRecords(ecosystem,name,{source:'vigievuln'})) {
|
|
505
|
+
if(item.document.withdrawn || !require('./vigievuln-advisories').isCurrentForPackage(store,{ecosystem,name},item))continue;
|
|
506
|
+
const relevant=(item.document.affected||[]).filter(a=>a?.package?.ecosystem===ecosystem && typeof a.package.name==='string' && (ecosystem==='Maven'?a.package.name===name:packageKey(a.package.name,ecosystem)===packageKey(name,ecosystem)));
|
|
507
|
+
if(!relevant.length)continue;
|
|
508
|
+
const verdict=vulnVerdict(String(version),{...item.document,affected:relevant},ecosystem,{source:'vigievuln'});
|
|
509
|
+
if(verdict===null)opts.onWarning?.({type:'source-unavailable',message:`VigieVuln: ${item.document.id} has only partial version evidence for ${name}@${version}.`});
|
|
510
|
+
if(verdict===true){const dep=version===d.version?d:{...d,version};const match=vulnToMatch(dep,item.document,{source:'vigievuln'});match.source='vigievuln';if(/^VV:CVE-\d{4}-\d{4,}$/.test(item.document.id||''))match.cve.aliases=[...new Set([...match.cve.aliases,item.document.id])];match.cve.curation=relevant[0]?.database_specific?.vigievuln_curation || item.document.curation;matches.push(match);}
|
|
439
511
|
}
|
|
440
|
-
matches.push(vulnToMatch(dep, vuln));
|
|
441
512
|
}
|
|
442
513
|
}
|
|
443
514
|
return matches;
|
|
515
|
+
} finally { if (!opts.store) store.close(); }
|
|
444
516
|
}
|
|
445
517
|
|
|
446
518
|
/**
|
|
@@ -449,7 +521,7 @@ function runMatches(deps, indexMap, detailById) {
|
|
|
449
521
|
async function queryOsvForDeps(resolvedDeps, opts = {}) {
|
|
450
522
|
const deps = [];
|
|
451
523
|
for (const d of resolvedDeps.values()) {
|
|
452
|
-
if (d.scope === "parent") continue; //
|
|
524
|
+
if (d.scope === "parent" || d.provenance === 'binary') continue; // native metadata is not an authenticated package identity
|
|
453
525
|
// Query every distinct concrete version (e.g. two profiles pinning the
|
|
454
526
|
// same g:a), not just the representative highest — otherwise a vuln that
|
|
455
527
|
// only affects a lower-versioned variant would be missed.
|
|
@@ -471,6 +543,7 @@ async function queryOsvForDeps(resolvedDeps, opts = {}) {
|
|
|
471
543
|
}
|
|
472
544
|
|
|
473
545
|
module.exports = {
|
|
546
|
+
queryReviewedForDeps,
|
|
474
547
|
cacheKey,
|
|
475
548
|
queryOsvForDeps,
|
|
476
549
|
queryBatch,
|
package/lib/outdated.js
CHANGED
|
@@ -30,24 +30,20 @@ for (const [id, fw] of Object.entries(COMPOSER_FRAMEWORKS)) {
|
|
|
30
30
|
const CACHE_DIR = path.join(require("./cache-directory").getCacheDir());
|
|
31
31
|
const EOL_CACHE_PATH = path.join(CACHE_DIR, "eol-cache.json");
|
|
32
32
|
const VERSION_CACHE_PATH = path.join(CACHE_DIR, "version-cache.json");
|
|
33
|
-
const EOL_CACHE_MAX_AGE_MS =
|
|
34
|
-
const VERSION_CACHE_MAX_AGE_MS =
|
|
33
|
+
const EOL_CACHE_MAX_AGE_MS = 4 * 3600 * 1000; // 4 hours
|
|
34
|
+
const VERSION_CACHE_MAX_AGE_MS = 4 * 3600 * 1000; // 4 hours
|
|
35
35
|
|
|
36
36
|
function loadJsonCache(file) {
|
|
37
|
-
|
|
38
|
-
catch { return { meta: { fetchedAt: 0 }, entries: {} }; }
|
|
37
|
+
return require('./json-cache').load(CACHE_DIR,path.basename(file),{ meta: { fetchedAt: 0 }, entries: {} });
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
function saveJsonCache(file, data) {
|
|
42
|
-
|
|
43
|
-
fs.mkdirSync(CACHE_DIR, { recursive: true });
|
|
44
|
-
fs.writeFileSync(file, JSON.stringify(data));
|
|
45
|
-
} catch { /* ignore */ }
|
|
41
|
+
require('./json-cache').save(CACHE_DIR,path.basename(file),data);
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
function isEolCacheFresh(maxAge = EOL_CACHE_MAX_AGE_MS) {
|
|
49
45
|
const c = loadJsonCache(EOL_CACHE_PATH);
|
|
50
|
-
return c.meta?.fetchedAt && (
|
|
46
|
+
return c.meta?.fetchedAt && require('./cache-policy').fresh(c.meta.fetchedAt, maxAge);
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
// -------- EOL via endoflife.date --------
|
|
@@ -120,7 +116,7 @@ function findEolProduct(dep) {
|
|
|
120
116
|
// a legacy file (global stamp only) is normalised by normalizeEolCache() at load time.
|
|
121
117
|
function eolEntryFresh(cache, product, now = Date.now()) {
|
|
122
118
|
const ts = cache.fetchedAt?.[product] ?? cache.meta?.fetchedAt ?? 0;
|
|
123
|
-
return ts > 0 && (
|
|
119
|
+
return ts > 0 && require('./cache-policy').fresh(ts, EOL_CACHE_MAX_AGE_MS, now);
|
|
124
120
|
}
|
|
125
121
|
|
|
126
122
|
/**
|
|
@@ -618,7 +614,8 @@ function parseMavenMetadataLatest(xml) {
|
|
|
618
614
|
async function checkOutdatedDeps(resolvedDeps, opts = {}) {
|
|
619
615
|
const { verbose, offline, concurrency = 8, repos, onProgress } = opts;
|
|
620
616
|
const cache = loadJsonCache(VERSION_CACHE_PATH);
|
|
621
|
-
const fresh = !require("./providers").hasHostedProxy() && cache.meta?.fetchedAt && (
|
|
617
|
+
const fresh = !require("./providers").hasHostedProxy() && cache.meta?.fetchedAt && require('./cache-policy').fresh(cache.meta.fetchedAt, VERSION_CACHE_MAX_AGE_MS);
|
|
618
|
+
const previous = !fresh && !offline ? {entries:cache.entries, fetchedAt:cache.meta?.fetchedAt} : null;
|
|
622
619
|
if (!fresh && !offline) cache.entries = {};
|
|
623
620
|
// Maven Central only — npm/composer/pypi/nuget have their own registries (codec.checkRegistry).
|
|
624
621
|
// Transitives are excluded BEFORE fetching: the Outdated chapter only reports deps you
|
|
@@ -673,7 +670,9 @@ async function checkOutdatedDeps(resolvedDeps, opts = {}) {
|
|
|
673
670
|
|
|
674
671
|
if (!offline) {
|
|
675
672
|
if (!fresh) cache.meta = { fetchedAt: Date.now() };
|
|
676
|
-
|
|
673
|
+
// Hosted responses must be refreshed on the next online run, but the
|
|
674
|
+
// successful answers still belong in an exported air-gapped cache.
|
|
675
|
+
require('./cache-policy').preserveEntries(cache, previous); saveJsonCache(VERSION_CACHE_PATH, cache);
|
|
677
676
|
}
|
|
678
677
|
results.sort((a, b) => `${a.dep.groupId}:${a.dep.artifactId}`.localeCompare(`${b.dep.groupId}:${b.dep.artifactId}`));
|
|
679
678
|
return results;
|