vigievuln 1.3.1 → 1.3.3

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 (110) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +1 -1
  3. package/data/fingerprints/index.js +80 -0
  4. package/data/fingerprints/interpreters/javascript/bun.json +23 -0
  5. package/data/fingerprints/interpreters/javascript/deno.json +10 -0
  6. package/data/fingerprints/interpreters/javascript/electron.json +20 -0
  7. package/data/fingerprints/interpreters/javascript/gjs.json +8 -0
  8. package/data/fingerprints/interpreters/javascript/javascriptcore.json +14 -0
  9. package/data/fingerprints/interpreters/javascript/jscgtk.json +10 -0
  10. package/data/fingerprints/interpreters/javascript/node.json +26 -0
  11. package/data/fingerprints/interpreters/javascript/nwjs.json +8 -0
  12. package/data/fingerprints/interpreters/javascript/webkitgtk.json +10 -0
  13. package/data/fingerprints/interpreters/javascript/wpewebkit.json +10 -0
  14. package/data/fingerprints/interpreters/languages/dotnet.json +8 -0
  15. package/data/fingerprints/interpreters/languages/erlang.json +9 -0
  16. package/data/fingerprints/interpreters/languages/gawk.json +10 -0
  17. package/data/fingerprints/interpreters/languages/guile.json +9 -0
  18. package/data/fingerprints/interpreters/languages/java.json +8 -0
  19. package/data/fingerprints/interpreters/languages/julia.json +9 -0
  20. package/data/fingerprints/interpreters/languages/lua.json +11 -0
  21. package/data/fingerprints/interpreters/languages/luajit.json +10 -0
  22. package/data/fingerprints/interpreters/languages/perl.json +11 -0
  23. package/data/fingerprints/interpreters/languages/php.json +22 -0
  24. package/data/fingerprints/interpreters/languages/powershell.json +17 -0
  25. package/data/fingerprints/interpreters/languages/pypy.json +8 -0
  26. package/data/fingerprints/interpreters/languages/python.json +24 -0
  27. package/data/fingerprints/interpreters/languages/r.json +9 -0
  28. package/data/fingerprints/interpreters/languages/racket.json +9 -0
  29. package/data/fingerprints/interpreters/languages/raku.json +8 -0
  30. package/data/fingerprints/interpreters/languages/ruby.json +21 -0
  31. package/data/fingerprints/interpreters/languages/tcl.json +9 -0
  32. package/data/fingerprints/interpreters/shells/bash.json +10 -0
  33. package/data/fingerprints/interpreters/shells/dash.json +8 -0
  34. package/data/fingerprints/interpreters/shells/fish.json +9 -0
  35. package/data/fingerprints/interpreters/shells/ksh.json +8 -0
  36. package/data/fingerprints/interpreters/shells/zsh.json +9 -0
  37. package/data/fingerprints/services/databases/clickhouse.json +8 -0
  38. package/data/fingerprints/services/databases/elasticsearch.json +8 -0
  39. package/data/fingerprints/services/databases/etcd.json +9 -0
  40. package/data/fingerprints/services/databases/mariadb.json +9 -0
  41. package/data/fingerprints/services/databases/memcached.json +9 -0
  42. package/data/fingerprints/services/databases/mongo.json +8 -0
  43. package/data/fingerprints/services/databases/mysql.json +9 -0
  44. package/data/fingerprints/services/databases/opensearch.json +8 -0
  45. package/data/fingerprints/services/databases/postgres.json +18 -0
  46. package/data/fingerprints/services/databases/redis.json +9 -0
  47. package/data/fingerprints/services/databases/valkey.json +8 -0
  48. package/data/fingerprints/services/dns-directory/bind.json +8 -0
  49. package/data/fingerprints/services/dns-directory/dnsmasq.json +8 -0
  50. package/data/fingerprints/services/dns-directory/slapd.json +8 -0
  51. package/data/fingerprints/services/dns-directory/unbound.json +8 -0
  52. package/data/fingerprints/services/mail/cyrus.json +8 -0
  53. package/data/fingerprints/services/mail/dovecot.json +8 -0
  54. package/data/fingerprints/services/mail/exim.json +9 -0
  55. package/data/fingerprints/services/mail/opendkim.json +8 -0
  56. package/data/fingerprints/services/mail/opensmtpd.json +8 -0
  57. package/data/fingerprints/services/mail/postfix.json +8 -0
  58. package/data/fingerprints/services/mail/rspamd.json +8 -0
  59. package/data/fingerprints/services/mail/sendmail.json +8 -0
  60. package/data/fingerprints/services/messaging/kafka.json +8 -0
  61. package/data/fingerprints/services/messaging/mosquitto.json +8 -0
  62. package/data/fingerprints/services/messaging/nats.json +9 -0
  63. package/data/fingerprints/services/messaging/rabbitmq.json +8 -0
  64. package/data/fingerprints/services/remote-access/dropbear.json +8 -0
  65. package/data/fingerprints/services/remote-access/openssh.json +10 -0
  66. package/data/fingerprints/services/remote-access/proftpd.json +8 -0
  67. package/data/fingerprints/services/remote-access/samba.json +8 -0
  68. package/data/fingerprints/services/remote-access/vsftpd.json +8 -0
  69. package/data/fingerprints/services/web-proxies/apache.json +18 -0
  70. package/data/fingerprints/services/web-proxies/caddy.json +9 -0
  71. package/data/fingerprints/services/web-proxies/envoy.json +8 -0
  72. package/data/fingerprints/services/web-proxies/haproxy.json +10 -0
  73. package/data/fingerprints/services/web-proxies/lighttpd.json +8 -0
  74. package/data/fingerprints/services/web-proxies/nginx.json +14 -0
  75. package/data/fingerprints/services/web-proxies/squid.json +8 -0
  76. package/data/fingerprints/services/web-proxies/tomcat.json +8 -0
  77. package/data/fingerprints/services/web-proxies/traefik.json +9 -0
  78. package/data/fingerprints/services/web-proxies/varnish.json +8 -0
  79. package/lib/artifacts/component-scope.js +26 -3
  80. package/lib/artifacts/elf-product.js +215 -0
  81. package/lib/artifacts/image-products.js +180 -0
  82. package/lib/artifacts/install-version.js +44 -0
  83. package/lib/artifacts/inventory-scope.js +2 -1
  84. package/lib/artifacts/pe-product.js +28 -0
  85. package/lib/artifacts/product-advisories.js +207 -0
  86. package/lib/artifacts/product-catalog.js +62 -0
  87. package/lib/artifacts/report-inventory.js +7 -1
  88. package/lib/artifacts/report.js +42 -7
  89. package/lib/artifacts/retire.js +80 -0
  90. package/lib/artifacts/scan.js +40 -13
  91. package/lib/cli-image.js +6 -1
  92. package/lib/codecs/binary/elf-metadata.js +6 -0
  93. package/lib/codecs/binary/metadata.js +1 -1
  94. package/lib/codecs/binary/pe-metadata.js +47 -11
  95. package/lib/codecs/binary/scan.js +1 -1
  96. package/lib/cve-report.js +26 -3
  97. package/lib/i18n.js +2 -0
  98. package/lib/image-references.js +21 -1
  99. package/lib/json-export.js +2 -2
  100. package/lib/providers/nvd.js +16 -2
  101. package/lib/report-notices.js +1 -1
  102. package/lib/resource-cache/engine.js +3 -2
  103. package/lib/resource-cache/validate.js +1 -0
  104. package/lib/retire.js +12 -10
  105. package/lib/source-image-scan.js +1 -0
  106. package/lib/system-inventory/collect.js +1 -1
  107. package/lib/system-inventory/distribution-sources.js +1 -1
  108. package/lib/system-inventory/nginx-advisories.js +26 -8
  109. package/package.json +1 -1
  110. package/vigievuln.js +3 -1
