Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ The following tests are not yet implemented and therefore missing:
- Mandatory Test 6.1.49
- Mandatory Test 6.1.50
- Mandatory Test 6.1.51
- Mandatory Test 6.1.53
- Mandatory Test 6.1.54
- Mandatory Test 6.1.55

Expand Down Expand Up @@ -435,6 +434,7 @@ export const mandatoryTest_6_1_41: DocumentTest
export const mandatoryTest_6_1_43: DocumentTest
export const mandatoryTest_6_1_45: DocumentTest
export const mandatoryTest_6_1_52: DocumentTest
export const mandatoryTest_6_1_53: DocumentTest
```

[(back to top)](#bsi-csaf-validator-lib)
Expand Down
1 change: 1 addition & 0 deletions csaf_2_1/mandatoryTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ export { mandatoryTest_6_1_41 } from './mandatoryTests/mandatoryTest_6_1_41.js'
export { mandatoryTest_6_1_43 } from './mandatoryTests/mandatoryTest_6_1_43.js'
export { mandatoryTest_6_1_45 } from './mandatoryTests/mandatoryTest_6_1_45.js'
export { mandatoryTest_6_1_52 } from './mandatoryTests/mandatoryTest_6_1_52.js'
export { mandatoryTest_6_1_53 } from './mandatoryTests/mandatoryTest_6_1_53.js'
96 changes: 96 additions & 0 deletions csaf_2_1/mandatoryTests/mandatoryTest_6_1_53.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import Ajv from 'ajv/dist/jtd.js'
import { compareZonedDateTimes } from '../dateHelper.js'

const ajv = new Ajv()

/*
This is the jtd schema that needs to match the input document so that the
test is activated. If this schema doesn't match it normally means that the input
document does not validate against the csaf json schema or optional fields that
the test checks are not present.
*/
const inputSchema = /** @type {const} */ ({
additionalProperties: true,
properties: {
document: {
additionalProperties: true,
properties: {
tracking: {
additionalProperties: true,
properties: {
revision_history: {
elements: {
additionalProperties: true,
optionalProperties: {
date: { type: 'string' },
},
},
},
},
},
},
},
Comment on lines +15 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is not relevant in the test.

vulnerabilities: {
elements: {
additionalProperties: true,
optionalProperties: {
first_known_exploitation_dates: {
elements: {
additionalProperties: true,
optionalProperties: {
date: { type: 'string' },
exploitation_date: { type: 'string' },
},
},
},
},
},
},
},
})

const validate = ajv.compile(inputSchema)

/**
* This implements the mandatory test 6.1.53 of the CSAF 2.1 standard.
*
* @param {any} doc
*/
export function mandatoryTest_6_1_53(doc) {
/*
The `ctx` variable holds the state that is accumulated during the test ran and is
finally returned by the function.
*/
const ctx = {
errors:
/** @type {Array<{ instancePath: string; message: string }>} */ ([]),
isValid: true,
}

if (!validate(doc)) {
return ctx
}

doc.vulnerabilities?.forEach((vulnerability, vulnerabilityIndex) => {
const exploitDate = vulnerability.first_known_exploitation_dates || []
exploitDate.forEach((exploit, exploitIdx) => {
const date = exploit.date
const exploitationDate = exploit.exploitation_date
Comment on lines +77 to +78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda dislike the variable being named exploit 🫣


if (
compareZonedDateTimes(
/** @type {string} */ (date),
/** @type {string} */ (exploitationDate)
) < 0
) {
ctx.isValid = false
ctx.errors.push({
instancePath: `/vulnerabilities/${vulnerabilityIndex}/first_known_exploitation_dates/${exploitIdx}`,
message: 'the "exploitation_date" is newer than the "date"',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unspecific what "the date" means.

Suggested change
message: 'the "exploitation_date" is newer than the "date"',
message: 'the "exploitation_date" is newer than the "date" which states when that information was last updated',

})
}
})
})

return ctx
}
56 changes: 56 additions & 0 deletions tests/csaf_2_1/mandatoryTest_6_1_53.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import assert from 'node:assert/strict'
import { mandatoryTest_6_1_53 } from '../../csaf_2_1/mandatoryTests/mandatoryTest_6_1_53.js'

describe('mandatoryTest_6_1_53', function () {
it('only runs on relevant documents', function () {
assert.equal(mandatoryTest_6_1_53({ document: 'mydoc' }).isValid, true)
})

it('skips empty vulnerability', function () {
assert.equal(
mandatoryTest_6_1_53({
document: {
tracking: {
revision_history: [],
},
Comment on lines +12 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

},
vulnerabilities: [
{}, // should be ignored
{
first_known_exploitation_dates: [
{
date: '2024-01-24T12:34:56.789Z',
exploitation_date: '2024-01-24T13:00:00.000Z',
},
],
},
],
}).isValid,
false
)
})

it('skips empty first_known_exploitation_date', function () {
assert.equal(
mandatoryTest_6_1_53({
document: {
tracking: {
revision_history: [],
},
},
Comment on lines +36 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

vulnerabilities: [
{
first_known_exploitation_dates: [
{}, // should be ignored
{
date: '2024-01-24T12:34:56.789Z',
exploitation_date: '2024-01-24T13:00:00.000Z',
},
],
},
],
}).isValid,
false
)
})
})
1 change: 0 additions & 1 deletion tests/csaf_2_1/oasis.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const excluded = [
'6.1.49',
'6.1.50',
'6.1.51',
'6.1.53',
'6.1.54',
'6.1.55',
'6.1.56',
Expand Down