-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add mandatory test 6.1.46 for csaf 2.1 - SSVC #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
christopher-exx
wants to merge
7
commits into
main
Choose a base branch
from
feat/197-csaf-2.1-mandatory-test-6.1.46
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6211607
feat: add mandatory test 6.1.46
christopher-exx 038e78d
docs: update readme
christopher-exx aa1340c
feat: change ssvc_v1 property to optionalProperty in inputSchema
christopher-exx e550ba1
feat: add test for input schema
christopher-exx 5b6d300
feat: change inputSchema test from valid to failing example
christopher-exx c66091b
fix: fix doc in inputSchema test
christopher-exx 1306b70
feat: adapt code to match ssvc v2
christopher-exx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import Ajv from 'ajv/dist/jtd.js' | ||
| import csafAjv from '../csafAjv.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: { | ||
| vulnerabilities: { | ||
| elements: { | ||
| additionalProperties: true, | ||
| optionalProperties: { | ||
| metrics: { | ||
| elements: { | ||
| additionalProperties: true, | ||
| optionalProperties: { | ||
| content: { | ||
| additionalProperties: true, | ||
| optionalProperties: { | ||
| ssvc_v2: { | ||
| additionalProperties: true, | ||
| properties: {}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| const validateInput = ajv.compile(inputSchema) | ||
|
|
||
| const validate_ssvc_v2 = csafAjv.compile({ | ||
| $ref: 'https://certcc.github.io/SSVC/data/schema/v2/Decision_Point_Value_Selection-2-0-0.schema.json', | ||
| }) | ||
|
|
||
| /** | ||
| * This implements the mandatory test 6.1.46 of the CSAF 2.1 standard. | ||
| * | ||
| * @param {unknown} doc | ||
| */ | ||
| export function mandatoryTest_6_1_46(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 (!validateInput(doc)) { | ||
| return ctx | ||
| } | ||
|
|
||
| doc.vulnerabilities?.forEach((vulnerability, vulnerabilityIndex) => { | ||
| vulnerability.metrics?.forEach((metric, metricIndex) => { | ||
| if (metric.content?.ssvc_v2) { | ||
| const valid = validate_ssvc_v2(metric.content.ssvc_v2) | ||
| if (!valid) { | ||
| ctx.isValid = false | ||
| for (const err of validate_ssvc_v2.errors ?? []) { | ||
| ctx.errors.push({ | ||
| instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/ssvc_v2${err.instancePath}`, | ||
| message: err.message ?? '', | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| return ctx | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import assert from 'node:assert/strict' | ||
| import { mandatoryTest_6_1_46 } from '../../csaf_2_1/mandatoryTests/mandatoryTest_6_1_46.js' | ||
| import { expect } from 'chai' | ||
|
|
||
| const failingInputSchemaTestWithEmptyVulnerability6_1_46 = { | ||
| vulnerabilities: [ | ||
| {}, // even this vulnerability is empty, the test should run | ||
| { | ||
| cve: 'CVE-1900-0001', | ||
| metrics: [ | ||
| { | ||
| content: { | ||
| ssvc_v2: { | ||
| schemaVersion: '2.0.0', | ||
| timestamp: '2024-01-24T10:00:00.000Z', | ||
| }, | ||
| }, | ||
| products: ['CSAFPID-9080700'], | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| } | ||
|
|
||
| describe('mandatoryTest_6_1_46', function () { | ||
| it('only runs on relevant documents', function () { | ||
| assert.equal(mandatoryTest_6_1_46({ document: 'mydoc' }).isValid, true) | ||
| }) | ||
| it('test input schema with empty json object in vulnerabilities', async function () { | ||
| const result = mandatoryTest_6_1_46( | ||
| failingInputSchemaTestWithEmptyVulnerability6_1_46 | ||
| ) | ||
| expect(result.errors.length).to.eq(1) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ const excluded = [ | |
| '6.1.37', | ||
| '6.1.42', | ||
| '6.1.44', | ||
| '6.1.46', | ||
| '6.1.47', | ||
| '6.1.48', | ||
| '6.1.49', | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm currently not confident that this reflects the latest version upstream. I need to double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right @tschmidtb51, as far as I can see there is a newer version upstream.