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.
Files changed (107) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +51 -141
  3. package/completions/vigievuln.bash +1 -1
  4. package/completions/vigievuln.zsh +1 -0
  5. package/lib/account-client.js +21 -14
  6. package/lib/account-session.js +6 -2
  7. package/lib/advisory-compression.js +25 -0
  8. package/lib/advisory-fixes.js +21 -0
  9. package/lib/advisory-store-sqlite.js +156 -0
  10. package/lib/advisory-store.js +484 -0
  11. package/lib/airgap-project.js +117 -0
  12. package/lib/application-plugins/runner.js +22 -13
  13. package/lib/application-plugins/wordpress.js +4 -3
  14. package/lib/application-providers/live-snapshot.js +1 -12
  15. package/lib/application-providers/snapshot-cache.js +27 -0
  16. package/lib/application-providers/wordfence-client.js +3 -3
  17. package/lib/attribution.js +2 -2
  18. package/lib/cache-archive-sqlite.js +215 -0
  19. package/lib/cache-archive.js +357 -26
  20. package/lib/cache-db.js +142 -0
  21. package/lib/cache-directory.js +18 -74
  22. package/lib/cache-policy.js +25 -0
  23. package/lib/cache-repository.js +48 -0
  24. package/lib/cache-startup.js +54 -0
  25. package/lib/certfr.js +9 -9
  26. package/lib/cli-command-routing.js +29 -6
  27. package/lib/cli-groups.js +32 -3
  28. package/lib/cli-project-commands.js +47 -6
  29. package/lib/cli-setup.js +300 -0
  30. package/lib/codecs/binary/pe-metadata.js +79 -0
  31. package/lib/codecs/binary/scan.js +4 -3
  32. package/lib/codecs/binary.codec.js +4 -2
  33. package/lib/codecs/composer/registry.js +8 -6
  34. package/lib/codecs/go/parse.js +7 -9
  35. package/lib/codecs/go/registry.js +7 -5
  36. package/lib/codecs/go.codec.js +5 -0
  37. package/lib/codecs/maven.codec.js +73 -8
  38. package/lib/codecs/npm/collect.js +12 -5
  39. package/lib/codecs/npm/parse.js +12 -5
  40. package/lib/codecs/npm/registry.js +42 -12
  41. package/lib/codecs/nuget/registry.js +8 -6
  42. package/lib/codecs/pypi/registry.js +8 -6
  43. package/lib/codecs/ruby/registry.js +7 -5
  44. package/lib/compression-dictionary.js +5 -0
  45. package/lib/coverage-diagnostics.js +26 -0
  46. package/lib/cve-download.js +157 -41
  47. package/lib/cve-legacy-ranges.js +59 -0
  48. package/lib/cve-match.js +85 -17
  49. package/lib/cve-npm-proxy.js +29 -0
  50. package/lib/cve-report.js +145 -58
  51. package/lib/cve-version-verdict.js +77 -0
  52. package/lib/deps-descriptor.js +8 -3
  53. package/lib/epss.js +13 -8
  54. package/lib/euvd.js +32 -8
  55. package/lib/gcve-feed.js +103 -0
  56. package/lib/gcve-index.js +181 -0
  57. package/lib/gcve.js +1 -1
  58. package/lib/github-publisher-maven.js +40 -0
  59. package/lib/hash-id.js +5 -5
  60. package/lib/hosted-proxy.js +6 -1
  61. package/lib/i18n.js +31 -8
  62. package/lib/json-cache.js +18 -0
  63. package/lib/json-export.js +16 -2
  64. package/lib/kev.js +7 -8
  65. package/lib/line-stream.js +23 -0
  66. package/lib/maven-airgap.js +80 -0
  67. package/lib/maven-cache.js +21 -0
  68. package/lib/maven-license.js +2 -1
  69. package/lib/maven-presence.js +2 -2
  70. package/lib/maven-reactor.js +23 -14
  71. package/lib/maven-repo.js +11 -6
  72. package/lib/merge-sources.js +25 -18
  73. package/lib/native-advisories.js +268 -0
  74. package/lib/nvd-bulk.js +145 -0
  75. package/lib/nvd-package-ranges.js +109 -0
  76. package/lib/nvd.js +52 -24
  77. package/lib/osv-db.js +253 -59
  78. package/lib/osv-legacy.js +57 -0
  79. package/lib/osv.js +241 -168
  80. package/lib/outdated.js +11 -12
  81. package/lib/package-metadata.js +141 -0
  82. package/lib/package-versions.js +52 -0
  83. package/lib/packagist-audit.js +6 -6
  84. package/lib/provenance.js +73 -19
  85. package/lib/providers/common.js +11 -1
  86. package/lib/providers/gcve.js +17 -0
  87. package/lib/providers/github.js +1 -0
  88. package/lib/providers/index.js +49 -26
  89. package/lib/providers/vigievuln.js +7 -0
  90. package/lib/proxy-cache.js +1 -1
  91. package/lib/proxy-scope.js +59 -0
  92. package/lib/proxy-throttle.js +71 -0
  93. package/lib/resource-cache/engine.js +36 -9
  94. package/lib/resource-cache/sqlite-store.js +95 -0
  95. package/lib/resource-cache/validate.js +5 -0
  96. package/lib/retire.js +24 -24
  97. package/lib/ruby-version.js +36 -0
  98. package/lib/sarif-export.js +1 -1
  99. package/lib/sbom-export.js +11 -7
  100. package/lib/snyk.js +32 -20
  101. package/lib/source-profile.js +67 -0
  102. package/lib/sqlite-driver.js +46 -0
  103. package/lib/transitive.js +69 -34
  104. package/lib/unmanaged.js +2 -1
  105. package/lib/vigievuln-advisories.js +47 -0
  106. package/package.json +7 -6
  107. package/vigievuln.js +380 -107
