-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrecommendedTest_6_2_35.js
More file actions
100 lines (92 loc) · 2.75 KB
/
recommendedTest_6_2_35.js
File metadata and controls
100 lines (92 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import Ajv from 'ajv/dist/jtd.js'
const ajv = new Ajv()
const inputSchema = /** @type {const} */ ({
additionalProperties: true,
properties: {
document: {
additionalProperties: true,
properties: {
distribution: {
additionalProperties: true,
properties: {
tlp: {
additionalProperties: true,
properties: {
label: { type: 'string' },
},
},
},
},
},
},
vulnerabilities: {
elements: {
additionalProperties: true,
optionalProperties: {
metrics: {
elements: {
additionalProperties: true,
optionalProperties: {
content: {
additionalProperties: true,
optionalProperties: {
ssvc_v1: {
additionalProperties: true,
optionalProperties: {
selections: {
elements: {
additionalProperties: true,
optionalProperties: {
namespace: {
type: 'string',
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
})
const validate = ajv.compile(inputSchema)
/**
* This implements the recommended test 6.2.35 of the CSAF 2.1 standard.
*
* @param {any} doc
*/
export function recommendedTest_6_2_35(doc) {
/** @type {Array<{ message: string; instancePath: string }>} */
const warnings = []
const context = { warnings }
if (!validate(doc)) {
return context
}
/*
* According to https://certcc.github.io/SSVC/data/schema/v1/Decision_Point-1-0-1.schema.json#/$defs/decision_point/properties/namespace
* a private namespace starts with "x_"
* */
if (doc.document.distribution.tlp.label !== 'CLEAR') {
return context
}
doc.vulnerabilities?.forEach((vulnerability, vulnerabilityIndex) => {
vulnerability.metrics?.forEach((metric, metricIndex) => {
const selections = metric.content?.ssvc_v1?.selections || []
selections.forEach((selection, selectionIndex) => {
if (selection.namespace?.startsWith('x_')) {
context.warnings.push({
message: `The namespace "${selection.namespace}" is a private namespace`,
instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/ssvc_v1/selections/${selectionIndex}/namespace`,
})
}
})
})
})
return context
}