@@ -0,0 +1,180 @@
1
+ 'use strict';
2
+
3
+ const { makeDepRecord } = require('../dep-record');
4
+ const { catalog, binaryProduct, imageProduct } = require('./product-catalog');
5
+
6
+ function describe(dep) {
7
+ const product = imageProduct(dep);
8
+ return product ? { id: product.id, label: product.label, category: product.category } : null;
9
+ }
10
+
11
+ function applyProductVersions(deps) {
12
+ const binaries = deps.filter((d) => d.ecosystem === 'binary');
13
+ const libraries = new Map(),
14
+ additions = [],
15
+ linkedFiles = new Set();
16
+ for (const dep of binaries) {
17
+ const meta = dep.binaryMetadata,
18
+ name = meta?.soname || dep.name;
19
+ if (!name.startsWith('lib')) continue;
20
+ const list = libraries.get(name) || [];
21
+ list.push(dep);
22
+ libraries.set(name, list);
23
+ }
24
+ for (const dep of binaries) {
25
+ const meta = dep.binaryMetadata;
26
+ if (!['elf', 'pe'].includes(meta?.format) || meta.status === 'unavailable') continue;
27
+ const product = binaryProduct(dep.name);
28
+ const evidence = (meta.products || []).map((item) => ({ item, provider: dep }));
29
+ if (product && !evidence.some(({ item }) => item.id === product.id)) {
30
+ const candidates = (meta.needed || [])
31
+ .flatMap((name) => libraries.get(name) || [])
32
+ .filter((lib) => lib.binaryMetadata?.machine === meta.machine && lib.binaryMetadata.bits === meta.bits);
33
+ for (const provider of candidates) {
34
+ const item = provider.binaryMetadata.products?.find((item) => item.id === product.id);
35
+ const soname = provider.binaryMetadata.soname || provider.name;
36
+ if (
37
+ item &&
38
+ candidates.filter((lib) => (lib.binaryMetadata?.soname || lib.name) === soname).length === 1
39
+ )
40
+ evidence.push({ item, provider });
41
+ }
42
+ }
43
+ for (const { item, provider } of evidence) {
44
+ if (provider !== dep) linkedFiles.add(JSON.stringify([provider.artifactPath, item.id]));
45
+ if (
46
+ evidence.filter((e) => e.item.id === item.id && e.item.resourceOffset === item.resourceOffset)
47
+ .length !== 1
48
+ )
49
+ continue;
50
+ const proof = {
51
+ product: item.id,
52
+ source: item.source,
53
+ binaryPath: dep.artifactPath,
54
+ versionPath: item.path || provider.artifactPath,
55
+ ...(item.resourceOffset !== undefined
56
+ ? { resourceId: item.resourceId, resourceOffset: item.resourceOffset }
57
+ : {})
58
+ };
59
+ if (item.resourceOffset !== undefined || item.id !== product?.id) {
60
+ const embedded = makeDepRecord({
61
+ ecosystem: 'image-product',
62
+ name: item.id,
63
+ version: item.version,
64
+ manifestPath: dep.artifactPath,
65
+ scope: 'runtime',
66
+ provenance: 'embedded-runtime'
67
+ });
68
+ additions.push({
69
+ ...embedded,
70
+ artifactPath: dep.artifactPath,
71
+ artifactTargetId: dep.artifactTargetId,
72
+ coordKey:
73
+ dep.coordKey +
74
+ ':embedded:' +
75
+ item.id +
76
+ (item.resourceOffset !== undefined ? ':' + item.resourceOffset : ''),
77
+ binaryEvidence: proof,
78
+ osPackageOwners: dep.osPackageOwners
79
+ });
80
+ } else {
81
+ dep.version = item.version;
82
+ dep.versions = item.version ? [item.version] : [];
83
+ dep.versionPaths = item.version ? { [item.version]: [dep.artifactPath] } : {};
84
+ dep.binaryEvidence = proof;
85
+ if (provider.osPackageOwners?.length) dep.osPackageOwners = provider.osPackageOwners;
86
+ }
87
+ }
88
+ }
89
+ deps.push(...additions.filter((d) => !linkedFiles.has(JSON.stringify([d.artifactPath, d.name]))));
90
+ }
91
+
92
+ function productCoverage(target, checks, assessedPackages, matches) {
93
+ const affected = new Set(
94
+ matches.filter((m) => m.dep?.artifactTargetId === target.id).map((m) => m.dep.coordKey)
95
+ );
96
+ const affectedPackages = new Set(
97
+ matches
98
+ .filter((m) => m.dep?.artifactTargetId === target.id && m.dep.ecosystem === 'system')
99
+ .map((m) => m.dep.manager + ':' + m.dep.name + '@' + m.dep.version)
100
+ );
101
+ const entries = [],
102
+ links = [];
103
+ const libraryProduct = require('./elf-product').libraryProduct;
104
+ const present = new Set(
105
+ target.deps
106
+ .filter((d) => d.ecosystem === 'binary')
107
+ .flatMap((d) => [d.name, d.binaryMetadata?.soname].filter(Boolean))
108
+ );
109
+ for (const dep of target.deps) {
110
+ for (const name of dep.binaryMetadata?.needed || []) {
111
+ const linked = libraryProduct(name) || binaryProduct(name);
112
+ if (linked)
113
+ links.push({
114
+ id: linked.id,
115
+ product: linked.label,
116
+ requiredBy: dep.artifactPath,
117
+ library: name,
118
+ fileObserved: present.has(name)
119
+ });
120
+ }
121
+ const product = describe(dep);
122
+ if (!product) continue;
123
+ const system = dep.ecosystem === 'system' || !!dep.osPackageOwners?.length;
124
+ const relevant = system ? [] : checks.filter((c) => c.product === product.id && c.version === dep.version);
125
+ const owners = dep.ecosystem === 'system' ? [dep] : dep.osPackageOwners || [];
126
+ const keys = owners.map((o) => o.manager + ':' + o.name + '@' + o.version);
127
+ const version = dep.version || (owners.length === 1 ? owners[0].version : null);
128
+ let advisoryCheck = 'indeterminate',
129
+ reason = relevant.find((c) => c.reason)?.reason;
130
+ if (affected.has(dep.coordKey) || keys.some((k) => affectedPackages.has(k))) advisoryCheck = 'affected';
131
+ else if (system) {
132
+ advisoryCheck =
133
+ keys.length && keys.every((k) => assessedPackages.has(k))
134
+ ? 'distribution-no-match'
135
+ : 'distribution-incomplete';
136
+ } else if (relevant.length && relevant.every((c) => c.execution === 'completed'))
137
+ advisoryCheck = 'no-match';
138
+ else if (relevant.length && relevant.every((c) => c.execution === 'not-applicable'))
139
+ advisoryCheck = 'disabled';
140
+ else if (dep.ecosystem === 'go') advisoryCheck = 'go-module';
141
+ else if (!version) reason = 'version-unknown';
142
+ else if (!relevant.length) reason = 'no-upstream-check';
143
+ entries.push({
144
+ ...product,
145
+ name: dep.name,
146
+ path: dep.artifactPath,
147
+ version,
148
+ versionSource: dep.binaryEvidence?.source || (system ? 'system-package' : null),
149
+ evidencePath: dep.binaryEvidence?.versionPath || dep.artifactPath,
150
+ resourceOffset: dep.binaryEvidence?.resourceOffset,
151
+ advisoryCheck,
152
+ reason
153
+ });
154
+ }
155
+ const recognizedPaths = new Set(entries.filter((e) => e.version).map((e) => e.evidencePath));
156
+ const unidentified = target.deps
157
+ .filter(
158
+ (d) =>
159
+ d.ecosystem === 'binary' &&
160
+ !d.osPackageOwners?.length &&
161
+ !describe(d) &&
162
+ !recognizedPaths.has(d.artifactPath) &&
163
+ !d.binaryMetadata?.go?.modules?.some((m) => m.kind === 'mod' && m.version && m.version !== '(devel)')
164
+ )
165
+ .map((d) => ({ path: d.artifactPath, format: d.binaryMetadata?.format || 'unknown' }));
166
+ const seen = new Set([...entries, ...links].map((e) => e.id));
167
+ return {
168
+ entries,
169
+ links,
170
+ unidentified,
171
+ scope:
172
+ target.kind === 'sbom'
173
+ ? 'publisher-sbom'
174
+ : target.metadata?.componentScope === require('./component-scope').IMAGE_COMPONENT_SCOPE
175
+ ? 'image-files'
176
+ : 'older-inventory',
177
+ unobserved: [...catalog.values()].filter((p) => !seen.has(p.id)).map((p) => p.label)
178
+ };
179
+ }
180
+ module.exports = { describe, applyProductVersions, productCoverage };
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path').posix;
5
+ const { safeFile } = require('../system-inventory/collect');
6
+
7
+ // Read installed build configuration as data, never as a script. Both the
8
+ // expected layout and linker identity must agree with the observed launcher.
9
+ function installedVersion(root, location, metadata, product) {
10
+ const needed = metadata.needed || [];
11
+ if (!product || !location || path.basename(path.dirname(location)) !== 'bin') return null;
12
+ const prefix = path.dirname(path.dirname(location));
13
+ function text(relative) {
14
+ const file = safeFile(root, path.join(prefix, relative));
15
+ if (!file) return '';
16
+ const stat = fs.statSync(file);
17
+ return stat.isFile() && stat.size <= 128 * 1024 ? fs.readFileSync(file, 'utf8') : '';
18
+ }
19
+ if (product.id === 'java' && needed.includes('libjli.so')) {
20
+ const release = text('release');
21
+ const version = /^JAVA_VERSION="(\d[\w.+-]{0,50})"\r?$/m.exec(release)?.[1];
22
+ if (version && /^IMPLEMENTOR="[^"\r\n]+"\r?$/m.test(release))
23
+ return { id: 'java', version, source: 'jdk-release', path: path.join(prefix, 'release') };
24
+ }
25
+ if (product.id === 'tcl') {
26
+ for (const soname of needed) {
27
+ const match = /^libtcl(\d+\.\d+)\.so(?:\.\d+)*$/.exec(soname);
28
+ if (!match) continue;
29
+ const config = path.join('lib', 'tcl' + match[1], 'tclConfig.sh');
30
+ const doc = text(config);
31
+ const minor = /^TCL_VERSION='(\d+\.\d+)'\r?$/m.exec(doc)?.[1];
32
+ const patch = /^TCL_PATCH_LEVEL='(\.\d+)'\r?$/m.exec(doc)?.[1];
33
+ if (match[1] === minor && patch && /^TCL_LIB_FILE='([^'\r\n]+)'\r?$/m.exec(doc)?.[1] === soname)
34
+ return {
35
+ id: 'tcl',
36
+ version: minor + patch,
37
+ source: 'tcl-build-config',
38
+ path: path.join(prefix, config)
39
+ };
40
+ }
41
+ }
42
+ return null;
43
+ }
44
+ module.exports = { installedVersion };
@@ -2,7 +2,7 @@
2
2
 
