vigievuln 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -2
- package/README.md +13 -7
- package/lib/advisory-freshness.js +2 -0
- package/lib/airgap-project.js +35 -7
- package/lib/applicability-evidence.js +12 -0
- package/lib/artifacts/applications.js +54 -0
- package/lib/artifacts/cve-view.js +108 -0
- package/lib/artifacts/enrichment.js +86 -0
- package/lib/artifacts/go-main-identity.js +45 -0
- package/lib/artifacts/go-publisher-advisories.js +24 -0
- package/lib/artifacts/index.js +272 -0
- package/lib/artifacts/publisher-advisories.js +12 -0
- package/lib/artifacts/remediation-report.js +48 -0
- package/lib/artifacts/report-inventory.js +26 -0
- package/lib/artifacts/report.js +191 -0
- package/lib/artifacts/risk-report.js +120 -0
- package/lib/artifacts/sbom.js +68 -0
- package/lib/artifacts/scan.js +401 -0
- package/lib/cache-archive-sqlite.js +41 -25
- package/lib/certs/analyze.js +49 -13
- package/lib/charts.js +124 -32
- package/lib/cli-command-routing.js +20 -6
- package/lib/cli-groups.js +2 -1
- package/lib/cli-image.js +206 -0
- package/lib/codecs/binary/elf-metadata.js +42 -0
- package/lib/codecs/binary/go-buildinfo.js +37 -0
- package/lib/codecs/binary/metadata.js +7 -0
- package/lib/codecs/binary/pe-metadata.js +27 -1
- package/lib/codecs/binary/scan.js +44 -26
- package/lib/codecs/binary/sniff.js +16 -15
- package/lib/codecs/binary.codec.js +27 -4
- package/lib/codecs/go/parse.js +10 -4
- package/lib/codecs/go.codec.js +23 -6
- package/lib/codecs/gradle/parse.js +63 -2
- package/lib/codecs/gradle/versionless.js +175 -0
- package/lib/codecs/gradle.codec.js +20 -3
- package/lib/codecs/index.js +2 -2
- package/lib/codecs/maven.codec.js +9 -4
- package/lib/codecs/npm/collect.js +6 -11
- package/lib/codecs/nuget/parse.js +16 -5
- package/lib/codecs/nuget.codec.js +2 -1
- package/lib/codecs/pypi/parse.js +56 -15
- package/lib/codecs/pypi.codec.js +2 -0
- package/lib/csaf-export.js +46 -11
- package/lib/cve-download.js +33 -29
- package/lib/cve-match.js +10 -0
- package/lib/cve-packages-proxy.js +19 -0
- package/lib/cve-report.js +273 -165
- package/lib/deps-descriptor.js +25 -3
- package/lib/diagnostics.js +12 -0
- package/lib/diff.js +0 -0
- package/lib/epss.js +6 -6
- package/lib/euvd.js +34 -4
- package/lib/finding-enrichment.js +165 -0
- package/lib/finding-summary.js +4 -3
- package/lib/i18n.js +35 -9
- package/lib/image-network.js +54 -0
- package/lib/image-references.js +203 -0
- package/lib/image-registry.js +385 -0
- package/lib/image-update.js +39 -0
- package/lib/json-export.js +100 -10
- package/lib/kev.js +6 -6
- package/lib/maven-bom.js +2 -1
- package/lib/merge-sources.js +3 -0
- package/lib/native-advisories.js +9 -7
- package/lib/native-cna-identities.js +12 -0
- package/lib/native-package-match.js +159 -0
- package/lib/native-source-prepare.js +60 -0
- package/lib/nvd.js +34 -23
- package/lib/osv.js +33 -14
- package/lib/project-descriptor.js +3 -2
- package/lib/provenance.js +8 -2
- package/lib/providers/alpine.js +8 -0
- package/lib/providers/common.js +11 -3
- package/lib/providers/debian.js +11 -0
- package/lib/providers/euvd.js +2 -1
- package/lib/providers/freexian.js +13 -0
- package/lib/providers/github.js +1 -0
- package/lib/providers/go.js +2 -1
- package/lib/providers/index.js +18 -14
- package/lib/providers/nginx.js +5 -0
- package/lib/providers/nvd.js +1 -1
- package/lib/providers/osv.js +1 -1
- package/lib/providers/osvdb.js +2 -2
- package/lib/proxy-throttle.js +89 -29
- package/lib/purl.js +10 -2
- package/lib/record-freshness.js +22 -0
- package/lib/report-notices.js +47 -0
- package/lib/report-time.js +45 -0
- package/lib/request-failure.js +22 -0
- package/lib/resource-cache/engine.js +130 -26
- package/lib/resource-cache/snapshot-projection.js +33 -0
- package/lib/resource-cache/validate.js +22 -5
- package/lib/risk-evidence.js +18 -0
- package/lib/sarif-export.js +17 -9
- package/lib/sbom-export.js +38 -12
- package/lib/source-health.js +25 -8
- package/lib/source-image-scan.js +57 -0
- package/lib/source-profile.js +6 -3
- package/lib/sqlite-driver.js +15 -1
- package/lib/suppress.js +34 -13
- package/lib/system-inventory/advisories.js +169 -0
- package/lib/system-inventory/alpine-tracker.js +47 -0
- package/lib/system-inventory/collect.js +118 -0
- package/lib/system-inventory/current-debian.js +99 -0
- package/lib/system-inventory/distribution-sources.js +132 -0
- package/lib/system-inventory/freexian-ela.js +32 -0
- package/lib/system-inventory/freexian-release-evidence.js +35 -0
- package/lib/system-inventory/freexian-tracker.js +72 -0
- package/lib/system-inventory/historical-debian.js +196 -0
- package/lib/system-inventory/index.js +2 -0
- package/lib/system-inventory/nginx-advisories.js +39 -0
- package/lib/system-inventory/rpm-storage.js +86 -0
- package/lib/system-inventory/targeted.js +70 -0
- package/lib/system-inventory/versions.js +59 -0
- package/lib/transitive.js +11 -2
- package/lib/ui.js +8 -5
- package/lib/unmanaged.js +1 -1
- package/lib/xlsx-export.js +8 -2
- package/package.json +12 -3
- package/vigievuln.js +279 -127
package/lib/csaf-export.js
CHANGED
|
@@ -60,7 +60,7 @@ function buildCsaf(resolvedDeps, cveMatches, opts = {}) {
|
|
|
60
60
|
const pid = `PROD-${n++}`;
|
|
61
61
|
const purl = purlFor(variant.dep);
|
|
62
62
|
full_product_names.push({ product_id: pid,
|
|
63
|
-
name: humanName(variant.dep) + (variant.location ? ` (${variant.location})` : ""),
|
|
63
|
+
name: humanName(variant.dep) + (variant.location ? ` (${variant.location})` : "") + (variant.dep.artifactTargetId ? ` [${variant.dep.artifactTargetId}${variant.dep.artifactPath ? `; ${variant.dep.artifactPath}` : ""}]` : ""),
|
|
64
64
|
...(purl ? { product_identification_helper: { purl } } : {}) });
|
|
65
65
|
return { ...variant, pid };
|
|
66
66
|
});
|
|
@@ -96,21 +96,23 @@ function buildCsaf(resolvedDeps, cveMatches, opts = {}) {
|
|
|
96
96
|
let v = byCve.get(id);
|
|
97
97
|
if (!v) {
|
|
98
98
|
const cve = m.cve;
|
|
99
|
+
const risk=require('./risk-evidence'),scoreSafe=!risk.relatedRisk(cve,'scoreSource'),severitySafe=!risk.relatedRisk(cve,'severitySource'),kevRelated=risk.relatedSignal(cve,'kev'),epssRelated=risk.relatedSignal(cve,'epss');
|
|
99
100
|
const notes = [];
|
|
101
|
+
const evidence=risk.evidenceObject(cve);if(Object.keys(evidence).length)notes.push({category:'other',title:'Related risk evidence',text:JSON.stringify(evidence)});
|
|
100
102
|
if (cve.description) notes.push({ category: "description", text: cve.description, title: "Description" });
|
|
101
103
|
const extras = [];
|
|
102
|
-
if (cve.epssPercentile != null) extras.push(
|
|
103
|
-
if (cve.kev) extras.push(
|
|
104
|
+
if (cve.epssPercentile != null) extras.push(`${epssRelated ? "Related upstream CVE EPSS percentile" : "EPSS percentile"} ${Math.round(cve.epssPercentile * 100)}%`);
|
|
105
|
+
if (cve.kev) extras.push(`${kevRelated ? "Related upstream CVE in CISA KEV" : "CISA KEV (known exploited)"}${cve.kevDueDate ? `, remediate by ${cve.kevDueDate}` : ""}`);
|
|
104
106
|
if (euvdExploited(cve)) extras.push(`ENISA EUVD (exploited${cve.euvd.exploitedSince ? ` since ${cve.euvd.exploitedSince}` : ""})`);
|
|
105
107
|
if (cve.priority?.band) extras.push(`vigievuln priority: ${cve.priority.band}${cve.priority.score != null ? ` (${cve.priority.score}/100)` : ""}`);
|
|
106
108
|
if (extras.length) notes.push({ category: "other", text: extras.join("; "), title: "Prioritization" });
|
|
107
109
|
|
|
108
110
|
const v3ver = cvssV3Version(cve.cvssVersion);
|
|
109
|
-
const scores = (v3ver && cve.score != null) ? [{
|
|
111
|
+
const scores = (scoreSafe && v3ver && cve.score != null) ? [{
|
|
110
112
|
cvss_v3: {
|
|
111
113
|
version: v3ver,
|
|
112
114
|
baseScore: cve.score,
|
|
113
|
-
baseSeverity: cvssV3Severity(cve.severity, cve.score),
|
|
115
|
+
baseSeverity: cvssV3Severity(severitySafe ? cve.severity : null, cve.score),
|
|
114
116
|
// Only carry the vector when it actually IS a v3 vector — a v4 (or
|
|
115
117
|
// mismatched) vector string fails the v3 schema's vectorString pattern.
|
|
116
118
|
...((cve.cvssVector && /^CVSS:3\.[01]\//.test(cve.cvssVector)) ? { vectorString: cve.cvssVector } : {}),
|
|
@@ -127,24 +129,57 @@ function buildCsaf(resolvedDeps, cveMatches, opts = {}) {
|
|
|
127
129
|
...(notes.length ? { notes } : {}),
|
|
128
130
|
product_status: { known_affected: [] },
|
|
129
131
|
...(scores.length ? { scores } : {}),
|
|
130
|
-
...(cve.kev ? { flags: [{ label: "exploited", product_ids: [] }] } : {}),
|
|
132
|
+
...(cve.kev && !kevRelated ? { flags: [{ label: "exploited", product_ids: [] }] } : {}),
|
|
131
133
|
...(europeanReferences(cve).length ? { references: europeanReferences(cve).map(r => ({ category: "external", summary: r.title ? `${r.source} ${r.id} — ${r.title}` : `${r.source} ${r.id}`, url: r.url })) } : {}),
|
|
132
134
|
};
|
|
133
135
|
byCve.set(id, v);
|
|
134
136
|
}
|
|
137
|
+
const relatedEvidence=require('./risk-evidence').evidenceObject(m.cve);
|
|
138
|
+
if(Object.keys(relatedEvidence).length){const text=JSON.stringify(relatedEvidence);v.notes ||= [];if(!v.notes.some(n=>n.title==='Related risk evidence' && n.text===text))v.notes.push({category:'other',title:'Related risk evidence',text});}
|
|
139
|
+
if(m.cve.historicalEvidence){const text=JSON.stringify({products:pids,evidence:m.cve.historicalEvidence});v.notes ||= [];if(!v.notes.some(n=>n.title==='Historical advisory evidence'&&n.text===text))v.notes.push({category:'other',title:'Historical advisory evidence',text});}
|
|
140
|
+
for(const evidence of require('./applicability-evidence').applicabilityEvidence(m.cve)){const text=JSON.stringify({products:pids,...evidence});v.notes ||= [];if(!v.notes.some(n=>n.title==='Applicability evidence'&&n.text===text))v.notes.push({category:'other',title:'Applicability evidence',text});}
|
|
141
|
+
if(m.cve.vendorEvidence){const text=JSON.stringify({products:pids,evidence:m.cve.vendorEvidence});v.notes ||= [];if(!v.notes.some(n=>n.title==='Vendor advisory evidence'&&n.text===text))v.notes.push({category:'other',title:'Vendor advisory evidence',text});}
|
|
135
142
|
if (id.startsWith("CVE-") && m.advisoryId) {
|
|
136
143
|
const system_name = String(m.source || "").includes("wordfence-v3") ? "Wordfence" :
|
|
137
144
|
String(m.source || "").includes("drupal-security-advisories") ? "Drupal Security Advisory" : "Advisory";
|
|
138
145
|
if (!(v.ids || []).some(item => item.system_name === system_name && item.text === m.advisoryId))
|
|
139
146
|
v.ids = [...(v.ids || []), { system_name, text: m.advisoryId }];
|
|
140
147
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
// Accepted risk remains affected. Only an explicit scoped VEX assertion
|
|
149
|
+
// may mark a product fixed/not affected.
|
|
150
|
+
const status = m.suppressed && ["fixed", "known_not_affected"].includes(m.suppressionStatus)
|
|
151
|
+
? m.suppressionStatus : "known_affected";
|
|
152
|
+
if (m.suppressed) {
|
|
153
|
+
v.notes ||= [];
|
|
154
|
+
v.notes.push({ category: "other", title: "VigieVuln triage", text: JSON.stringify({
|
|
155
|
+
product_ids: pids, suppressed: true, reason: m.suppressedReason || "ignored", status,
|
|
156
|
+
}) });
|
|
157
|
+
}
|
|
158
|
+
v.product_status[status] ||= [];
|
|
159
|
+
for (const pid of pids) if (pid && !v.product_status[status].includes(pid)) {
|
|
160
|
+
v.product_status[status].push(pid);
|
|
161
|
+
if (v.scores?.[0] && !v.scores[0].products.includes(pid)) v.scores[0].products.push(pid);
|
|
162
|
+
if (v.flags?.[0] && !v.flags[0].product_ids.includes(pid)) v.flags[0].product_ids.push(pid);
|
|
145
163
|
}
|
|
146
164
|
}
|
|
147
165
|
|
|
166
|
+
for (const v of byCve.values()) {
|
|
167
|
+
const statuses = v.product_status;
|
|
168
|
+
const affected = new Set(statuses.known_affected || []);
|
|
169
|
+
// Contradictory assertions cannot clear a product; affected wins regardless
|
|
170
|
+
// of input order. Different clearance statuses are also contradictory.
|
|
171
|
+
for (const pid of statuses.fixed || [])
|
|
172
|
+
if ((statuses.known_not_affected || []).includes(pid)) affected.add(pid);
|
|
173
|
+
statuses.known_affected = [...affected];
|
|
174
|
+
for (const status of ["fixed", "known_not_affected"])
|
|
175
|
+
if (statuses[status]) statuses[status] = statuses[status].filter(pid => !affected.has(pid));
|
|
176
|
+
for (const status of Object.keys(statuses)) if (!statuses[status].length) delete statuses[status];
|
|
177
|
+
if (v.flags) {
|
|
178
|
+
v.flags = v.flags.map(flag => ({ ...flag, product_ids: flag.product_ids.filter(pid => affected.has(pid)) }))
|
|
179
|
+
.filter(flag => flag.product_ids.length);
|
|
180
|
+
if (!v.flags.length) delete v.flags;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
148
183
|
return {
|
|
149
184
|
document: {
|
|
150
185
|
category: "csaf_vex",
|
|
@@ -168,7 +203,7 @@ function buildCsaf(resolvedDeps, cveMatches, opts = {}) {
|
|
|
168
203
|
product_tree: { full_product_names },
|
|
169
204
|
// Drop any vulnerability that ended up with zero affected products (e.g. a
|
|
170
205
|
// match with no usable dep) — an empty product_status is schema-invalid.
|
|
171
|
-
vulnerabilities: [...byCve.values()].filter(v => v.product_status.
|
|
206
|
+
vulnerabilities: [...byCve.values()].filter(v => Object.keys(v.product_status).length > 0),
|
|
172
207
|
};
|
|
173
208
|
}
|
|
174
209
|
|
package/lib/cve-download.js
CHANGED
|
@@ -429,7 +429,7 @@ function walkJsonFiles(dir, onFile) {
|
|
|
429
429
|
}
|
|
430
430
|
|
|
431
431
|
async function buildCveIndex(extractDir, opts = {}) {
|
|
432
|
-
const { verbose, releaseTag } = opts;
|
|
432
|
+
const { verbose, releaseTag, cacheDir = path.dirname(CVE_DATA_DIR) } = opts;
|
|
433
433
|
const index = newIndex();
|
|
434
434
|
let processed = 0;
|
|
435
435
|
let added = 0;
|
|
@@ -455,20 +455,23 @@ async function buildCveIndex(extractDir, opts = {}) {
|
|
|
455
455
|
// Keep native records and REJECTED revisions alongside the legacy index.
|
|
456
456
|
// This incremental import cannot infer withdrawals from absent files, so its
|
|
457
457
|
// coverage is recorded as partial until a full reconciliation is available.
|
|
458
|
-
const store = require('./advisory-store').openAdvisoryStore({cacheDir
|
|
459
|
-
await require('./native-advisories').importCveDirectory(store,extractDir,{fetchedAt:Date.parse(index.meta.builtAt),provenance:{transport:'direct',releaseTag:releaseTag || null}});
|
|
460
|
-
|
|
458
|
+
const store = require('./advisory-store').openAdvisoryStore({cacheDir});
|
|
459
|
+
try { await require('./native-advisories').importCveDirectory(store,extractDir,{fetchedAt:Date.parse(index.meta.builtAt),provenance:{transport:'direct',releaseTag:releaseTag || null}}); }
|
|
460
|
+
finally { store.close(); }
|
|
461
|
+
saveCveIndex(index, cacheDir);
|
|
461
462
|
return index;
|
|
462
463
|
}
|
|
463
464
|
|
|
464
|
-
function saveCveIndex(index) {
|
|
465
|
-
const db=require('./cache-db').getCacheDb(
|
|
466
|
-
const insert=db.prepare('INSERT INTO cve_lookup(kind,lookup_key,source,cve,affected_key,projection_json) VALUES (?,?,?,?,?,?)');
|
|
465
|
+
function saveCveIndex(index, cacheDir = path.dirname(CVE_DATA_DIR)) {
|
|
466
|
+
const db=require('./cache-db').getCacheDb(cacheDir);
|
|
467
|
+
const insert=db.prepare('INSERT OR IGNORE INTO cve_lookup(kind,lookup_key,source,cve,affected_key,projection_json) VALUES (?,?,?,?,?,?)');
|
|
468
|
+
const existing=db.prepare('SELECT projection_json FROM cve_lookup WHERE kind=? AND lookup_key=? AND source=? AND cve=? AND affected_key=?');
|
|
467
469
|
db.transaction(()=>{
|
|
468
470
|
db.exec('DELETE FROM cve_lookup');
|
|
469
471
|
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
472
|
const projection=JSON.stringify(entry),key=require('node:crypto').createHash('sha256').update(projection).digest('hex');
|
|
471
|
-
insert.run(kind,lookup,
|
|
473
|
+
const source=entry.source||'CVEProject',result=insert.run(kind,lookup,source,entry.id,key,projection);
|
|
474
|
+
if(!result.changes && existing.get(kind,lookup,source,entry.id,key)?.projection_json!==projection)throw Error('CVE index projection hash collision');
|
|
472
475
|
}
|
|
473
476
|
const stamp=Date.parse(index.meta.builtAt);
|
|
474
477
|
db.prepare(`INSERT INTO cache_snapshots(namespace,fetched_at,complete,stale,record_count,metadata_json) VALUES (?,?,?,?,?,?)
|
|
@@ -477,8 +480,8 @@ function saveCveIndex(index) {
|
|
|
477
480
|
});
|
|
478
481
|
}
|
|
479
482
|
|
|
480
|
-
function loadCveIndex() {
|
|
481
|
-
const db=require('./cache-db').getCacheDb(
|
|
483
|
+
function loadCveIndex(cacheDir = path.dirname(CVE_DATA_DIR)) {
|
|
484
|
+
const db=require('./cache-db').getCacheDb(cacheDir);
|
|
482
485
|
const snapshot=db.prepare("SELECT metadata_json FROM cache_snapshots WHERE namespace='cve_lookup'").get();
|
|
483
486
|
if(!snapshot)return null;
|
|
484
487
|
const statement=db.prepare('SELECT projection_json FROM cve_lookup WHERE kind=? AND lookup_key=?');
|
|
@@ -489,9 +492,9 @@ function loadCveIndex() {
|
|
|
489
492
|
return {meta:JSON.parse(snapshot.metadata_json),byPackageName:bucket('package'),byProduct:bucket('product')};
|
|
490
493
|
}
|
|
491
494
|
|
|
492
|
-
function isCveIndexFresh(maxAgeHours = 4) {
|
|
495
|
+
function isCveIndexFresh(maxAgeHours = 4, cacheDir = path.dirname(CVE_DATA_DIR)) {
|
|
493
496
|
try {
|
|
494
|
-
const meta=loadCveIndex()?.meta;
|
|
497
|
+
const meta=loadCveIndex(cacheDir)?.meta;
|
|
495
498
|
if (!meta.builtAt) return false;
|
|
496
499
|
const age = Date.now() - new Date(meta.checkedAt || meta.builtAt).getTime();
|
|
497
500
|
return age < maxAgeHours * 3600 * 1000;
|
|
@@ -499,39 +502,40 @@ function isCveIndexFresh(maxAgeHours = 4) {
|
|
|
499
502
|
}
|
|
500
503
|
|
|
501
504
|
async function downloadCveData(opts = {}) {
|
|
502
|
-
const { verbose, force, revalidate } = opts;
|
|
503
|
-
|
|
504
|
-
|
|
505
|
+
const { verbose, force, revalidate, cacheDir = path.dirname(CVE_DATA_DIR) } = opts;
|
|
506
|
+
const dataDir=path.join(cacheDir,'cve-data'), extractDir=path.join(dataDir,'extracted'), zipPath=path.join(dataDir,'cves.zip');
|
|
507
|
+
await fs.promises.mkdir(dataDir, { recursive: true });
|
|
508
|
+
if (!force && !revalidate && isCurrentCveIndex(loadCveIndex(cacheDir)) && isCveIndexFresh(4, cacheDir)) {
|
|
505
509
|
if (verbose) console.log("CVE index is fresh (<4h); skipping download");
|
|
506
|
-
return loadCveIndex();
|
|
510
|
+
return loadCveIndex(cacheDir);
|
|
507
511
|
}
|
|
508
512
|
|
|
509
513
|
if (verbose) console.log("📥 fetching latest CVE release metadata…");
|
|
510
514
|
const { url, tag, name } = await fetchLatestRelease();
|
|
511
515
|
if (verbose) console.log(` ${tag} → ${name}`);
|
|
512
|
-
const cached=loadCveIndex();
|
|
513
|
-
const db=require('./cache-db').getCacheDb(
|
|
516
|
+
const cached=loadCveIndex(cacheDir);
|
|
517
|
+
const db=require('./cache-db').getCacheDb(cacheDir);
|
|
514
518
|
const snapshot=db.prepare("SELECT complete,stale FROM cache_snapshots WHERE namespace='cve_lookup'").get();
|
|
515
519
|
if (!force && isCurrentCveIndex(cached) && snapshot?.complete === 1 && snapshot.stale === 0 && tag && cached.meta.releaseTag === tag) {
|
|
516
520
|
const checkedAt=new Date().toISOString(), meta={...cached.meta,checkedAt};
|
|
517
521
|
db.prepare("UPDATE cache_snapshots SET fetched_at=?,metadata_json=? WHERE namespace='cve_lookup'").run(Date.parse(checkedAt),JSON.stringify(meta));
|
|
518
522
|
if (verbose) console.log('CVE release unchanged; retained local index');
|
|
519
|
-
return loadCveIndex();
|
|
523
|
+
return loadCveIndex(cacheDir);
|
|
520
524
|
}
|
|
521
525
|
|
|
522
526
|
if (verbose) console.log("📥 downloading CVE zip (this may take a while)…");
|
|
523
|
-
await download(url,
|
|
527
|
+
await download(url, zipPath, { verbose, tag, name });
|
|
524
528
|
|
|
525
529
|
if (verbose) console.log("📦 extracting…");
|
|
526
|
-
try { await fs.promises.rm(
|
|
527
|
-
await extractZip(
|
|
530
|
+
try { await fs.promises.rm(extractDir, { recursive: true, force: true }); } catch {}
|
|
531
|
+
await extractZip(zipPath, extractDir, { verbose });
|
|
528
532
|
|
|
529
533
|
if (verbose) console.log("🔎 building Maven CVE index…");
|
|
530
|
-
const index = await buildCveIndex(
|
|
534
|
+
const index = await buildCveIndex(extractDir, { verbose, releaseTag: tag, cacheDir });
|
|
531
535
|
|
|
532
536
|
// cleanup heavy files
|
|
533
|
-
try { await fs.promises.rm(
|
|
534
|
-
try { await fs.promises.rm(
|
|
537
|
+
try { await fs.promises.rm(extractDir, { recursive: true, force: true }); } catch {}
|
|
538
|
+
try { await fs.promises.rm(zipPath, { force: true }); } catch {}
|
|
535
539
|
|
|
536
540
|
return index;
|
|
537
541
|
}
|
|
@@ -541,15 +545,15 @@ async function downloadCveData(opts = {}) {
|
|
|
541
545
|
* downloading/refreshing as needed.
|
|
542
546
|
*/
|
|
543
547
|
async function ensureCveIndex(opts = {}) {
|
|
544
|
-
const { force, offline, verbose, ttlMs = 4 * 3600000 } = opts;
|
|
548
|
+
const { force, offline, verbose, ttlMs = 4 * 3600000, cacheDir = path.dirname(CVE_DATA_DIR) } = opts;
|
|
545
549
|
if (!Number.isFinite(ttlMs) || ttlMs < 0) throw new Error("invalid CVEProject TTL");
|
|
546
|
-
const cached = loadCveIndex();
|
|
550
|
+
const cached = loadCveIndex(cacheDir);
|
|
547
551
|
if (offline) {
|
|
548
552
|
if (!cached) throw new Error("--cve-offline set but no cached CVE index found");
|
|
549
553
|
return cached;
|
|
550
554
|
}
|
|
551
|
-
if (!force && !require('./cache-policy').shouldForceUpdate() && isCurrentCveIndex(cached) && isCveIndexFresh(ttlMs / 3600000)) return cached;
|
|
552
|
-
return downloadCveData({ verbose, force: !!force, revalidate: true });
|
|
555
|
+
if (!force && !require('./cache-policy').shouldForceUpdate() && isCurrentCveIndex(cached) && isCveIndexFresh(ttlMs / 3600000, cacheDir)) return cached;
|
|
556
|
+
return downloadCveData({ verbose, force: !!force, revalidate: true, cacheDir });
|
|
553
557
|
}
|
|
554
558
|
|
|
555
559
|
module.exports = {
|
package/lib/cve-match.js
CHANGED
|
@@ -221,6 +221,10 @@ function commonExclusions(sets) {
|
|
|
221
221
|
|
|
222
222
|
async function expandWithTransitives(resolvedDeps, opts = {}) {
|
|
223
223
|
const { verbose } = opts;
|
|
224
|
+
// Gradle allows a direct declaration to omit its version when another request
|
|
225
|
+
// on the same classpath supplies it. Resolve these before seeding the graph:
|
|
226
|
+
// they remain DIRECT dependencies, with their own scopes and exclusions.
|
|
227
|
+
await require("./codecs/gradle/versionless").recoverVersionlessGradle(resolvedDeps, opts);
|
|
224
228
|
// Root depMgmt: every dep in the Map that has a concrete version becomes a
|
|
225
229
|
// version override for transitive resolution. This catches cases where the
|
|
226
230
|
// project pins a transitive's version via <dependencyManagement>.
|
|
@@ -262,6 +266,12 @@ async function expandWithTransitives(resolvedDeps, opts = {}) {
|
|
|
262
266
|
// A depMgmt-only pin is not a dependency: it must not seed the graph (it would drag
|
|
263
267
|
// its whole subtree in). It still pins versions through rootDepMgmt above.
|
|
264
268
|
.filter(d => !d.managedOnly);
|
|
269
|
+
// An inferred plugin BOM is scoped to its sole Gradle script. Never let it
|
|
270
|
+
// become a version pin for Maven roots or another Gradle module.
|
|
271
|
+
for (const [key, m] of (opts.gradleBomDepMgmt || [])) {
|
|
272
|
+
if (!rootDepMgmt.has(key) && directs.length && directs.every(d => d.ecosystemType === "gradle"
|
|
273
|
+
&& d.manifestPaths?.length === 1 && d.manifestPaths[0] === m.manifestPath)) rootDepMgmt.set(key, { version: m.version, exclusions: [] });
|
|
274
|
+
}
|
|
265
275
|
|
|
266
276
|
if (verbose) console.log(`🌳 Resolving transitives for ${directs.length} direct deps…`);
|
|
267
277
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Native CVEProject records selected by explicit package identity; no product
|
|
3
|
+
// names, guessed aliases or unverified negative results enter the index.
|
|
4
|
+
const {packageName}=require('./advisory-store');
|
|
5
|
+
const tuple=(ecosystem,name)=>({source:'cveproject',ecosystem,name:packageName(ecosystem,name),version:'*'});
|
|
6
|
+
const key=p=>JSON.stringify([p.ecosystem,packageName(p.ecosystem,p.name)]);
|
|
7
|
+
function packageIdentities(deps){const found=new Map();for(const dep of deps.values()){if(dep.provenance==='binary')continue;const identity=require('./native-package-match').depIdentity(dep);if(identity)for(const ecosystem of [identity.ecosystem,...(identity.ecosystem.startsWith('system:deb:debian:')?['system:deb:debian:*']:[])])for(const name of identity.names){const p={ecosystem,name:packageName(ecosystem,name)};found.set(key(p),p);}}return [...found.values()].sort((a,b)=>key(a).localeCompare(key(b)));}
|
|
8
|
+
async function refreshPackageCves(deps,store,{ttlMs=4*3600000,getResource=require('./providers').getResource}={}){
|
|
9
|
+
const packages=packageIdentities(deps),needed=packages.filter(p=>require('./cache-policy').shouldForceUpdate() || !store.getQuery(tuple(p.ecosystem,p.name),{ttlMs})?.fresh);let incomplete=false,received=0;
|
|
10
|
+
for(let i=0;i<needed.length;i+=200){const batch=needed.slice(i,i+200),res=await getResource('github','cve-packages',{packages:batch},{forceRefresh:true});if(!res.ok)throw Error(`CVEProject package proxy HTTP ${res.status}`);const body=await res.json();if(!Array.isArray(body.records)||typeof body.complete!=='boolean'||body.scope!=='explicit-package-identities')throw Error('invalid CVEProject package proxy response');
|
|
11
|
+
const at=Date.parse(res.headers?.get('x-fad-proxy-fetched-at')||'');if(!Number.isFinite(at)||at<=0||at>Date.now()+300000)throw Error('CVEProject package response has no trustworthy source timestamp');
|
|
12
|
+
const stale=res.headers?.get('x-fad-proxy')==='stale'||Date.now()-at>=require('./cache-policy').DEFAULT_TTL_MS,byKey=new Map(batch.map(p=>[key(p),new Set()])),records=[];
|
|
13
|
+
for(const raw of body.records){const record=require('./native-advisories').cveEnvelope(raw,{fetchedAt:at,provenance:{transport:'proxy',stale}});let relevant=false;for(const container of [raw.containers?.cna,...(raw.containers?.adp||[])])for(const affected of container?.affected||[]){const p=require('./native-package-match').explicitNativePackage(affected,{source:'cveproject',record:raw,container});if(!p)continue;const k=key(p);if(byKey.has(k)){byKey.get(k).add(record.id);relevant=true;}}if(!relevant)throw Error('CVEProject package proxy returned an unrelated record');records.push(record);}
|
|
14
|
+
if(new Set(records.map(x=>x.id)).size!==records.length)throw Error('CVEProject package proxy returned duplicate records');
|
|
15
|
+
const queries=body.complete&&!stale?batch.map(p=>({...tuple(p.ecosystem,p.name),ids:[...byKey.get(key(p))].sort(),fetchedAt:at,complete:true,provenance:{transport:'proxy',scope:'explicit-package-identities'}})):[];store.commit({records,queries});received+=records.length;if(!body.complete||stale)incomplete=true;
|
|
16
|
+
}
|
|
17
|
+
return {packages:packages.length,requested:needed.length,received,incomplete};
|
|
18
|
+
}
|
|
19
|
+
module.exports={packageIdentities,refreshPackageCves,tuple};
|