|
| 1 | +import Ajv from 'ajv/dist/jtd.js' |
| 2 | + |
| 3 | +const ajv = new Ajv() |
| 4 | + |
| 5 | +const inputSchema = /** @type {const} */ ({ |
| 6 | + additionalProperties: true, |
| 7 | + properties: { |
| 8 | + vulnerabilities: { |
| 9 | + elements: { |
| 10 | + additionalProperties: true, |
| 11 | + properties: { |
| 12 | + metrics: { |
| 13 | + elements: { |
| 14 | + additionalProperties: true, |
| 15 | + properties: { |
| 16 | + content: { |
| 17 | + additionalProperties: true, |
| 18 | + properties: { |
| 19 | + ssvc_v1: { |
| 20 | + additionalProperties: true, |
| 21 | + properties: { |
| 22 | + role: { |
| 23 | + type: 'string', |
| 24 | + }, |
| 25 | + }, |
| 26 | + }, |
| 27 | + }, |
| 28 | + }, |
| 29 | + }, |
| 30 | + }, |
| 31 | + }, |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + }, |
| 36 | +}) |
| 37 | + |
| 38 | +const validate = ajv.compile(inputSchema) |
| 39 | + |
| 40 | +/** |
| 41 | + * This implements the optional test 6.2.37 of the CSAF 2.1 standard. |
| 42 | + * |
| 43 | + * @param {any} doc |
| 44 | + */ |
| 45 | +export function optionalTest_6_2_37(doc) { |
| 46 | + /** @type {Array<{ message: string; instancePath: string }>} */ |
| 47 | + const warnings = [] |
| 48 | + const context = { warnings } |
| 49 | + |
| 50 | + if (!validate(doc)) { |
| 51 | + return context |
| 52 | + } |
| 53 | + |
| 54 | + /* |
| 55 | + * Please note that this list can change |
| 56 | + * */ |
| 57 | + const registeredSsvcRoles = ['Supplier', 'Deployer', 'Coordinator'] |
| 58 | + |
| 59 | + doc.vulnerabilities?.forEach((vulnerability, vulnerabilityIndex) => { |
| 60 | + vulnerability.metrics.forEach((metric, metricIndex) => { |
| 61 | + const role = metric.content.ssvc_v1.role |
| 62 | + if (!registeredSsvcRoles.includes(role)) { |
| 63 | + context.warnings.push({ |
| 64 | + message: `The used role "${role}" is not a registered role`, |
| 65 | + instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/ssvc_v1/role`, |
| 66 | + }) |
| 67 | + } |
| 68 | + }) |
| 69 | + }) |
| 70 | + |
| 71 | + return context |
| 72 | +} |
0 commit comments