package/lib/snyk.js CHANGED
@@ -26,7 +26,11 @@ async function runSnykTest(outputDir, opts = {}) {
26
26
  maxBuffer: 256 * 1024 * 1024,
27
27
  timeout: timeoutMs,
28
28
  });
29
- return parseSnykStdout(stdout);
29
+ const parsed = parseSnykStdout(stdout);
30
+ if (!parsed.length) throw new Error('snyk returned no project results');
31
+ const snykErr = snykOutputError(parsed);
32
+ if (snykErr) throw new Error(`snyk failed: ${snykErr}`);
33
+ return parsed;
30
34
  } catch (err) {
31
35
  if (err.code === "ENOENT") throw new Error("snyk CLI not found on PATH — install snyk separately");
32
36
  if (err.killed) throw new Error(`snyk timed out after ${Math.round(timeoutMs / 1000)}s (raise opts.timeoutMs)`);
@@ -37,8 +41,9 @@ async function runSnykTest(outputDir, opts = {}) {
37
41
  // as "0 vulnerabilities" → a silent success that hides a real snyk failure.
38
42
  if (err.stdout) {
39
43
  const parsed = parseSnykStdout(err.stdout);
44
+ if (!parsed.length) throw new Error('snyk returned no project results');
40
45
  const snykErr = snykOutputError(parsed);
41
- if (snykErr) throw new Error(`snyk failed (exit ${err.code}): ${snykErr}`);
46
+ if (snykErr || err.code !== 1) throw new Error(`snyk failed (exit ${err.code}): ${snykErr || err.message}`);
42
47
  return parsed;
43
48
  }
44
49
  // No JSON on stdout at all → surface stderr (the human-readable reason) rather
@@ -84,6 +89,7 @@ function parseSnykStdout(stdout) {
84
89
  for (const l of lines) {
85
90
  try { out.push(JSON.parse(l)); } catch { /* skip */ }
86
91
  }
92
+ if (!out.length) throw new Error('snyk returned invalid JSON');
87
93
  return out;
88
94
  }
89
95
  }
@@ -93,24 +99,24 @@ function parseSnykStdout(stdout) {
93
99
  * [{ dep: {groupId, artifactId, version}, cve: {id, severity, score, ...}, source: 'snyk' }]
94
100
  */
95
101
  function parseSnykResults(snykProjectsJson) {
102
+ const { makeDepRecord } = require('./dep-record');
96
103
  const out = [];
97
104
  const projects = Array.isArray(snykProjectsJson) ? snykProjectsJson : [snykProjectsJson];
98
105
  for (const proj of projects) {
99
106
  const vulns = proj?.vulnerabilities || [];
100
107
  for (const v of vulns) {
101
108
  const pkg = v.packageName || v.moduleName || "";
102
- const [groupId, artifactId] = pkg.includes(":") ? pkg.split(":") : [null, pkg];
109
+ const manager = String(proj.packageManager || '').toLowerCase();
110
+ const ecosystem = ({ maven:'maven', gradle:'maven', npm:'npm', yarn:'npm', pnpm:'npm', pip:'pypi', pipenv:'pypi', poetry:'pypi', rubygems:'ruby', nuget:'nuget', gomodules:'go', composer:'composer' })[manager] || (pkg.includes(':') ? 'maven' : 'npm');
111
+ const separator = ecosystem === 'maven' ? ':' : ecosystem === 'composer' ? '/' : null;
112
+ const at = separator ? pkg.indexOf(separator) : -1;
113
+ const namespace = at < 0 ? '' : pkg.slice(0, at), name = at < 0 ? pkg : pkg.slice(at + 1);
114
+ if (!name) continue;
103
115
  const cveIds = v.identifiers?.CVE || [];
104
116
  const cveId = cveIds[0] || v.id;
105
117
  const fixVersions = Array.isArray(v.fixedIn) ? v.fixedIn : [];
106
118
  out.push({
107
- dep: {
108
- groupId: groupId || "",
109
- artifactId: artifactId || "",
110
- version: v.version || "",
111
- scope: "compile",
112
- pomPaths: [],
113
- },
119
+ dep: makeDepRecord({ ecosystem, namespace, name, version: v.version || null }),
114
120
  cve: {
115
121
  id: cveId,
116
122
  severity: (v.severity || "UNKNOWN").toUpperCase(),
@@ -127,23 +133,29 @@ function parseSnykResults(snykProjectsJson) {
127
133
  }
128
134
 
129
135
  /**
130
- * Merge vigievuln and Snyk matches, deduping by (groupId:artifactId, cve.id).
131
- * When a finding exists in both, vigievuln's row is kept but tagged source='both'.
136
+ * Merge by ecosystem, package, version and advisory without discarding existing findings.
137
+ * When a finding exists in both, retain the original source and add Snyk.
132
138
  */
133
- function mergeWithFadResults(fadMatches, snykMatches) {
134
- const byKey = new Map();
135
- const k = m => `${m.dep.groupId}:${m.dep.artifactId}|${m.cve.id}`;
136
- for (const m of fadMatches || []) byKey.set(k(m), { ...m, source: "fad" });
139
+ function mergeWithFadResults(fadMatches, snykMatches, resolvedDeps) {
140
+ const byKey = new Map(), merged = [...(fadMatches || [])];
141
+ const k = m => JSON.stringify([m.dep.coordKey || `${m.dep.groupId}:${m.dep.artifactId}`, m.dep.version || null, m.cve.id]);
142
+ for (let i=0;i<merged.length;i++) {
143
+ const key=k(merged[i]);if(!byKey.has(key))byKey.set(key,[]);byKey.get(key).push(i);
144
+ }
137
145
  for (const s of snykMatches || []) {
138
146
  const key = k(s);
139
147
  if (byKey.has(key)) {
140
- const existing = byKey.get(key);
141
- byKey.set(key, { ...existing, source: "both" });
148
+ for(const index of byKey.get(key)) {
149
+ const existing=merged[index];
150
+ merged[index]={ ...existing, source: [...new Set([...(existing.source || 'cache').split('+'), 'snyk'])].sort().join('+') };
151
+ }
142
152
  } else {
143
- byKey.set(key, s);
153
+ const known=resolvedDeps?.get(s.dep.coordKey);
154
+ const versions=known?.versions?.length ? known.versions : [known?.version];
155
+ const dep=known && versions.includes(s.dep.version) ? {...known,version:s.dep.version} : s.dep;
156
+ byKey.set(key,[merged.length]);merged.push({...s,dep});
144
157
  }
145
158
  }
146
- const merged = [...byKey.values()];
147
159
  // Re-sort by severity (Snyk additions throw off ordering)
148
160
  const rank = { CRITICAL: 4, HIGH: 3, MEDIUM: 2, LOW: 1, NONE: 0, UNKNOWN: 0 };
149
161
  merged.sort((a, b) => {
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ // Geographic selection concerns the operator providing the advisory service,
4
+ // not the country in which an advisory was authored or a server is hosted.
5
+ // Package registries and non-vulnerability metadata remain available.
6
+ const PROFILES = new Set(['all', 'us', 'eu', 'proxy']);
7
+ const RESTRICTED_APP_OPTIONS = ['wordfenceFeed', 'wordfenceLive', 'wordfenceFeedUrl', 'wordfenceApiKey',
8
+ 'drupalAdvisories', 'drupalAdvisoriesLive', 'prestashopAdvisories', 'prestashopAdvisoriesLive',
9
+ 'typo3Advisories', 'typo3AdvisoriesLive', 'spipAdvisories', 'spipAdvisoriesLive'];
10
+
11
+ function applySourceProfile(options, {explicit = () => false} = {}) {
12
+ const out = {...options};
13
+ const profile = String(out.sourceProfile || 'all').toLowerCase();
14
+ if (!PROFILES.has(profile)) throw new Error('source profile must be all, us, eu or proxy');
15
+ out.sourceProfile = profile;
16
+ const warnings = [];
17
+ if (profile === 'eu' || profile === 'us') {
18
+ if (RESTRICTED_APP_OPTIONS.some(name => !!out[name])) throw new Error('Regional source profiles cannot use explicitly configured CMS advisory feeds: their origin cannot be verified.');
19
+ if (out.snyk) throw new Error('Regional source profiles cannot run Snyk; choose all sources for this integration.');
20
+ if (profile === 'eu' && (explicit('osvDb') && out.osvDb || out.osvDbRefresh)) throw new Error('--osv-db is unavailable in the EU-only source profile.');
21
+ // Application plugins auto-read source snapshots whose origin is not isolated
22
+ // by region in current cache formats. Suppress them until provenance is scoped.
23
+ out.appPlugins = 'none';
24
+ out.disableBinaryId = true; // hash lookups mix EU and US providers in one pipeline
25
+ if (profile === 'eu') {
26
+ Object.assign(out, {osv:false, osvDb:false, nvd:false, epss:false, kev:false, retire:false, nvdCpeMatch:false});
27
+ out.disableCveProject = true;
28
+ } else {
29
+ Object.assign(out, {euvd:false, certfr:false, packagistAudit:false});
30
+ out.disableGcve = true;
31
+ }
32
+ warnings.push(`The ${profile.toUpperCase()}-only profile excludes sources outside that region. CMS advisory plugins and native-binary identity are disabled because their current caches combine sources; advisory coverage is incomplete.`);
33
+ }
34
+ if (profile === 'proxy') {
35
+ if (!out.proxyCache) throw new Error('The proxy-only profile requires a configured proxy; run vigievuln setup.');
36
+ if (out.snyk) throw new Error('Snyk cannot be used in the proxy-only profile.');
37
+ }
38
+ return {options:out, warnings};
39
+ }
40
+
41
+ /** Network transport guard: provider bypasses and unrecognised redirects fail closed. */
42
+ function proxyOnlyFetch(fetcher, proxyUrl) {
43
+ const { proxyOrigin } = require('./proxy-scope');
44
+ const origin = proxyOrigin(proxyUrl);
45
+ return (input, init = {}) => {
46
+ let url;
47
+ try { url = new URL(typeof input === 'string' || input instanceof URL ? String(input) : input.url); }
48
+ catch { throw new Error('proxy-only: invalid network URL'); }
49
+ if (url.origin !== origin || url.username || url.password) throw new Error('proxy-only: direct network request blocked');
50
+ return fetcher(input, {...init, redirect:'error'});
51
+ };
52
+ }
53
+
54
+ /** Dedicated transport used only by the official account client while issuing a key. */
55
+ function officialAccountFetch(fetcher) {
56
+ const {ACCOUNT_ORIGIN} = require('./account-client');
57
+ const methods = new Map([['/v1/accounts/me','GET'],['/v1/accounts/login','POST'],['/v1/accounts/logout','POST'],['/v1/accounts/terms','POST'],['/v1/accounts/proxy-keys','POST']]);
58
+ return (input, init = {}) => {
59
+ let url; try { url = new URL(typeof input === 'string' || input instanceof URL ? String(input) : input.url); }
60
+ catch { throw new Error('official account: invalid URL'); }
61
+ if (url.origin !== ACCOUNT_ORIGIN || url.username || url.password || url.search || url.hash || methods.get(url.pathname) !== String(init.method || 'GET').toUpperCase())
62
+ throw new Error('official account: request blocked');
63
+ return fetcher(input, {...init,redirect:'error'});
64
+ };
65
+ }
66
+
67
+ module.exports = { applySourceProfile, proxyOnlyFetch, officialAccountFetch };
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+
6
+ function openSqlite(file, {readonly = false} = {}) {
7
+ if (file !== ':memory:') fs.mkdirSync(path.dirname(file), {recursive:true, mode:0o700});
8
+ const db = typeof Bun !== 'undefined'
9
+ ? new (require('bun:sqlite').Database)(file, {readonly, create:!readonly})
10
+ : new (require('node:sqlite').DatabaseSync)(file, {readOnly:readonly});
11
+ db.exec('PRAGMA foreign_keys=ON; PRAGMA busy_timeout=5000;');
12
+ if (!readonly) db.exec('PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL;');
13
+ const statements=new Map();
14
+ const prepared=new Set();
15
+ const prepare = sql => {
16
+ let statement=statements.get(sql);
17
+ if (!statement) {
18
+ statement=db.prepare(sql);
19
+ if(typeof Bun !== 'undefined') prepared.add(statement);
20
+ if (statements.size>=128) statements.delete(statements.keys().next().value);
21
+ statements.set(sql,statement);
22
+ }
23
+ return statement;
24
+ };
25
+ return {
26
+ // Bun's default close defers releasing the file while prepared statements
27
+ // exist. Finalize them immediately so Windows can rename/delete the cache.
28
+ file, prepare, exec:sql=>db.exec(sql), close:()=>{
29
+ statements.clear();
30
+ if(typeof Bun !== 'undefined') for(const statement of prepared) statement.finalize();
31
+ prepared.clear();
32
+ if(typeof Bun !== 'undefined') db.close(true); else db.close();
33
+ },
34
+ transaction(action) {
35
+ db.exec('BEGIN IMMEDIATE');
36
+ try {
37
+ const result=action();
38
+ if (result && typeof result.then === 'function') throw new Error('SQLite transaction callback must be synchronous');
39
+ db.exec('COMMIT'); return result;
40
+ }
41
+ catch(error) { try { db.exec('ROLLBACK'); } catch {} throw error; }
42
+ },
43
+ };
44
+ }
45
+
46
+ module.exports = {openSqlite};
package/lib/transitive.js CHANGED
@@ -42,6 +42,14 @@ const SCOPE_MATRIX = {
42
42
 
43
43
  function coord(v) { return v == null ? null : String(v).trim() || null; }
44
44
 
45
+ // Maven dependency-management keys include type and classifier. Keep the
46
+ // historical short key for ordinary jars; test-jars and classified artifacts
47
+ // must never donate their scope or version to a different artifact.
48
+ function managedKey(d) {
49
+ const base = `${d.groupId}:${d.artifactId}`, type = d.type || 'jar', classifier = d.classifier || (type === 'test-jar' ? 'tests' : '');
50
+ return type === 'jar' && !classifier ? base : `${base}:${type}:${classifier}`;
51
+ }
52
+
45
53
  function pomPath(g, a, v) {
46
54
  const gPath = g.replace(/\./g, "/");
47
55
  return `${MAVEN_CENTRAL}/${gPath}/${a}/${v}/${a}-${v}.pom`;
@@ -59,11 +67,20 @@ function cachePath(g, a, v, dir = POM_CACHE_DIR) {
59
67
  async function fetchPom(g, a, v, opts = {}) {
60
68
  const { verbose, offline, fetcher = globalThis.fetch, cacheDir = POM_CACHE_DIR, repos } = opts;
61
69
  const cf = cachePath(g, a, v, cacheDir);
62
- if (fs.existsSync(cf)) {
63
- const xml = await fs.promises.readFile(cf, "utf8");
64
- if (xml === "__NOT_FOUND__") return null;
65
- return xml;
70
+ let legacyNegative = false;
71
+ const cachedPom=require('./maven-cache').read(cf);
72
+ if (cachedPom) {
73
+ const xml = cachedPom.value;
74
+ if (offline || require('./cache-policy').fresh(cachedPom.fetchedAt)) {
75
+ if (xml !== "__NOT_FOUND__") return xml;
76
+ legacyNegative = true;
77
+ }
66
78
  }
79
+ // A public seed never overrides an existing locally configured repository.
80
+ const seeded = offline && (!Array.isArray(repos) || repos.every(r=>r.central === true))
81
+ ? require('./package-versions').getVersion('maven',`${g}:${a}`,String(v)) : null;
82
+ if (seeded) return seeded.body;
83
+ if (legacyNegative) return null;
67
84
  if (offline) return null;
68
85
  // Multi-repo path: try every user-configured repo, fall back to Maven
69
86
  // Central via lib/maven-repo. Falling back to the legacy single-URL
@@ -73,17 +90,15 @@ async function fetchPom(g, a, v, opts = {}) {
73
90
  const { fetchPomFromRepos } = require("./maven-repo");
74
91
  const hit = await fetchPomFromRepos(repos, g, a, v, { fetcher, userAgent: "vigievuln-transitive" });
75
92
  if (hit?.body) {
76
- await fs.promises.mkdir(cacheDir, { recursive: true });
77
- await fs.promises.writeFile(cf, hit.body);
93
+ require('./maven-cache').write(cf,hit.body);
78
94
  return hit.body;
79
95
  }
80
- await fs.promises.mkdir(cacheDir, { recursive: true });
81
- await fs.promises.writeFile(cf, "__NOT_FOUND__");
96
+ require('./maven-cache').write(cf,"__NOT_FOUND__");
82
97
  if (verbose) console.warn(` not found in any repo: ${g}:${a}:${v}`);
83
98
  return null;
84
99
  } catch (err) {
85
100
  if (verbose) console.warn(` multi-repo fetch failed: ${g}:${a}:${v} — ${err.message}`);
86
- return null;
101
+ return cachedPom?.value && cachedPom.value !== '__NOT_FOUND__' ? cachedPom.value : null;
87
102
  }
88
103
  }
89
104
  const url = pomPath(g, a, v);
@@ -92,22 +107,20 @@ async function fetchPom(g, a, v, opts = {}) {
92
107
  { path: `${g.replace(/\./g, "/")}/${a}/${v}/${a}-${v}.pom` },
93
108
  { fetcher, headers: { "User-Agent": "vigievuln-transitive" } });
94
109
  if (res.status === 404) {
95
- await fs.promises.mkdir(cacheDir, { recursive: true });
96
- await fs.promises.writeFile(cf, "__NOT_FOUND__");
110
+ require('./maven-cache').write(cf,"__NOT_FOUND__");
97
111
  if (verbose) console.warn(` 404: ${g}:${a}:${v}`);
98
112
  return null;
99
113
  }
100
114
  if (!res.ok) {
101
115
  if (verbose) console.warn(` HTTP ${res.status}: ${g}:${a}:${v}`);
102
- return null;
116
+ return cachedPom?.value && cachedPom.value !== '__NOT_FOUND__' ? cachedPom.value : null;
103
117
  }
104
118
  const xml = await res.text();
105
- await fs.promises.mkdir(cacheDir, { recursive: true });
106
- await fs.promises.writeFile(cf, xml);
119
+ require('./maven-cache').write(cf,xml);
107
120
  return xml;
108
121
  } catch (err) {
109
122
  if (verbose) console.warn(` fetch failed: ${g}:${a}:${v} — ${err.message}`);
110
- return null;
123
+ return cachedPom?.value && cachedPom.value !== '__NOT_FOUND__' ? cachedPom.value : null;
111
124
  }
112
125
  }
113
126
 
@@ -155,6 +168,7 @@ async function parsePomXml(xml) {
155
168
  scopeDeclared: !!coord(d.scope?.[0]),
156
169
  optional: d.optional?.[0] === "true",
157
170
  type: coord(d.type?.[0]) || "jar",
171
+ classifier: coord(d.classifier?.[0]) || "",
158
172
  exclusions: (d.exclusions?.[0]?.exclusion || []).map(e => ({
159
173
  groupId: coord(e.groupId?.[0]),
160
174
  artifactId: coord(e.artifactId?.[0]),
@@ -206,13 +220,17 @@ async function effectivePom(g, a, v, opts = {}, seen = new Set()) {
206
220
  // result for a g:a:v is stable, so caching the finished object is safe; callers
207
221
  // only READ eff.depMgmt/eff.deps. Only active when opts.effCache is supplied,
208
222
  // so existing single-shot callers are byte-for-byte unchanged.
209
- if (opts.effCache && opts.effCache.has(key)) return opts.effCache.get(key);
223
+ if (opts.effCache && opts.effCache.has(key)) {
224
+ const cached = opts.effCache.get(key);
225
+ if (!cached) opts.onMissingPom?.({ groupId: g, artifactId: a, version: v });
226
+ return cached;
227
+ }
210
228
  seen.add(key);
211
229
 
212
230
  const xml = await fetchPom(g, a, v, opts);
213
- if (!xml) { if (opts.effCache) opts.effCache.set(key, null); return null; }
231
+ if (!xml) { opts.onMissingPom?.({ groupId: g, artifactId: a, version: v }); if (opts.effCache) opts.effCache.set(key, null); return null; }
214
232
  const pom = await parsePomXml(xml);
215
- if (!pom) { if (opts.effCache) opts.effCache.set(key, null); return null; }
233
+ if (!pom) { opts.onMissingPom?.({ groupId: g, artifactId: a, version: v }); if (opts.effCache) opts.effCache.set(key, null); return null; }
216
234
 
217
235
  let merged = {
218
236
  groupId: pom.groupId,
@@ -224,7 +242,9 @@ async function effectivePom(g, a, v, opts = {}, seen = new Set()) {
224
242
  };
225
243
 
226
244
  if (pom.parent) {
227
- const parentEff = await effectivePom(pom.parent.groupId, pom.parent.artifactId, pom.parent.version, opts, seen);
245
+ // A completed parent traversal must not mark that parent as active when a
246
+ // later sibling BOM inherits it too. Keep cycle detection per branch.
247
+ const parentEff = await effectivePom(pom.parent.groupId, pom.parent.artifactId, pom.parent.version, opts, new Set(seen));
228
248
  if (parentEff) {
229
249
  merged.properties = { ...parentEff.properties, ...merged.properties };
230
250
  merged.parentVersion = parentEff.version;
@@ -237,8 +257,8 @@ async function effectivePom(g, a, v, opts = {}, seen = new Set()) {
237
257
  // Maven inherits the parent's <dependencies>, but a child that REDECLARES one
238
258
  // overrides it: concatenating both let the BFS pick the parent's first (a
239
259
  // child pinning X:2.0 over an inherited X:1.0 resolved as 1.0).
240
- const own = new Set(merged.deps.map(d => `${d.groupId}:${d.artifactId}`));
241
- merged.deps = [...parentEff.deps.filter(d => !own.has(`${d.groupId}:${d.artifactId}`)), ...merged.deps];
260
+ const own = new Set(merged.deps.map(managedKey));
261
+ merged.deps = [...parentEff.deps.filter(d => !own.has(managedKey(d))), ...merged.deps];
242
262
  }
243
263
  }
244
264
 
@@ -267,6 +287,8 @@ async function effectivePom(g, a, v, opts = {}, seen = new Set()) {
267
287
  groupId: resolveProps(d.groupId, effProps, builtins),
268
288
  artifactId: resolveProps(d.artifactId, effProps, builtins),
269
289
  version: normalizeHardPin(resolveProps(d.version, effProps, builtins)),
290
+ type: resolveProps(d.type, effProps, builtins),
291
+ classifier: resolveProps(d.classifier, effProps, builtins),
270
292
  });
271
293
  merged.depMgmt = merged.depMgmt.map(resolveDep);
272
294
  merged.deps = merged.deps.map(resolveDep);
@@ -281,7 +303,7 @@ async function effectivePom(g, a, v, opts = {}, seen = new Set()) {
281
303
  // The previous last-wins pass let a later import override both. Each key appears once in
282
304
  // the result, so buildMgmt's last-wins has nothing left to get wrong.
283
305
  const importOpts = ovKeys.length ? { ...opts, propertyOverrides: undefined } : opts;
284
- const keyOf = d => `${d.groupId}:${d.artifactId}`;
306
+ const keyOf = managedKey;
285
307
  const explicit = new Map(); // later (child) entries override earlier (parent)
286
308
  for (const dm of merged.depMgmt) if (dm.scope !== "import" && !dm.fromImport) explicit.set(keyOf(dm), dm);
287
309
  const result = new Map(explicit);
@@ -310,7 +332,7 @@ async function effectivePom(g, a, v, opts = {}, seen = new Set()) {
310
332
  function buildMgmt(depMgmt) {
311
333
  const m = new Map();
312
334
  for (const d of depMgmt) {
313
- if (d.groupId && d.artifactId) m.set(`${d.groupId}:${d.artifactId}`, d);
335
+ if (d.groupId && d.artifactId) m.set(managedKey(d), d);
314
336
  }
315
337
  return m;
316
338
  }
@@ -320,7 +342,7 @@ function buildMgmt(depMgmt) {
320
342
  const SCOPE_BREADTH = { compile: 4, runtime: 3, provided: 2, test: 1 };
321
343
  const wider = (a, b) => (SCOPE_BREADTH[a] || 0) > (SCOPE_BREADTH[b] || 0);
322
344
 
323
- const METADATA_TTL_MS = 24 * 3600 * 1000;
345
+ const METADATA_TTL_MS = 4 * 3600 * 1000;
324
346
  /**
325
347
  * Every published version of g:a (maven-metadata.xml), to resolve a version RANGE the way
326
348
  * Maven does: the highest version inside it. Cached beside the POMs; 24 h online, any age
@@ -334,10 +356,8 @@ async function fetchMetadataVersions(g, a, opts = {}) {
334
356
  // Central" is exactly what identifies a commercial build (lib/commercial-support.js).
335
357
  const cf = path.join(cacheDir, `${seg(g)}__${seg(a)}__maven-metadata${Array.isArray(repos) && repos.length ? "-repos" : ""}.xml`);
336
358
  const parse = xml => [...String(xml).matchAll(/<version>([^<]+)<\/version>/g)].map(m => m[1].trim()).filter(Boolean);
337
- try {
338
- const st = fs.statSync(cf);
339
- if (offline || (!require("./providers").hasHostedProxy() && Date.now() - st.mtimeMs < METADATA_TTL_MS)) return parse(fs.readFileSync(cf, "utf8"));
340
- } catch { /* not cached */ }
359
+ const cached=require('./maven-cache').read(cf);
360
+ if(cached && (offline || (!require("./providers").hasHostedProxy() && require('./cache-policy').fresh(cached.fetchedAt,METADATA_TTL_MS)))) return parse(cached.value);
341
361
  if (offline) return [];
342
362
  let body = null;
343
363
  try {
@@ -351,7 +371,7 @@ async function fetchMetadataVersions(g, a, opts = {}) {
351
371
  }
352
372
  } catch { body = null; }
353
373
  if (!body) return [];
354
- try { fs.mkdirSync(cacheDir, { recursive: true }); fs.writeFileSync(cf, body); } catch { /* cache is best-effort */ }
374
+ require('./maven-cache').write(cf,body);
355
375
  return parse(body);
356
376
  }
357
377
 
@@ -399,7 +419,7 @@ async function resolveTransitiveDeps(directDeps, opts = {}) {
399
419
  repos, // optional repo list (lib/maven-repo). Falls back to repo1.maven.org alone.
400
420
  effCache,
401
421
  } = opts;
402
- const fetchOpts = { verbose, offline, fetcher, cacheDir, repos, ...(effCache ? { effCache } : {}) };
422
+ const fetchOpts = { verbose, offline, fetcher, cacheDir, repos, ...(effCache ? { effCache } : {}), ...(opts.onMissingPom ? { onMissingPom: opts.onMissingPom } : {}) };
403
423
 
404
424
  // A managed entry is `{ version, exclusions? }` (global pass) or a bare version string
405
425
  // (per-module management). Reading `.version` off a string gave
@@ -417,18 +437,27 @@ async function resolveTransitiveDeps(directDeps, opts = {}) {
417
437
  };
418
438
 
419
439
  const visited = new Set();
440
+ const variants = new Map(), reportedVariants = new Set();
441
+ const noteVariant = dep => {
442
+ const key = `${dep.groupId}:${dep.artifactId}`, variant = managedKey(dep), old = variants.get(key);
443
+ if (old && old !== variant && !reportedVariants.has(key)) {
444
+ reportedVariants.add(key);
445
+ opts.onVariantCollision?.({groupId:dep.groupId,artifactId:dep.artifactId});
446
+ } else if (!old) variants.set(key, variant);
447
+ };
420
448
  const out = new Map();
421
449
  let level = [];
422
450
  for (const dep of directDeps) {
423
451
  if (!dep.groupId || !dep.artifactId || !dep.version) continue;
424
452
  const v = await concrete(dep.groupId, dep.artifactId, dep.version);
425
453
  if (!v) continue;
454
+ noteVariant(dep);
426
455
  level.push({
427
456
  groupId: dep.groupId, artifactId: dep.artifactId, version: v,
428
457
  scope: dep.scope || "compile", depth: 0, via: [],
429
458
  // Maven applies a <dependencyManagement> entry's <exclusions> to the managed dep
430
459
  // wherever it appears, on top of the ones declared on the dependency itself.
431
- rootExclusions: [...(dep.exclusions || []), ...(managed(`${dep.groupId}:${dep.artifactId}`)?.exclusions || [])],
460
+ rootExclusions: [...(dep.exclusions || []), ...(managed(managedKey(dep))?.exclusions || [])],
432
461
  });
433
462
  visited.add(`${dep.groupId}:${dep.artifactId}`);
434
463
  }
@@ -436,7 +465,10 @@ async function resolveTransitiveDeps(directDeps, opts = {}) {
436
465
  const widened = [];
437
466
  for (let depth = 0; level.length && depth < maxDepth; depth++) {
438
467
  const effs = await mapLimit(level, concurrency, n =>
439
- effectivePom(n.groupId, n.artifactId, n.version, fetchOpts).catch(() => null));
468
+ effectivePom(n.groupId, n.artifactId, n.version, fetchOpts).catch(() => {
469
+ opts.onResolutionError?.();
470
+ return null;
471
+ }));
440
472
  const next = [];
441
473
  for (let i = 0; i < level.length; i++) {
442
474
  const node = level[i];
@@ -460,12 +492,13 @@ async function resolveTransitiveDeps(directDeps, opts = {}) {
460
492
  // declares logback-classic bare, its parent manages it <scope>test</scope> —
461
493
  // read as compile, logback-classic:1.1.2 landed on a production classpath it is
462
494
  // not on, with a CRITICAL.
463
- const own = mgmt.get(childKey);
495
+ const own = mgmt.get(managedKey(dep));
464
496
  const depScope = dep.scopeDeclared === false && own?.scope && own.scope !== "import" ? own.scope : (dep.scope || "compile");
465
497
  const depExclusions = (dep.exclusions && dep.exclusions.length) ? dep.exclusions : (own?.exclusions || []);
466
498
 
467
499
  const propagated = SCOPE_MATRIX[node.scope]?.[depScope];
468
500
  if (!propagated || !includedScopes.includes(propagated)) continue;
501
+ noteVariant(dep);
469
502
 
470
503
  const via = [...node.via, nodeKey];
471
504
  if (visited.has(childKey)) {
@@ -481,7 +514,7 @@ async function resolveTransitiveDeps(directDeps, opts = {}) {
481
514
  }
482
515
 
483
516
  // Version: root pin > declared > the POM's own managed version.
484
- const pinned = managed(childKey);
517
+ const pinned = managed(managedKey(dep));
485
518
  let resolvedVersion = (pinned && pinned.version) || dep.version || (own && own.version) || null;
486
519
  // A floor (a Gradle constraint), not a force: the requested version wins when higher.
487
520
  if (pinned?.minimum && dep.version && !isVersionRange(dep.version) && !/\$\{/.test(dep.version)
@@ -511,6 +544,7 @@ async function resolveTransitiveDeps(directDeps, opts = {}) {
511
544
  level = next;
512
545
  if (verbose && process.stdout.isTTY) process.stdout.write(`\r resolved ${out.size} transitives, depth ${depth + 1} `);
513
546
  }
547
+ if (level.length) opts.onDepthLimit?.(level.length);
514
548
 
515
549
  // A widened winner widens its subtree too (Maven re-derives the children's scope from the
516
550
  // winner's). Entries in depth order, so a parent is settled before its children.
@@ -539,6 +573,7 @@ module.exports = {
539
573
  fetchPom,
540
574
  resolveProps,
541
575
  buildMgmt,
576
+ managedKey,
542
577
  POM_CACHE_DIR,
543
578
  SCOPE_MATRIX,
544
579
  };
package/lib/unmanaged.js CHANGED
@@ -67,6 +67,7 @@ function buildInventory(resolved) {
67
67
  declaredName: d.declaredName || d.name || null,
68
68
  provenance: d.provenance,
69
69
  hashes: d.hashes,
70
+ binaryMetadata: d.binaryMetadata || null,
70
71
  identity,
71
72
  integrity: d.integrity || "unknown",
72
73
  noOnlineInfo: !identity,
@@ -75,7 +76,7 @@ function buildInventory(resolved) {
75
76
  knownMalicious: !!(identity && identity.knownMalicious),
76
77
  });
77
78
  }
78
- out.sort((a, b) => String(a.path).localeCompare(String(b.path)));
79
+ out.sort((a, b) => Number(!/\.exe$/i.test(a.path || "")) - Number(!/\.exe$/i.test(b.path || "")) || String(a.path).localeCompare(String(b.path)));
79
80
  return out;
80
81
  }
81
82
 
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+ // Targeted consultations of our published advisories. A query is a snapshot of
3
+ // one package, including an empty result; it can supersede older cached entries.
4
+ const {packageName,queryCoversRecord}=require('./advisory-store');
5
+ const tuple=p=>({source:'vigievuln',ecosystem:p.ecosystem,name:p.name,version:'*'});
6
+ const key=p=>JSON.stringify([p.ecosystem,p.ecosystem==='Maven'?p.name:packageName(p.ecosystem,p.name)]);
7
+ function packagesFor(resolved){
8
+ const {osvEcosystemFor,osvPkgName}=require('./osv'),out=new Map();
9
+ for(const dep of resolved.values()){
10
+ if(!dep || dep.scope==='parent'||dep.provenance==='binary'||!['maven','npm','yarn'].includes(dep.ecosystem))continue;
11
+ const ecosystem=osvEcosystemFor(dep),name=osvPkgName(dep);if(!name)continue;
12
+ const p={ecosystem,name:ecosystem==='Maven'?name:packageName(ecosystem,name)};out.set(key(p),p);
13
+ }
14
+ return [...out.values()].sort((a,b)=>key(a).localeCompare(key(b)));
15
+ }
16
+ async function refreshReviewed(resolved,store,{ttlMs=4 * 3600000,getResource=require('./providers').getResource}={}){
17
+ const packages=packagesFor(resolved),needed=packages.filter(p=>require('./cache-policy').shouldForceUpdate() || !store.getQuery(tuple(p),{ttlMs})?.fresh);let received=0;
18
+ for(let i=0;i<needed.length;i+=200){
19
+ const batch=needed.slice(i,i+200),response=await getResource('vigievuln','advisories',{packages:batch},{forceRefresh:true});
20
+ if(!response.ok)throw Error(`reviewed advisory proxy HTTP ${response.status}`);
21
+ const body=await response.json();if(body?.complete!==true||!Array.isArray(body.records))throw Error('incomplete reviewed advisory response');
22
+ const serverAt=Date.parse(response.headers?.get('x-fad-proxy-fetched-at')||''),now=Date.now();
23
+ if(!Number.isFinite(serverAt)||serverAt<=0||serverAt>now+300000)throw Error('reviewed advisory response has no trustworthy timestamp');
24
+ // Clock skew must not make a just-observed snapshot appear stale locally.
25
+ // Clamping backward is conservative for later withdrawal comparisons.
26
+ const at=Math.min(serverAt,now);
27
+ if(response.headers?.get('x-fad-proxy')==='stale')throw Error('reviewed advisory response is stale');
28
+ const expected=new Map(batch.map(p=>[key(p),new Set()])),records=[];
29
+ for(const document of body.records){
30
+ if(!document||!/^(?:VV:CVE-\d{4}-\d{4,}|vv:CVE-\d{4}-\d{4,}:[a-zA-Z0-9._-]+)$/.test(document.id||'')||!Array.isArray(document.affected)||!document.curation?.method||!Array.isArray(document.references))throw Error('invalid reviewed advisory');
31
+ const bindings=[];
32
+ for(const entry of document.affected){const p=entry?.package;if(!p||!['Maven','npm'].includes(p.ecosystem)||typeof p.name!=='string'||!p.name||!Array.isArray(entry.ranges)||!Array.isArray(entry.versions))throw Error('invalid reviewed advisory package');bindings.push(p);if(expected.has(key(p)))expected.get(key(p)).add(document.id);}
33
+ if(!bindings.some(p=>expected.has(key(p))))throw Error('unrelated reviewed advisory');
34
+ records.push({source:'vigievuln',document,packages:bindings,fetchedAt:at,modifiedAt:document.modifiedAt||null,provenance:{transport:'vigievuln-proxy'}});
35
+ }
36
+ if(new Set(records.map(r=>r.document.id)).size!==records.length)throw Error('duplicate reviewed advisory');
37
+ const queries=batch.map(p=>({...tuple(p),ids:[...expected.get(key(p))].sort(),fetchedAt:at,complete:true,provenance:{transport:'vigievuln-proxy'}}));
38
+ store.commit({records,queries});received+=records.length;
39
+ }
40
+ return {packages:packages.length,requested:needed.length,received};
41
+ }
42
+ function isCurrentForPackage(store,p,record){
43
+ const query=store.getQuery(tuple(p),{ttlMs:Number.MAX_SAFE_INTEGER});
44
+ // A confirmed absence supersedes only a record no newer than the snapshot.
45
+ return !(query && query.provenance?.stale!==true && queryCoversRecord(query,record) && !query.ids.includes(record.document.id));
46
+ }
47
+ module.exports={packagesFor,refreshReviewed,isCurrentForPackage};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vigievuln",
3
- "version": "1.1.2",
4
- "description": "One-shot polyglot dependency auditor (10 ecosystems + 9 CMS/Frameworks). No build tools. Real & complete air-gapped mode. Private deps, binaries, certs, EOL, CVE (KEV+EPSS) - Made for professional code audits.",
3
+ "version": "1.2.0",
4
+ "description": "Polyglot dependency auditor for Maven, Gradle, JavaScript, Composer, PyPI, NuGet, Go, Ruby and 9 CMS/frameworks, with offline scans and audit reports.",
5
5
  "keywords": [
6
6
  "sca",
7
7
  "software-composition-analysis",
@@ -81,7 +81,7 @@
81
81
  "fad": "vigievuln.js"
82
82
  },
83
83
  "scripts": {
84
- "test": "node --test test/*.test.js",
84
+ "test": "node scripts/run-tests.js",
85
85
  "build:linux": "bun build vigievuln.js --compile --target=bun-linux-x64 --outfile=dist/vigievuln",
86
86
  "build:win": "bun build vigievuln.js --compile --target=bun-windows-x64 --outfile=dist/vigievuln.exe",
87
87
  "build:macos": "bun build vigievuln.js --compile --target=bun-darwin-x64 --outfile=dist/vigievuln-macos",
@@ -91,17 +91,18 @@
91
91
  "dependencies": {
92
92
  "chalk": "^4.1.2",
93
93
  "commander": "^14.0.3",
94
+ "enquirer": "^2.4.1",
94
95
  "fflate": "^0.8.3",
95
96
  "js-yaml": "^4.3.2",
96
- "minimatch": "^10.2.6",
97
+ "minimatch": "^11.0.4",
97
98
  "p-limit": "^3.1.0",
98
99
  "retire": "^6.1.0",
99
- "rimraf": "^6.1.3",
100
+ "rimraf": "^6.1.4",
100
101
  "smol-toml": "^1.8.0",
101
102
  "xml2js": "^0.6.2"
102
103
  },
103
104
  "engines": {
104
- "node": "^20.19.0 || >=22.12.0"
105
+ "node": "^22.13.0 || ^23.4.0 || >=24.0.0"
105
106
  },
106
107
  "files": [
107
108
  "vigievuln.js",