Skip to content

Commit 247b542

Browse files
feat: adapt recommended test 6.2.25
1 parent e33b1fe commit 247b542

File tree

1 file changed

+22
-33
lines changed

1 file changed

+22
-33
lines changed

csaf_2_1/recommendedTests/recommendedTest_6_2_25.js

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const inputSchema = /** @type {const} */ ({
1515
vulnerabilities: {
1616
elements: {
1717
additionalProperties: true,
18-
properties: {
18+
optionalProperties: {
1919
cwes: {
2020
elements: {
2121
additionalProperties: true,
@@ -57,38 +57,27 @@ export async function recommendedTest_6_2_25(doc) {
5757

5858
for (let i = 0; i < doc.vulnerabilities.length; ++i) {
5959
const vulnerability = doc.vulnerabilities[i]
60-
for (let j = 0; j < vulnerability.cwes.length; ++j) {
61-
const cwe = vulnerability.cwes.at(j)
62-
if (validateCWE(cwe)) {
63-
const cwec = cwecMap.get(cwe.version)
64-
if (!cwec) {
65-
context.warnings.push({
66-
instancePath: `/vulnerabilities/${i}/cwes/${j}/version`,
67-
message: 'no such cwe version is recognized',
68-
})
69-
continue
70-
}
71-
const entry = (await cwec()).default.weaknesses.find(
72-
(w) => w.id === cwe.id
73-
)
74-
if (!entry) {
75-
context.warnings.push({
76-
instancePath: `/vulnerabilities/${i}/cwes/${j}/id`,
77-
message: `no weakness with this id is recognized in CWE ${cwe.version}`,
78-
})
79-
continue
80-
}
81-
//NOTE: the usage property is not available in cwe version 4.11 and older
82-
if (
83-
entry.usage !== 'Allowed' &&
84-
entry.usage !== 'Allowed-with-Review'
85-
) {
86-
context.warnings.push({
87-
instancePath: `/vulnerabilities/${i}/cwes/${j}/id`,
88-
message:
89-
'the usage of the weakness with the given id is not allowed',
90-
})
91-
continue
60+
if (vulnerability.cwes) {
61+
for (let j = 0; j < vulnerability.cwes.length; ++j) {
62+
const cwe = vulnerability.cwes.at(j)
63+
if (validateCWE(cwe)) {
64+
const cwec = cwecMap.get(cwe.version)
65+
if (cwec) {
66+
const entry = (await cwec()).default.weaknesses.find(
67+
(w) => w.id === cwe.id
68+
)
69+
//NOTE: the usage property is not available in cwe version 4.11 and older
70+
if (
71+
entry?.usage !== 'Allowed' &&
72+
entry?.usage !== 'Allowed-with-Review'
73+
) {
74+
context.warnings.push({
75+
instancePath: `/vulnerabilities/${i}/cwes/${j}/id`,
76+
message:
77+
'the usage of the weakness with the given id is not allowed',
78+
})
79+
}
80+
}
9281
}
9382
}
9483
}

0 commit comments

Comments
 (0)