Skip to content

Commit b23229f

Browse files
Merge pull request #274 from secvisogram/feat/199-Informative-Tests_CSAF2_1_6.3.2
Feat/199 informative tests csaf2.1 6.3.2
2 parents 4a1299b + 49575ad commit b23229f

File tree

4 files changed

+103
-2
lines changed

4 files changed

+103
-2
lines changed

csaf_2_1/informativeTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export {
2-
informativeTest_6_3_2,
32
informativeTest_6_3_3,
43
informativeTest_6_3_5,
54
informativeTest_6_3_6,
@@ -11,3 +10,4 @@ export {
1110
} from '../informativeTests.js'
1211
export { informativeTest_6_3_1 } from './informativeTests/informativeTest_6_3_1.js'
1312
export { informativeTest_6_3_4 } from './informativeTests/informativeTest_6_3_4.js'
13+
export { informativeTest_6_3_2 } from './informativeTests/informativeTest_6_3_2.js'
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
optionalProperties: {
12+
metrics: {
13+
elements: {
14+
additionalProperties: true,
15+
optionalProperties: {
16+
content: {
17+
additionalProperties: true,
18+
optionalProperties: {
19+
cvss_v3: {
20+
additionalProperties: true,
21+
optionalProperties: {
22+
version: { type: 'string' },
23+
vectorString: { type: 'string' },
24+
},
25+
},
26+
},
27+
},
28+
},
29+
},
30+
},
31+
},
32+
},
33+
},
34+
},
35+
})
36+
37+
const validateInput = ajv.compile(inputSchema)
38+
39+
/**
40+
* For each item in the list of metrics which contains the cvss_v3 object under
41+
* content it MUST be tested that CVSS v3.0 is not used.
42+
* @param {unknown} doc
43+
* @returns
44+
*/
45+
export function informativeTest_6_3_2(doc) {
46+
const ctx = {
47+
infos: /** @type {Array<{ message: string; instancePath: string }>} */ ([]),
48+
}
49+
50+
if (!validateInput(doc)) {
51+
return ctx
52+
}
53+
54+
doc.vulnerabilities.forEach((vulnerability, vulnerabilityIndex) => {
55+
const metrics = vulnerability.metrics
56+
metrics?.forEach((metric, metricIndex) => {
57+
if (metric.content?.cvss_v3) {
58+
if (
59+
metric.content.cvss_v3.version === '3.0' ||
60+
metric.content.cvss_v3.vectorString?.startsWith('CVSS:3.0')
61+
) {
62+
ctx.infos.push({
63+
instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/cvss_v3/version`,
64+
message: 'It is recommended to upgrade to CVSS v3.1.',
65+
})
66+
}
67+
}
68+
})
69+
})
70+
71+
return ctx
72+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import assert from 'node:assert/strict'
2+
import { informativeTest_6_3_2 } from '../../csaf_2_1/informativeTests/informativeTest_6_3_2.js'
3+
4+
describe('informativeTest_6_3_2', function () {
5+
it('only runs on relevant documents', function () {
6+
assert.equal(informativeTest_6_3_2({ document: 'mydoc' }).infos.length, 0)
7+
})
8+
it('test input schema with not considered json object in vulnerabilities', function () {
9+
assert.equal(
10+
informativeTest_6_3_2({
11+
document: {},
12+
vulnerabilities: [
13+
{},
14+
{
15+
metrics: [
16+
{
17+
content: {
18+
cvss_v3: {
19+
version: '3.0',
20+
},
21+
},
22+
},
23+
],
24+
},
25+
],
26+
}).infos.length,
27+
1
28+
)
29+
})
30+
})

tests/csaf_2_1/oasis.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ const excluded = [
7171
'6.2.44',
7272
'6.2.45',
7373
'6.2.46',
74-
'6.3.2',
7574
'6.3.14',
7675
'6.3.15',
7776
'6.3.12',

0 commit comments

Comments
 (0)