3
3
  // A saved inventory is validated before this transformation. Filtering an old
4
4
  // snapshot cannot reconstruct descriptors that its collectors never observed.
5
- const { IMAGE_COMPONENT_SCOPE, isNpmPackageDescriptor, imageComponentRole } = require('./component-scope');
5
+ const { IMAGE_COMPONENT_SCOPE, isNpmPackageDescriptor, imageComponentRole, imageComponentSource } = require('./component-scope');
6
6
  const SCOPE_REASON = 'image-inventory-scope-outdated';
7
7
  const SCOPE_MESSAGE = 'The saved image inventory predates the current component scope or contains package metadata fragments. Reacquire the image to establish its current inventory.';
8
8
 
@@ -26,6 +26,7 @@ function applyComponentScope(target, { checkPolicy = true } = {}) {
26
26
  result.deps = (result.deps || []).filter(dep => {
27
27
  if (isNpmFragment(dep)) { filtered = true; return false; }
28
28
  dep.imageRole = imageComponentRole(dep);
29
+ dep.imageSource = imageComponentSource(dep);
29
30
  dep.scope = dep.imageRole === 'transitive' ? 'transitive' : 'runtime';
30
31
  return true;
31
32
  });
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ const { catalog } = require('./product-catalog');
4
+ const normalize = (value) => (typeof value === 'string' ? value.trim().toLowerCase() : '');
5
+ const listed = (values, value) => !!value && values?.some((v) => normalize(v) === normalize(value));
6
+
7
+ // Read one PE's own StringFileInfo tables. Exact product and publisher/original
8
+ // filename must agree within a table. Never borrow the enclosing EXE's version.
9
+ function versionResource(tables) {
10
+ const identities = new Set(),
11
+ versions = new Set();
12
+ for (const table of tables || []) {
13
+ const product = [...catalog.values()].find(
14
+ (p) =>
15
+ listed(p.peVersionInfo?.names, table.ProductName) &&
16
+ (listed(p.peVersionInfo?.originals, table.OriginalFilename) ||
17
+ listed(p.peVersionInfo?.vendors, table.CompanyName))
18
+ );
19
+ if (!product) return null;
20
+ identities.add(product.id);
21
+ const version = String(table.ProductVersion || '').trim();
22
+ versions.add(/^\d+(?:\.\d+){1,3}$/.test(version) && version.length <= 40 ? version : null);
23
+ }
24
+ if (identities.size !== 1) return null;
25
+ const [id] = identities;
26
+ return { id, version: versions.size === 1 ? [...versions][0] : null, source: 'pe-version-info' };
27
+ }
28
+ module.exports = { versionResource };
@@ -0,0 +1,207 @@
1
+ 'use strict';
2
+
3
+ const { imageProduct } = require('./product-catalog');
4
+ const { createCacheRepository } = require('../cache-repository');
5
+ const { extractFromNvdRecord } = require('../nvd');
6
+ const { getResource } = require('../providers');
7
+ const { validateResourceJson, DEFAULT_MAX_BODY_BYTES } = require('../resource-cache/engine');
8
+ const { fresh } = require('../cache-policy');
9
+
10
+ const VERSION = /^\d{1,8}(?:\.\d{1,8}){1,3}$/;
11
+ const bounds = ['versionStartIncluding', 'versionStartExcluding', 'versionEndIncluding', 'versionEndExcluding'];
12
+ function compare(a, b) {
13
+ const x = a.split('.').map(Number),
14
+ y = b.split('.').map(Number);
15
+ for (let i = 0; i < Math.max(x.length, y.length); i++) {
16
+ const d = (x[i] || 0) - (y[i] || 0);
17
+ if (d) return Math.sign(d);
18
+ }
19
+ return 0;
20
+ }
21
+
22
+ // Only an independently sufficient configuration can confirm the finding. An
23
+ // AND with hardware/OS constraints or an unmodelled version remains unknown.
24
+ function evaluateConfiguration(node, product, version) {
25
+ if (!node || node.negate || !['OR', 'AND', undefined].includes(node.operator)) return null;
26
+ const values = [];
27
+ for (const leaf of node.cpeMatch || []) {
28
+ const fields = String(leaf.criteria).split(':');
29
+ if (
30
+ fields.length !== 13 ||
31
+ fields.slice(0, 5).join(':') !== 'cpe:2.3:a:' + product ||
32
+ leaf.vulnerable !== true
33
+ ) {
34
+ values.push(null);
35
+ continue;
36
+ }
37
+ const pin = fields[5];
38
+ if (
39
+ !fields.slice(6).every((value) => value === '*' || value === '-') ||
40
+ (pin !== '*' && !VERSION.test(pin)) ||
41
+ bounds.some((k) => leaf[k] != null && !VERSION.test(leaf[k]))
42
+ ) {
43
+ values.push(null);
44
+ continue;
45
+ }
46
+ values.push(
47
+ (pin === '*' || compare(version, pin) === 0) &&
48
+ (!leaf.versionStartIncluding || compare(version, leaf.versionStartIncluding) >= 0) &&
49
+ (!leaf.versionStartExcluding || compare(version, leaf.versionStartExcluding) > 0) &&
50
+ (!leaf.versionEndIncluding || compare(version, leaf.versionEndIncluding) <= 0) &&
51
+ (!leaf.versionEndExcluding || compare(version, leaf.versionEndExcluding) < 0)
52
+ );
53
+ }
54
+ for (const child of [...(node.nodes || []), ...(node.children || [])])
55
+ values.push(evaluateConfiguration(child, product, version));
56
+ if (!values.length) return null;
57
+ if (node.operator === 'AND') return values.includes(false) ? false : values.includes(null) ? null : true;
58
+ return values.includes(true) ? true : values.includes(null) ? null : false;
59
+ }
60
+
61
+ async function assessProductAdvisories(target, options) {
62
+ const matches = [],
63
+ coverage = [],
64
+ groups = new Map();
65
+ for (const dep of target.deps) {
66
+ const product = imageProduct(dep);
67
+ if (
68
+ !product ||
69
+ !dep.binaryEvidence?.product ||
70
+ dep.binaryEvidence.product !== product.id ||
71
+ dep.osPackageOwners?.length
72
+ )
73
+ continue;
74
+ // Slimmed distro images may discard dpkg .list files. When the matching
75
+ // system package exists, never apply upstream rules to a system-prefix binary.
76
+ if (
77
+ /^(?:usr\/)?(?:s?bin|lib(?:32|64)?)\//.test(dep.artifactPath || '') &&
78
+ target.packages.some((pkg) => product.pkg.test(pkg.name))
79
+ )
80
+ continue;
81
+ if (!product.cpe || !VERSION.test(dep.version)) {
82
+ coverage.push({
83
+ collector: 'image-product-applicability',
84
+ product: product.id,
85
+ version: dep.version,
86
+ execution: 'partial',
87
+ result: 'indeterminate',
88
+ reason: dep.version
89
+ ? 'No supported upstream CPE/version comparison.'
90
+ : 'No exact runtime version was identified.'
91
+ });
92
+ continue;
93
+ }
94
+ for (const cpe of [product.cpe, ...(product.cpeAliases || [])]) {
95
+ const key = JSON.stringify([product.id, dep.version, cpe]);
96
+ const items = groups.get(key) || [];
97
+ items.push(dep);
98
+ groups.set(key, items);
99
+ }
100
+ }
101
+ for (const [key, items] of groups) {
102
+ const [id, version, cpe] = JSON.parse(key);
103
+ const check = {
104
+ collector: 'nvd-image-product',
105
+ product: id,
106
+ version,
107
+ cpe,
108
+ scope: 'upstream-cpe-version',
109
+ count: 0
110
+ };
111
+ coverage.push(check);
112
+ if (options.nvd === false || options.sourceProfile === 'eu') {
113
+ Object.assign(check, {
114
+ execution: 'not-applicable',
115
+ result: 'not-consulted',
116
+ expected: false,
117
+ reason: 'NVD excluded by configuration.'
118
+ });
119
+ continue;
120
+ }
121
+ try {
122
+ const repo = createCacheRepository(options.cacheDir);
123
+ const ns = 'image-product-nvd/1',
124
+ cacheKey = JSON.stringify([cpe, version]);
125
+ let saved = repo.get(ns, cacheKey),
126
+ error;
127
+ if (!options.offline && (!saved || saved.stale || !fresh(saved.fetchedAt) || options.forceUpdate)) {
128
+ try {
129
+ const params = { product: id, version, cpe };
130
+ const response = await getResource('nvd', 'image-product', params, {
131
+ fetcher: options.fetcher,
132
+ signal: AbortSignal.timeout(30000),
133
+ forceRefresh: options.forceUpdate
134
+ });
135
+ if (!response.ok) throw Error('NVD HTTP ' + response.status);
136
+ const chunks = [];
137
+ let bytes = 0;
138
+ for await (const part of response.body) {
139
+ bytes += part.length;
140
+ if (bytes > DEFAULT_MAX_BODY_BYTES) throw Error('NVD product response exceeds the metadata budget');
141
+ chunks.push(Buffer.from(part));
142
+ }
143
+ const body = JSON.parse(Buffer.concat(chunks).toString('utf8'));
144
+ validateResourceJson({ provider: 'nvd', type: 'image-product', params }, body);
145
+ if (body.totalResults !== body.vulnerabilities.length || body.startIndex !== 0)
146
+ throw Error('Incomplete NVD product response');
147
+ const records = [],
148
+ unknown = [];
149
+ for (const { cve } of body.vulnerabilities) {
150
+ if (cve.vulnStatus === 'Rejected') continue;
151
+ const verdict = evaluateConfiguration({ nodes: cve.configurations }, cpe, version);
152
+ if (verdict === true) records.push(extractFromNvdRecord(cve));
153
+ if (verdict === null) unknown.push(cve.id);
154
+ }
155
+ const stamp = response.headers.get('x-fad-proxy-fetched-at');
156
+ const fetchedAt = stamp ? Date.parse(stamp) : Date.now();
157
+ if (
158
+ (require('../providers').hasProxyRoute() && !stamp) ||
159
+ !Number.isFinite(fetchedAt) ||
160
+ fetchedAt <= 0 ||
161
+ fetchedAt > Date.now() + 300000
162
+ )
163
+ throw Error('Invalid NVD observation timestamp');
164
+ const stale = response.headers.get('x-fad-proxy') === 'stale';
165
+ repo.put(ns, cacheKey, { records, unknown }, { fetchedAt, stale });
166
+ saved = { value: { records, unknown }, fetchedAt, stale };
167
+ } catch (e) {
168
+ error = e.message;
169
+ }
170
+ }
171
+ if (!saved) throw Error(error || 'No cached NVD consultation for this product/version.');
172
+ const { records, unknown } = saved.value;
173
+ const stale = saved.stale || (!fresh(saved.fetchedAt) && !options.forceUpdate);
174
+ for (const dep of items)
175
+ for (const record of records)
176
+ matches.push({
177
+ dep,
178
+ source: 'nvd',
179
+ confidence: 'probable',
180
+ cve: {
181
+ ...record,
182
+ fixVersion: null,
183
+ identityEvidence: dep.binaryEvidence,
184
+ advisorySource: 'https://nvd.nist.gov/vuln/detail/' + record.id
185
+ }
186
+ });
187
+ Object.assign(check, {
188
+ execution: error || stale || unknown.length ? 'partial' : 'completed',
189
+ result: records.length ? 'affected' : error || stale || unknown.length ? 'indeterminate' : 'no-match',
190
+ fetchedAt: saved.fetchedAt,
191
+ count: records.length,
192
+ unknown: unknown.length,
193
+ reason:
194
+ error ||
195
+ (stale
196
+ ? 'Saved NVD consultation is stale.'
197
+ : unknown.length
198
+ ? 'Some CPE configuration conditions could not be established.'
199
+ : undefined)
200
+ });
201
+ } catch (e) {
202
+ Object.assign(check, { execution: 'not-run', result: 'indeterminate', reason: e.message });
203
+ }
204
+ }
205
+ return { matches, coverage };
206
+ }
207
+ module.exports = { assessProductAdvisories, evaluateConfiguration, VERSION };
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ // Program names identify candidates for presentation. Only product-specific version
4
+ // evidence can authorize upstream matching. Package aliases refer to installed
5
+ // binary packages, never arbitrary npm, PyPI or Composer project names.
6
+ const fingerprints = require('../../data/fingerprints');
7
+ const catalog = new Map();
8
+ for (const rule of fingerprints) {
9
+ if (
10
+ rule.schemaVersion !== 1 ||
11
+ !/^[a-z][a-z0-9-]*$/.test(rule.id) ||
12
+ catalog.has(rule.id) ||
13
+ !['interpreter', 'service'].includes(rule.category)
14
+ )
15
+ throw Error('Invalid image fingerprint ' + rule.id);
16
+ catalog.set(rule.id, {
17
+ ...rule,
18
+ executable: new RegExp(rule.executable),
19
+ pkg: new RegExp(rule.osPackage),
20
+ library: rule.elfLibrary ? new RegExp(rule.elfLibrary) : null,
21
+ banner: rule.elfBanner ? new RegExp(rule.elfBanner, 'g') : null
22
+ });
23
+ }
24
+
25
+ function binaryProduct(name) {
26
+ if (typeof name !== 'string') return null;
27
+ if (/\.exe$/i.test(name)) name = name.slice(0, -4).toLowerCase();
28
+ for (const product of catalog.values())
29
+ if (product.executable.test(name) && name !== 'master') return product;
30
+ return null;
31
+ }
32
+
33
+ const goServices = new Map(
34
+ [...catalog.values()].filter((p) => p.goMainModule).map((p) => [p.goMainModule, p.id])
35
+ );
36
+ function imageProduct(dep) {
37
+ if (dep.ecosystem === 'image-product') return catalog.get(dep.name);
38
+ if (dep.ecosystem === 'system') {
39
+ for (const product of catalog.values()) if (product.pkg.test(dep.name)) return product;
40
+ }
41
+ if (dep.ecosystem === 'binary') {
42
+ const proof = catalog.get(dep.binaryEvidence?.product);
43
+ if (proof) return proof;
44
+ for (const owner of dep.osPackageOwners || []) {
45
+ for (const product of catalog.values())
46
+ if (
47
+ product.pkg.test(owner.name) &&
48
+ (product.executable.test(dep.name) || ['smtpd', 'master'].includes(dep.name))
49
+ )
50
+ return product;
51
+ }
52
+ return binaryProduct(dep.name);
53
+ }
54
+ if (
55
+ dep.ecosystem === 'go' &&
56
+ (dep.binaryEvidence?.original?.kind === 'mod' || dep.binaryEvidence?.source === 'go-vcs-and-module-proxy')
57
+ ) {
58
+ return catalog.get(goServices.get(String(dep.name).replace(/\/v\d+$/, '')));
59
+ }
60
+ return null;
61
+ }
62
+ module.exports = { catalog, binaryProduct, imageProduct };
@@ -5,6 +5,7 @@
5
5
  const componentIdentity = dep => JSON.stringify([
6
6
  dep.packageType || dep.ecosystem || '', dep.namespace || '',
7
7
  dep.name || dep.artifactId || dep.coord || '', dep.version || '', dep.architecture || '',
8
+ ...(dep.binaryEvidence?.product ? [dep.artifactPath || dep.binaryEvidence.binaryPath,dep.binaryEvidence.resourceOffset ?? null] : []),
8
9
  ]);
9
10
  const needsAdvisory = dep => dep.ecosystem === 'system' || dep.ecosystem === 'binary' ||
10
11
  dep.provenance === 'binary' || dep.provenance === 'embedded' || dep.osPackageOwners?.length > 0;
@@ -13,7 +14,12 @@ function reportedComponents(artifact, matches = []) {
13
14
  (match.dep?.artifactTargetId || match.artifactTargetId) === artifact.id &&
14
15
  !match.cpeFiltered && (match.cve?.id || match.advisoryId)
15
16
  ).map(match => componentIdentity(match.dep || {})));
16
- return (artifact.components || []).filter(dep => (['direct','transitive'].includes(dep.imageRole) && !['system','binary'].includes(dep.ecosystem)) || !needsAdvisory(dep) || affected.has(componentIdentity(dep)));
17
+ return (artifact.components || []).filter(dep => {
18
+ if(require('./product-catalog').imageProduct(dep))return true;
19
+ if(affected.has(componentIdentity(dep)))return true;
20
+ if(dep.imageRole==='transitive')return false;
21
+ return !needsAdvisory(dep);
22
+ });
17
23
  }
18
24
  function reportArtifacts(artifacts, matches) {
19
25
  return artifacts.map(artifact => {