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/cve-download.js
CHANGED
|
@@ -47,8 +47,8 @@ const KNOWN_JAVA_VENDORS = new Set([
|
|
|
47
47
|
]);
|
|
48
48
|
|
|
49
49
|
// Curated CPE vendor:product → Maven coord map, shared with lib/cpe.js. Used
|
|
50
|
-
// here at index-build time to
|
|
51
|
-
//
|
|
50
|
+
// here at index-build time to retain product-only Java records as lookup
|
|
51
|
+
// candidates. Such a mapping does not establish an exact package identity.
|
|
52
52
|
let COORD_MAP_CACHE = null;
|
|
53
53
|
function coordMap() {
|
|
54
54
|
if (!COORD_MAP_CACHE) {
|
|
@@ -83,12 +83,64 @@ function curatedCoordsFor(vendor, product) {
|
|
|
83
83
|
return [...out];
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
// A named module is narrower than a product family. Resolve it only through
|
|
87
|
+
// our existing vendor/coordinate catalogue, with matching product AND module
|
|
88
|
+
// names and a unique coordinate. Never fan a framework advisory out to modules.
|
|
89
|
+
function curatedModuleCoordsFor(a) {
|
|
90
|
+
if (a.packageName || a.packageURL || a.purl || a.collectionURL || !Array.isArray(a.modules)) return [];
|
|
91
|
+
if (!a.versions?.some(v => v.versionType === 'maven')) return [];
|
|
92
|
+
const vendorTokens = String(a.vendor || '').toLowerCase().split(/[^a-z0-9.]+|\./).filter(Boolean);
|
|
93
|
+
const product = String(a.product || '').toLowerCase();
|
|
94
|
+
if (!a.modules.some(m => typeof m === 'string' && m.toLowerCase() === product)) return [];
|
|
95
|
+
const candidates = new Set();
|
|
96
|
+
for (const [vendorProduct, coords] of Object.entries(coordMap().byVendorProduct || {})) {
|
|
97
|
+
if (!vendorTokens.includes(vendorProduct.split(':')[0])) continue;
|
|
98
|
+
for (const c of coords) if (c.split(':')[1] === product) candidates.add(c);
|
|
99
|
+
}
|
|
100
|
+
return candidates.size === 1 ? [...candidates] : [];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Only a coordinate actually named by the CNA is evidence of an exact Maven
|
|
104
|
+
// package. A product name, CPE, repository URL or curated mapping is not.
|
|
105
|
+
function explicitMavenCoordinate(affected) {
|
|
106
|
+
const valid = value => /^[A-Za-z0-9_.-]+:[A-Za-z0-9_.-]+$/.test(value);
|
|
107
|
+
let found = null;
|
|
108
|
+
const record = coord => {
|
|
109
|
+
if (found && found !== coord) return false;
|
|
110
|
+
found = coord; return true;
|
|
111
|
+
};
|
|
112
|
+
for (const value of [affected?.packageURL, affected?.purl, affected?.packageName]) {
|
|
113
|
+
if (typeof value !== 'string') continue;
|
|
114
|
+
const name = value.trim();
|
|
115
|
+
if (value === affected?.packageName && valid(name)) {
|
|
116
|
+
// A contradictory registry is not Maven identity evidence. Unknown
|
|
117
|
+
// repository hosts also cannot safely establish their ecosystem.
|
|
118
|
+
if (affected.collectionURL) {
|
|
119
|
+
let host;
|
|
120
|
+
try { host = new URL(affected.collectionURL).hostname.toLowerCase(); } catch { return null; }
|
|
121
|
+
if (!/^(?:repo1\.maven\.org|repo\.maven\.apache\.org|central\.sonatype\.com|repository\.jboss\.org|repo\.spring\.io|maven\.google\.com)$/.test(host)) return null;
|
|
122
|
+
}
|
|
123
|
+
if (!record(name)) return null;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
// Versioned or qualified purls impose additional constraints which the
|
|
127
|
+
// CVE version ranges alone cannot safely establish.
|
|
128
|
+
const m = /^pkg:maven\/([^/?#@]+)\/([^/?#@]+)$/i.exec(name);
|
|
129
|
+
if (m) try {
|
|
130
|
+
const coord = `${decodeURIComponent(m[1])}:${decodeURIComponent(m[2])}`;
|
|
131
|
+
if (!valid(coord) || !record(coord)) return null;
|
|
132
|
+
} catch { return null; }
|
|
133
|
+
else if (/^pkg:/i.test(name) || value === affected?.purl) return null;
|
|
134
|
+
}
|
|
135
|
+
return found;
|
|
136
|
+
}
|
|
137
|
+
|
|
86
138
|
const PRODUCT_HEURISTIC = /^(spring-|jackson-|commons-|hibernate-|netty-|guava|log4j|slf4j|okhttp|httpclient|jetty-|tomcat-|struts-)/;
|
|
87
139
|
|
|
88
140
|
function isMavenRelevant(affected) {
|
|
89
141
|
if (!affected || !Array.isArray(affected)) return false;
|
|
90
142
|
for (const a of affected) {
|
|
91
|
-
if (
|
|
143
|
+
if (explicitMavenCoordinate(a)) return true;
|
|
92
144
|
if (a.collectionURL && /maven|sonatype|jboss\.org|jcenter/i.test(a.collectionURL)) return true;
|
|
93
145
|
if (a.versions?.some(v => v.versionType === "maven")) return true;
|
|
94
146
|
const v = String(a.vendor || "").toLowerCase();
|
|
@@ -150,33 +202,40 @@ function severityFromScore(s) {
|
|
|
150
202
|
* and flag the patched 2.12.2/2.3.1 backport lines.
|
|
151
203
|
*/
|
|
152
204
|
function expandVersionChanges(v) {
|
|
205
|
+
if (v.changes == null || (Array.isArray(v.changes) && !v.changes.length)) return null;
|
|
153
206
|
const changes = Array.isArray(v.changes) ? v.changes.filter(c => c && c.at) : [];
|
|
154
|
-
|
|
155
|
-
const
|
|
207
|
+
const cmp = require('./cve-version-verdict').comparator(v.versionType);
|
|
208
|
+
const unknown = () => [{version:'*', status:'unknown', versionType:v.versionType}];
|
|
209
|
+
if (!cmp || typeof v.version !== 'string' || (v.version !== '0' && cmp(v.version,v.version) !== 0) ||
|
|
210
|
+
!Array.isArray(v.changes) || !['affected','unaffected'].includes(String(v.status || '').toLowerCase()) ||
|
|
211
|
+
changes.length !== v.changes.length || changes.some(c => typeof c.at !== 'string' || cmp(c.at,c.at) !== 0 || !['affected','unaffected'].includes(String(c.status || '').toLowerCase()))) return unknown();
|
|
212
|
+
const compare = (a,b) => a === '0' || b === '0' ? (a === b ? 0 : a === '0' ? -1 : 1) : cmp(a,b);
|
|
213
|
+
const upper = v.lessThan ?? v.lessThanOrEqual;
|
|
214
|
+
if (upper == null || (v.lessThan != null && v.lessThanOrEqual != null) ||
|
|
215
|
+
(upper != null && upper !== '*' && (typeof upper !== 'string' || compare(upper,upper) !== 0 || compare(v.version,upper) >= 0)) ||
|
|
216
|
+
changes.some(c => compare(c.at,v.version) < 0 || (upper && upper !== '*' && compare(c.at,upper) >= 0))) return unknown();
|
|
217
|
+
const sorted = [...changes].sort((a, b) => cmp(a.at, b.at));
|
|
218
|
+
if (sorted.some((c,i) => i && cmp(sorted[i-1].at,c.at) === 0)) return unknown();
|
|
156
219
|
const windows = [];
|
|
157
220
|
let status = String(v.status || "affected").toLowerCase();
|
|
158
221
|
let start = v.version;
|
|
159
222
|
for (const c of sorted) {
|
|
160
|
-
|
|
161
|
-
windows.push({ version: start, status: "affected", versionType: v.versionType, lessThan: c.at, lessThanOrEqual: undefined });
|
|
162
|
-
}
|
|
223
|
+
windows.push({ version: start, status, versionType: v.versionType, lessThan: c.at, lessThanOrEqual: undefined });
|
|
163
224
|
status = String(c.status || "").toLowerCase();
|
|
164
225
|
start = c.at;
|
|
165
226
|
}
|
|
166
|
-
|
|
167
|
-
windows.push({ version: start, status: "affected", versionType: v.versionType, lessThan: v.lessThan, lessThanOrEqual: v.lessThanOrEqual });
|
|
168
|
-
}
|
|
227
|
+
windows.push({ version: start, status, versionType: v.versionType, lessThan: v.lessThan, lessThanOrEqual: v.lessThanOrEqual });
|
|
169
228
|
return windows;
|
|
170
229
|
}
|
|
171
230
|
|
|
172
231
|
function extractAffectedRanges(affected) {
|
|
173
232
|
const out = [];
|
|
174
233
|
for (const a of affected || []) {
|
|
175
|
-
const explicit =
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
const packageNames = explicit ? [explicit] : curatedCoordsFor(a.vendor, a.product);
|
|
234
|
+
const explicit = explicitMavenCoordinate(a);
|
|
235
|
+
// Curated mappings find candidates only; they do not prove that the
|
|
236
|
+
// advisory applies to any particular Maven artifact.
|
|
237
|
+
const moduleCoords = explicit ? [] : curatedModuleCoordsFor(a);
|
|
238
|
+
const packageNames = explicit ? [explicit] : moduleCoords.length ? moduleCoords : curatedCoordsFor(a.vendor, a.product);
|
|
180
239
|
const vendor = a.vendor ? String(a.vendor).toLowerCase() : null;
|
|
181
240
|
const product = a.product ? String(a.product).toLowerCase() : null;
|
|
182
241
|
const versions = Array.isArray(a.versions) ? a.versions : [];
|
|
@@ -187,18 +246,22 @@ function extractAffectedRanges(affected) {
|
|
|
187
246
|
lessThan: v.lessThan,
|
|
188
247
|
lessThanOrEqual: v.lessThanOrEqual,
|
|
189
248
|
}]);
|
|
190
|
-
out.push({ packageName: packageNames[0] || null, packageNames, vendor, product, ranges
|
|
249
|
+
out.push({ packageName: packageNames[0] || null, packageNames, vendor, product, ranges,
|
|
250
|
+
...(a._rangeEvidence ? {rangeEvidence:a._rangeEvidence} : {}),
|
|
251
|
+
defaultStatus: ['affected','unaffected','unknown'].includes(a.defaultStatus) ? a.defaultStatus : 'unknown',
|
|
252
|
+
...(Array.isArray(a.platforms) && a.platforms.length ? { platforms: a.platforms } : {}),
|
|
253
|
+
...(a._affectedProvider ? { affectedProvider: a._affectedProvider } : {}),
|
|
254
|
+
coordinateEvidence: explicit ? 'explicit-coordinate' : moduleCoords.length ? 'curated-module' : 'curated-product' });
|
|
191
255
|
}
|
|
192
256
|
return out;
|
|
193
257
|
}
|
|
194
258
|
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
// records: struts 2.3.x fixed in 2.3.32 vs 2.5.x fixed in 2.5.10.1.)
|
|
259
|
+
// Exclusive upper bounds can name a fix; an inclusive bound is still affected.
|
|
260
|
+
// The matched branch is selected separately by cve-match, not by this summary.
|
|
198
261
|
function fixVersionFromRanges(ranges) {
|
|
199
262
|
let best = null;
|
|
200
263
|
for (const r of ranges) {
|
|
201
|
-
for (const u of [r.lessThan
|
|
264
|
+
for (const u of [r.lessThan]) {
|
|
202
265
|
if (!versionLikeBound(u)) continue;
|
|
203
266
|
const s = String(u).trim();
|
|
204
267
|
if (!best || compareMavenVersions(s, best) > 0) best = s;
|
|
@@ -210,15 +273,23 @@ function fixVersionFromRanges(ranges) {
|
|
|
210
273
|
function extractMavenRelevantCve(json) {
|
|
211
274
|
const cveId = json?.cveMetadata?.cveId || json?.cve?.id;
|
|
212
275
|
if (!cveId) return null;
|
|
213
|
-
const
|
|
276
|
+
const description = extractDescription(json);
|
|
277
|
+
const {normalizeLegacySplitRanges}=require('./cve-legacy-ranges');
|
|
278
|
+
const cna = Array.isArray(json?.containers?.cna?.affected) ? json.containers.cna.affected.map(a => ({...normalizeLegacySplitRanges(a,description,json.containers.cna.x_legacyV4Record), _affectedProvider: {kind:'cna', name:json.containers.cna.providerMetadata?.shortName || null}})) : [];
|
|
279
|
+
// ADPs may provide structured package evidence that is absent from the
|
|
280
|
+
// CNA. Only ingest ADP entries with an explicit Maven coordinate; product
|
|
281
|
+
// names and CPEs remain candidates, not proof of a package identity.
|
|
282
|
+
const adps = Array.isArray(json?.containers?.adp) ? json.containers.adp : [];
|
|
283
|
+
const affected = [...cna, ...adps.flatMap(adp => Array.isArray(adp?.affected)
|
|
284
|
+
? adp.affected.filter(a => explicitMavenCoordinate(a)).map(a => ({...a, _affectedProvider:{kind:'adp', name:adp.providerMetadata?.shortName || null}})) : [])];
|
|
214
285
|
if (!isMavenRelevant(affected)) return null;
|
|
215
286
|
|
|
216
287
|
const { severity, score } = extractSeverity(json);
|
|
217
|
-
const description = extractDescription(json);
|
|
218
288
|
const ranges = extractAffectedRanges(affected);
|
|
219
289
|
|
|
220
290
|
return {
|
|
221
291
|
id: cveId,
|
|
292
|
+
source: "CVEProject",
|
|
222
293
|
severity,
|
|
223
294
|
score,
|
|
224
295
|
description,
|
|
@@ -229,9 +300,12 @@ function extractMavenRelevantCve(json) {
|
|
|
229
300
|
};
|
|
230
301
|
}
|
|
231
302
|
|
|
303
|
+
// Schema 6 also recovers corroborated legacy split ranges and package identity.
|
|
304
|
+
const MAVEN_INDEX_VERSION = 6;
|
|
305
|
+
function isCurrentCveIndex(index) { return index?.meta?.indexVersion === MAVEN_INDEX_VERSION; }
|
|
232
306
|
function newIndex() {
|
|
233
307
|
return {
|
|
234
|
-
meta: { builtAt: null, releaseTag: null, cveCount: 0 },
|
|
308
|
+
meta: { indexVersion: MAVEN_INDEX_VERSION, builtAt: null, releaseTag: null, cveCount: 0 },
|
|
235
309
|
byPackageName: {},
|
|
236
310
|
byProduct: {},
|
|
237
311
|
};
|
|
@@ -241,6 +315,7 @@ function addToIndex(index, cve) {
|
|
|
241
315
|
for (const a of cve.affected) {
|
|
242
316
|
const entry = {
|
|
243
317
|
id: cve.id,
|
|
318
|
+
source: cve.source || "CVEProject",
|
|
244
319
|
severity: cve.severity,
|
|
245
320
|
score: cve.score,
|
|
246
321
|
description: cve.description,
|
|
@@ -248,10 +323,14 @@ function addToIndex(index, cve) {
|
|
|
248
323
|
ranges: a.ranges,
|
|
249
324
|
vendor: a.vendor,
|
|
250
325
|
product: a.product,
|
|
326
|
+
coordinateEvidence: a.coordinateEvidence || 'unknown', defaultStatus: a.defaultStatus || 'unknown',
|
|
327
|
+
...(a.rangeEvidence ? {rangeEvidence:a.rangeEvidence} : {}),
|
|
328
|
+
...(a.platforms?.length ? { platforms: a.platforms } : {}),
|
|
329
|
+
...(a.affectedProvider ? { affectedProviders: [a.affectedProvider] } : {}),
|
|
251
330
|
};
|
|
252
331
|
const names = a.packageNames?.length ? a.packageNames : (a.packageName ? [a.packageName] : []);
|
|
253
332
|
for (const n of names) {
|
|
254
|
-
(index.byPackageName[String(n).toLowerCase()] ||= []).push(entry);
|
|
333
|
+
(index.byPackageName[String(n).toLowerCase()] ||= []).push({ ...entry, exactPackageName: ['explicit-coordinate','curated-module'].includes(a.coordinateEvidence) ? String(n) : null });
|
|
255
334
|
}
|
|
256
335
|
if (a.product) {
|
|
257
336
|
(index.byProduct[a.product] ||= []).push(entry);
|
|
@@ -373,39 +452,72 @@ async function buildCveIndex(extractDir, opts = {}) {
|
|
|
373
452
|
index.meta.builtAt = new Date().toISOString();
|
|
374
453
|
index.meta.releaseTag = releaseTag || null;
|
|
375
454
|
index.meta.cveCount = added;
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
455
|
+
// Keep native records and REJECTED revisions alongside the legacy index.
|
|
456
|
+
// This incremental import cannot infer withdrawals from absent files, so its
|
|
457
|
+
// coverage is recorded as partial until a full reconciliation is available.
|
|
458
|
+
const store = require('./advisory-store').openAdvisoryStore({cacheDir:path.dirname(CVE_DATA_DIR)});
|
|
459
|
+
await require('./native-advisories').importCveDirectory(store,extractDir,{fetchedAt:Date.parse(index.meta.builtAt),provenance:{transport:'direct',releaseTag:releaseTag || null}});
|
|
460
|
+
saveCveIndex(index);
|
|
379
461
|
return index;
|
|
380
462
|
}
|
|
381
463
|
|
|
464
|
+
function saveCveIndex(index) {
|
|
465
|
+
const db=require('./cache-db').getCacheDb(path.dirname(CVE_DATA_DIR));
|
|
466
|
+
const insert=db.prepare('INSERT INTO cve_lookup(kind,lookup_key,source,cve,affected_key,projection_json) VALUES (?,?,?,?,?,?)');
|
|
467
|
+
db.transaction(()=>{
|
|
468
|
+
db.exec('DELETE FROM cve_lookup');
|
|
469
|
+
for(const [kind,buckets] of [['package',index.byPackageName],['product',index.byProduct]])for(const [lookup,entries] of Object.entries(buckets))for(const entry of entries){
|
|
470
|
+
const projection=JSON.stringify(entry),key=require('node:crypto').createHash('sha256').update(projection).digest('hex');
|
|
471
|
+
insert.run(kind,lookup,entry.source||'CVEProject',entry.id,key,projection);
|
|
472
|
+
}
|
|
473
|
+
const stamp=Date.parse(index.meta.builtAt);
|
|
474
|
+
db.prepare(`INSERT INTO cache_snapshots(namespace,fetched_at,complete,stale,record_count,metadata_json) VALUES (?,?,?,?,?,?)
|
|
475
|
+
ON CONFLICT(namespace) DO UPDATE SET fetched_at=excluded.fetched_at,complete=excluded.complete,stale=excluded.stale,
|
|
476
|
+
record_count=excluded.record_count,metadata_json=excluded.metadata_json`).run('cve_lookup',stamp,1,0,index.meta.cveCount,JSON.stringify(index.meta));
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
|
|
382
480
|
function loadCveIndex() {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
481
|
+
const db=require('./cache-db').getCacheDb(path.dirname(CVE_DATA_DIR));
|
|
482
|
+
const snapshot=db.prepare("SELECT metadata_json FROM cache_snapshots WHERE namespace='cve_lookup'").get();
|
|
483
|
+
if(!snapshot)return null;
|
|
484
|
+
const statement=db.prepare('SELECT projection_json FROM cve_lookup WHERE kind=? AND lookup_key=?');
|
|
485
|
+
const bucket=kind=>new Proxy(Object.create(null),{get(_target,key){
|
|
486
|
+
if(typeof key!=='string')return undefined;
|
|
487
|
+
return statement.all(kind,key).map(row=>JSON.parse(row.projection_json));
|
|
488
|
+
}});
|
|
489
|
+
return {meta:JSON.parse(snapshot.metadata_json),byPackageName:bucket('package'),byProduct:bucket('product')};
|
|
386
490
|
}
|
|
387
491
|
|
|
388
|
-
function isCveIndexFresh(maxAgeHours =
|
|
389
|
-
if (!fs.existsSync(CVE_META_PATH)) return false;
|
|
492
|
+
function isCveIndexFresh(maxAgeHours = 4) {
|
|
390
493
|
try {
|
|
391
|
-
const meta
|
|
494
|
+
const meta=loadCveIndex()?.meta;
|
|
392
495
|
if (!meta.builtAt) return false;
|
|
393
|
-
const age = Date.now() - new Date(meta.builtAt).getTime();
|
|
496
|
+
const age = Date.now() - new Date(meta.checkedAt || meta.builtAt).getTime();
|
|
394
497
|
return age < maxAgeHours * 3600 * 1000;
|
|
395
498
|
} catch { return false; }
|
|
396
499
|
}
|
|
397
500
|
|
|
398
501
|
async function downloadCveData(opts = {}) {
|
|
399
|
-
const { verbose, force } = opts;
|
|
502
|
+
const { verbose, force, revalidate } = opts;
|
|
400
503
|
await fs.promises.mkdir(CVE_DATA_DIR, { recursive: true });
|
|
401
|
-
if (!force && isCveIndexFresh()) {
|
|
402
|
-
if (verbose) console.log("CVE index is fresh (<
|
|
504
|
+
if (!force && !revalidate && isCurrentCveIndex(loadCveIndex()) && isCveIndexFresh()) {
|
|
505
|
+
if (verbose) console.log("CVE index is fresh (<4h); skipping download");
|
|
403
506
|
return loadCveIndex();
|
|
404
507
|
}
|
|
405
508
|
|
|
406
509
|
if (verbose) console.log("📥 fetching latest CVE release metadata…");
|
|
407
510
|
const { url, tag, name } = await fetchLatestRelease();
|
|
408
511
|
if (verbose) console.log(` ${tag} → ${name}`);
|
|
512
|
+
const cached=loadCveIndex();
|
|
513
|
+
const db=require('./cache-db').getCacheDb(path.dirname(CVE_DATA_DIR));
|
|
514
|
+
const snapshot=db.prepare("SELECT complete,stale FROM cache_snapshots WHERE namespace='cve_lookup'").get();
|
|
515
|
+
if (!force && isCurrentCveIndex(cached) && snapshot?.complete === 1 && snapshot.stale === 0 && tag && cached.meta.releaseTag === tag) {
|
|
516
|
+
const checkedAt=new Date().toISOString(), meta={...cached.meta,checkedAt};
|
|
517
|
+
db.prepare("UPDATE cache_snapshots SET fetched_at=?,metadata_json=? WHERE namespace='cve_lookup'").run(Date.parse(checkedAt),JSON.stringify(meta));
|
|
518
|
+
if (verbose) console.log('CVE release unchanged; retained local index');
|
|
519
|
+
return loadCveIndex();
|
|
520
|
+
}
|
|
409
521
|
|
|
410
522
|
if (verbose) console.log("📥 downloading CVE zip (this may take a while)…");
|
|
411
523
|
await download(url, CVE_ZIP_PATH, { verbose, tag, name });
|
|
@@ -429,14 +541,15 @@ async function downloadCveData(opts = {}) {
|
|
|
429
541
|
* downloading/refreshing as needed.
|
|
430
542
|
*/
|
|
431
543
|
async function ensureCveIndex(opts = {}) {
|
|
432
|
-
const { force, offline, verbose } = opts;
|
|
544
|
+
const { force, offline, verbose, ttlMs = 4 * 3600000 } = opts;
|
|
545
|
+
if (!Number.isFinite(ttlMs) || ttlMs < 0) throw new Error("invalid CVEProject TTL");
|
|
433
546
|
const cached = loadCveIndex();
|
|
434
547
|
if (offline) {
|
|
435
548
|
if (!cached) throw new Error("--cve-offline set but no cached CVE index found");
|
|
436
549
|
return cached;
|
|
437
550
|
}
|
|
438
|
-
if (!force && cached && isCveIndexFresh()) return cached;
|
|
439
|
-
return downloadCveData({ verbose, force });
|
|
551
|
+
if (!force && !require('./cache-policy').shouldForceUpdate() && isCurrentCveIndex(cached) && isCveIndexFresh(ttlMs / 3600000)) return cached;
|
|
552
|
+
return downloadCveData({ verbose, force: !!force, revalidate: true });
|
|
440
553
|
}
|
|
441
554
|
|
|
442
555
|
module.exports = {
|
|
@@ -449,8 +562,11 @@ module.exports = {
|
|
|
449
562
|
isCveIndexFresh,
|
|
450
563
|
ensureCveIndex,
|
|
451
564
|
extractMavenRelevantCve,
|
|
565
|
+
extractAffectedRanges,
|
|
452
566
|
isMavenRelevant,
|
|
453
567
|
curatedCoordsFor,
|
|
454
568
|
newIndex,
|
|
455
569
|
addToIndex,
|
|
570
|
+
MAVEN_INDEX_VERSION,
|
|
571
|
+
isCurrentCveIndex,
|
|
456
572
|
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const COORDINATE=/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)+:[A-Za-z0-9_.-]+$/;
|
|
3
|
+
const VERSION='[0-9](?:[A-Za-z0-9._+-]*[A-Za-z0-9])?';
|
|
4
|
+
const CLAUSE=`from (${VERSION}) and before (${VERSION})`;
|
|
5
|
+
|
|
6
|
+
function sentenceIntervals(product,description) {
|
|
7
|
+
if(typeof description!=='string' || description.length>100000)return null;
|
|
8
|
+
const head='This affects the package '+product+' ';
|
|
9
|
+
if(!description.startsWith(head))return null;
|
|
10
|
+
const body=description.slice(head.length);
|
|
11
|
+
const m=new RegExp(`^(${CLAUSE}(?:, ${CLAUSE})*)\\.(?:\\s|$)`).exec(body);
|
|
12
|
+
if(!m)return null;
|
|
13
|
+
return m[1].split(', ').map(part=>new RegExp(`^${CLAUSE}$`).exec(part).slice(1));
|
|
14
|
+
}
|
|
15
|
+
function legacyIntervals(affected,legacy) {
|
|
16
|
+
const vendors=legacy?.affects?.vendor?.vendor_data;
|
|
17
|
+
if(!Array.isArray(vendors))return null;
|
|
18
|
+
const products=vendors.filter(v=>v.vendor_name===affected.vendor).flatMap(v=>v.product?.product_data || []).filter(p=>p.product_name===affected.product);
|
|
19
|
+
if(products.length!==1)return null;
|
|
20
|
+
const rows=products[0].version?.version_data;
|
|
21
|
+
if(!Array.isArray(rows) || !rows.length || rows.length%2 || rows.length>64)return null;
|
|
22
|
+
const intervals=[];
|
|
23
|
+
for(let i=0;i<rows.length;i+=2) {
|
|
24
|
+
const a=rows[i],b=rows[i+1];
|
|
25
|
+
if(!a || !b || a.version_affected!=='>=' || b.version_affected!=='<' ||
|
|
26
|
+
[...Object.keys(a),...Object.keys(b)].some(k=>!['version_affected','version_value'].includes(k)))return null;
|
|
27
|
+
intervals.push([a.version_value,b.version_value]);
|
|
28
|
+
}
|
|
29
|
+
return intervals;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Some CVE 4 -> 5 conversions split each interval into two unusable rows:
|
|
33
|
+
// [lower, "unspecified") and ["unspecified", upper). Recover ONLY when all
|
|
34
|
+
// bounds agree, in order, with the retained structured V4 record or its rigid
|
|
35
|
+
// package/range sentence. Neither repository/file similarity nor arbitrary prose
|
|
36
|
+
// establishes a range. Native source documents are never modified.
|
|
37
|
+
function normalizeLegacySplitRanges(affected,description,legacy) {
|
|
38
|
+
if(!affected || !COORDINATE.test(affected.product || '') || affected.packageName ||
|
|
39
|
+
affected.packageURL || affected.purl || affected.collectionURL || !Array.isArray(affected.versions))return affected;
|
|
40
|
+
const text=sentenceIntervals(affected.product,description),structured=legacyIntervals(affected,legacy);
|
|
41
|
+
if(text && structured && JSON.stringify(text)!==JSON.stringify(structured))return affected;
|
|
42
|
+
const parts=structured || text,old=affected.versions;
|
|
43
|
+
if(!parts || !parts.length || parts.length>32 || old.length!==parts.length*2)return affected;
|
|
44
|
+
const versions=[],cmp=require('./cve-version-verdict').comparator('maven');
|
|
45
|
+
const concrete=new RegExp(`^${VERSION}$`);
|
|
46
|
+
for(let i=0;i<parts.length;i++) {
|
|
47
|
+
const [lower,upper]=parts[i],a=old[i*2],b=old[i*2+1];
|
|
48
|
+
const valid=r=>r && r.status==='affected' && r.versionType==='custom' &&
|
|
49
|
+
Object.keys(r).every(k=>['version','lessThan','status','versionType'].includes(k));
|
|
50
|
+
if(typeof lower!=='string' || typeof upper!=='string' || !concrete.test(lower) || !concrete.test(upper) ||
|
|
51
|
+
!valid(a) || !valid(b) || a.version!==lower || a.lessThan!=='unspecified' ||
|
|
52
|
+
b.version!=='unspecified' || b.lessThan!==upper || cmp(lower,upper)==null || cmp(lower,upper)>=0)return affected;
|
|
53
|
+
versions.push({version:lower,lessThan:upper,versionType:'maven',status:'affected'});
|
|
54
|
+
}
|
|
55
|
+
// Do not infer a default unaffected status or an automatic fix from this repair.
|
|
56
|
+
return {...affected,packageName:affected.product,versions,
|
|
57
|
+
_rangeEvidence:`Exact package/ranges corroborated by every legacy split bound and ${structured?'retained CVE V4 operators':'original range sentence'}`};
|
|
58
|
+
}
|
|
59
|
+
module.exports={normalizeLegacySplitRanges};
|
package/lib/cve-match.js
CHANGED
|
@@ -9,6 +9,7 @@ const { coord } = require("./core");
|
|
|
9
9
|
const { compareMavenVersions, isVersionAffected, normalizeHardPin, branchFixFromRanges } = require("./maven-version");
|
|
10
10
|
const { resolveTransitiveDeps } = require("./transitive");
|
|
11
11
|
const { makeDepRecord } = require("./dep-record");
|
|
12
|
+
const { affectedVerdict, rangeMembership, comparator } = require('./cve-version-verdict');
|
|
12
13
|
|
|
13
14
|
const SEVERITY_RANK = { CRITICAL: 4, HIGH: 3, MEDIUM: 2, LOW: 1, NONE: 0, UNKNOWN: 0 };
|
|
14
15
|
|
|
@@ -86,7 +87,9 @@ function collectResolvedDeps(allPomMetadata, allPropsByPom, opts = {}) {
|
|
|
86
87
|
if (v) v = resolveDepVersion(v, props);
|
|
87
88
|
const key = `${g}:${a}`;
|
|
88
89
|
const existing = out.get(key);
|
|
89
|
-
|
|
90
|
+
// A provided dependency can execute in production when supplied by
|
|
91
|
+
// the application server; only test scope is definitely test-only.
|
|
92
|
+
const isDev = scope === "test";
|
|
90
93
|
// A concrete (resolved, non-property) version worth scanning on its own.
|
|
91
94
|
const concrete = v && !/\$\{/.test(v) ? v : null;
|
|
92
95
|
// A scope=import BOM keeps its historical treatment: it is an explicit platform
|
|
@@ -382,7 +385,7 @@ function settleManagedOnly(resolvedDeps) {
|
|
|
382
385
|
* "probable" — vendor matches groupId prefix
|
|
383
386
|
* "possible" — product matches artifactId but vendor is unknown/unmatched
|
|
384
387
|
*/
|
|
385
|
-
function matchOne(dep, entries, confidence) {
|
|
388
|
+
function matchOne(dep, entries, confidence, onUnknown) {
|
|
386
389
|
const matches = [];
|
|
387
390
|
if (!entries) return matches;
|
|
388
391
|
// Scan every distinct version the dep resolves to (e.g. two profiles pinning
|
|
@@ -398,12 +401,51 @@ function matchOne(dep, entries, confidence) {
|
|
|
398
401
|
const concrete = versions.filter(v => v && !/\$\{/.test(String(v)));
|
|
399
402
|
if (!concrete.length) return matches;
|
|
400
403
|
for (const e of entries) {
|
|
404
|
+
// `custom` on an explicitly identified Maven package uses that package's
|
|
405
|
+
// version ordering. Never apply this fallback to product/CPE guesses or GIT.
|
|
406
|
+
const effectiveRanges = item => (item.ranges || []).map(r =>
|
|
407
|
+
item.coordinateEvidence === 'explicit-coordinate' && String(r.versionType).toLowerCase() === 'custom'
|
|
408
|
+
? { ...r, versionType: 'maven' } : r);
|
|
409
|
+
// Rows from the same provider describe alternative release branches, not
|
|
410
|
+
// independent assertions which must all match. Keep CNA/ADP disagreements.
|
|
411
|
+
const providers = new Map();
|
|
412
|
+
for (const item of e._sourceEntries || [e]) {
|
|
413
|
+
const key = JSON.stringify(item.affectedProviders || []);
|
|
414
|
+
const previous = providers.get(key);
|
|
415
|
+
const status = item.defaultStatus === undefined ? 'unaffected' : item.defaultStatus;
|
|
416
|
+
if (!previous) providers.set(key, { ranges: effectiveRanges(item), defaultStatus: status, platforms: item.platforms });
|
|
417
|
+
else {
|
|
418
|
+
previous.ranges.push(...effectiveRanges(item));
|
|
419
|
+
if (previous.defaultStatus !== status) previous.defaultStatus = 'unknown';
|
|
420
|
+
// An unrestricted/Java branch must not erase another branch's OS
|
|
421
|
+
// constraint when their version ranges are combined. Keep the union
|
|
422
|
+
// indeterminate until conditional branches can be evaluated separately.
|
|
423
|
+
if (item.platforms?.length) previous.platforms = [...(previous.platforms || []), ...item.platforms];
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
const evidence = [...providers.values()];
|
|
427
|
+
const evaluatedRanges = effectiveRanges(e);
|
|
428
|
+
const verdictFor = version => {
|
|
429
|
+
const states = evidence.map(item => item.platforms?.some(p => typeof p !== 'string' || p.trim().toLowerCase() !== 'java') ? null : affectedVerdict(String(version), item.ranges, item.defaultStatus === undefined ? 'unaffected' : item.defaultStatus));
|
|
430
|
+
if (states.some(state => state === null)) return null;
|
|
431
|
+
return states.every(state => state === true) ? true : states.every(state => state === false) ? false : null;
|
|
432
|
+
};
|
|
401
433
|
for (const ver of concrete) {
|
|
402
|
-
const
|
|
434
|
+
const vdep = ver === dep.version ? dep : { ...dep, version: ver };
|
|
435
|
+
const affected = verdictFor(ver);
|
|
436
|
+
if (affected === null) {
|
|
437
|
+
onUnknown?.({ dep: vdep, cve: e, source: e.source || 'CVEProject', confidence: 'possible' });
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
403
440
|
if (affected) {
|
|
404
|
-
const vdep = ver === dep.version ? dep : { ...dep, version: ver };
|
|
405
441
|
const branchFix = branchFixFromRanges(ver, e.ranges);
|
|
406
|
-
|
|
442
|
+
// An inclusive upper bound names an affected version, not a fix. Also
|
|
443
|
+
// reject a branch fix that another range in the same record still affects.
|
|
444
|
+
const candidate = branchFix?.fixed;
|
|
445
|
+
const applicable = evaluatedRanges.filter(r => r.status === 'affected' && rangeMembership(String(ver), r) === true);
|
|
446
|
+
const fixVersion = candidate && verdictFor(candidate) === false && applicable.length && applicable.every(r => comparator(r.versionType)?.(String(candidate), String(ver)) > 0) ? candidate : null;
|
|
447
|
+
const { _sourceEntries, ...publicEntry } = e;
|
|
448
|
+
matches.push({ dep: vdep, cve: { ...publicEntry, fixVersion, fixEvaluation: fixVersion ? 'verified' : 'unknown', ...(branchFix && (!branchFix.fixed || fixVersion) ? { branchFix } : {}) }, source: e.source || "CVEProject", confidence });
|
|
407
449
|
}
|
|
408
450
|
}
|
|
409
451
|
}
|
|
@@ -438,23 +480,49 @@ function matchDepsAgainstCves(resolvedDeps, cveIndex, opts = {}) {
|
|
|
438
480
|
|
|
439
481
|
const all = [];
|
|
440
482
|
for (const dep of resolvedDeps.values()) {
|
|
441
|
-
// The CVEProject
|
|
442
|
-
//
|
|
443
|
-
|
|
444
|
-
if (dep.ecosystem === "npm") continue;
|
|
483
|
+
// The CVEProject index contains Maven coordinates only. Other ecosystems
|
|
484
|
+
// are handled by their own advisory sources and must not match by artifact.
|
|
485
|
+
if (dep.ecosystem && dep.ecosystem !== "maven") continue;
|
|
445
486
|
if (dep.provenance === "binary") continue; // no resolved coordinate yet (Plan 2 identifies it)
|
|
446
487
|
const key = `${dep.groupId}:${dep.artifactId}`.toLowerCase();
|
|
447
|
-
//
|
|
448
|
-
|
|
488
|
+
// A lookup key can also have been reconstructed from a generic product
|
|
489
|
+
// name by an older index. Only native, explicit coordinates prove an
|
|
490
|
+
// exact identity; missing legacy evidence must remain indeterminate.
|
|
491
|
+
const entries = byPackage[key] || [];
|
|
492
|
+
const exactCoord = `${dep.groupId}:${dep.artifactId}`;
|
|
493
|
+
const exact = e => ['explicit-coordinate','curated-module'].includes(e.coordinateEvidence) && e.exactPackageName === exactCoord;
|
|
494
|
+
// A CNA and one or more ADPs can describe the same package/advisory.
|
|
495
|
+
// Evaluate their ranges together so conflicting statuses cannot silently
|
|
496
|
+
// become a positive finding merely because one entry was visited first.
|
|
497
|
+
const exactGroups = new Map();
|
|
498
|
+
for (const entry of entries.filter(exact)) {
|
|
499
|
+
const previous = exactGroups.get(entry.id);
|
|
500
|
+
if (!previous) exactGroups.set(entry.id, { ...entry, ranges: [...(entry.ranges || [])], affectedProviders: [...(entry.affectedProviders || [])], _sourceEntries: [entry] });
|
|
501
|
+
else {
|
|
502
|
+
previous.ranges.push(...(entry.ranges || []));
|
|
503
|
+
previous.affectedProviders.push(...(entry.affectedProviders || []));
|
|
504
|
+
previous._sourceEntries.push(entry);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
const t1 = [...exactGroups.values()].flatMap(e => matchOne(dep, [e], e.coordinateEvidence === 'curated-module' ? 'probable' : 'exact', opts.onUncertain));
|
|
449
508
|
all.push(...t1);
|
|
450
|
-
//
|
|
509
|
+
// A different explicitly named coordinate is a different Maven artifact;
|
|
510
|
+
// an old projection missing the original spelling is indeterminate.
|
|
511
|
+
const uncertain = matchOne(dep, entries.filter(e => !exact(e) && !(e.coordinateEvidence === 'explicit-coordinate' && e.exactPackageName)), "possible", opts.onUncertain);
|
|
512
|
+
for (const candidate of uncertain) opts.onUncertain?.(candidate);
|
|
513
|
+
if (includePossibleTier) all.push(...uncertain);
|
|
514
|
+
// Product-only candidates are indeterminate even when the vendor differs:
|
|
515
|
+
// vendor labels are not reliable enough to prove absence either.
|
|
451
516
|
const productMatches = byProduct[dep.artifactId.toLowerCase()] || [];
|
|
452
517
|
for (const e of productMatches) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
518
|
+
// Explicit coordinates are already handled by their package key. A
|
|
519
|
+
// product alias must not broaden that proof to another artifact.
|
|
520
|
+
if (['explicit-coordinate','curated-module'].includes(e.coordinateEvidence)) continue;
|
|
521
|
+
// Product/vendor similarity is useful for manual triage but is not a
|
|
522
|
+
// proof that this artifact is the affected package.
|
|
523
|
+
const possible = matchOne(dep, [e], "possible", opts.onUncertain);
|
|
524
|
+
for (const candidate of possible) opts.onUncertain?.(candidate);
|
|
525
|
+
if (includePossibleTier) all.push(...possible);
|
|
458
526
|
}
|
|
459
527
|
}
|
|
460
528
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Fetch only npm identities involved in this scan. The proxy returns raw CVE
|
|
3
|
+
// records, never pre-digested ranges; offline scans consume the stored records.
|
|
4
|
+
const {osvPkgName}=require('./osv');
|
|
5
|
+
const tuple=name=>({source:'cveproject',ecosystem:'npm',name,version:'*'});
|
|
6
|
+
function packageNames(resolved){return [...new Set([...resolved.values()].filter(d=>['npm','yarn'].includes(d.ecosystem)&&d.provenance!=='binary').map(osvPkgName).filter(Boolean).map(s=>s.toLowerCase()))].sort();}
|
|
7
|
+
async function refreshNpmCves(resolved,store,{ttlMs=4 * 3600000,getResource=require('./providers').getResource}={}){
|
|
8
|
+
const names=packageNames(resolved),needed=names.filter(name=>require('./cache-policy').shouldForceUpdate() || !store.getQuery(tuple(name),{ttlMs})?.fresh);let incomplete=false,received=0;
|
|
9
|
+
for(let i=0;i<needed.length;i+=200){
|
|
10
|
+
const batch=needed.slice(i,i+200),res=await getResource('github','cve-npm',{names:batch},{forceRefresh:true});
|
|
11
|
+
if(!res.ok)throw Error(`npm CVE proxy HTTP ${res.status}`);
|
|
12
|
+
const body=await res.json();if(!Array.isArray(body.records)||typeof body.complete!=='boolean')throw Error('invalid npm CVE proxy response');
|
|
13
|
+
const at=Date.parse(res.headers?.get('x-fad-proxy-fetched-at')||'');
|
|
14
|
+
if(!Number.isFinite(at)||at<=0||at>Date.now()+300000)throw Error('npm CVE proxy response has no trustworthy source timestamp');
|
|
15
|
+
const stale=res.headers?.get('x-fad-proxy')==='stale' || Date.now()-at >= require('./cache-policy').DEFAULT_TTL_MS, idsByName=new Map(batch.map(name=>[name,new Set()])),records=[];
|
|
16
|
+
for(const raw of body.records){
|
|
17
|
+
const record=require('./native-advisories').cveEnvelope(raw,{fetchedAt:at,provenance:{transport:'proxy',stale}});
|
|
18
|
+
for(const p of record.packages.filter(p=>p.ecosystem==='npm'))if(idsByName.has(p.name.toLowerCase()))idsByName.get(p.name.toLowerCase()).add(record.id);
|
|
19
|
+
if(!record.packages.some(p=>p.ecosystem==='npm'&&idsByName.has(p.name.toLowerCase())))throw Error('npm CVE proxy returned an unrelated record');
|
|
20
|
+
records.push(record);
|
|
21
|
+
}
|
|
22
|
+
const unique=new Map(records.map(x=>[x.id,x]));if(unique.size!==records.length)throw Error('npm CVE proxy returned duplicate records');
|
|
23
|
+
const queries=body.complete&&!stale?batch.map(name=>({...tuple(name),ids:[...idsByName.get(name)].sort(),fetchedAt:at,complete:true,provenance:{transport:'proxy'}})):[];
|
|
24
|
+
store.commit({records,queries});received+=records.length;
|
|
25
|
+
if(!body.complete||stale)incomplete=true;
|
|
26
|
+
}
|
|
27
|
+
return {packages:names.length,requested:needed.length,received,incomplete};
|
|
28
|
+
}
|
|
29
|
+
module.exports={refreshNpmCves,packageNames,tuple};
|