-
Notifications
You must be signed in to change notification settings - Fork 9
Feat/199 informative tests csaf2.1 6.3.13 - SSVC #279
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
Draft
rainer-exxcellent
wants to merge
8
commits into
main
Choose a base branch
from
feat/199-Informative-Tests_CSAF2_1_6.3.13
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.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9a0b2a4
feat: update csaf and exclude new tests
domachine 43e6aee
feat(CSAF2.1): #199 test 6.3.13 for CSAF 2.1
rainer-exxcellent 52db94f
feat(CSAF2.1): #199 test 6.3.13 for CSAF 2.1 - change optionalPropert…
rainer-exxcellent 63991aa
feat(CSAF2.1): #199 test 6.3.13 for CSAF 2.1 - move test in README to…
rainer-exxcellent 53413d9
feat(CSAF2.1): #199 test 6.3.13 for CSAF 2.1 - change to ssvc_v2
rainer-exxcellent 095d6d7
feat(CSAF2.1): #199 test 6.3.13 for CSAF 2.1 - fix test informativeTe…
rainer-exxcellent 6d380fc
feat(CSAF2.1): #199 test 6.3.13 for CSAF 2.1 - use registred namespaces
rainer-exxcellent ca42f0a
feat(CSAF2.1): #199 test 6.3.13 for CSAF 2.1 - document generation of…
rainer-exxcellent 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
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,118 @@ | ||
| import Ajv from 'ajv/dist/jtd.js' | ||
| import decision_points from '../../lib/ssvc/decision_points.js' | ||
|
|
||
| const ajv = new Ajv() | ||
|
|
||
| /** @typedef {import('ajv/dist/jtd.js').JTDDataType<typeof inputSchema>} InputSchema */ | ||
|
|
||
| /** @typedef {InputSchema['vulnerabilities'][number]} Vulnerability */ | ||
|
|
||
| /** @typedef {NonNullable<Vulnerability['metrics']>[number]} Metric */ | ||
|
|
||
| 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, | ||
| optionalProperties: { | ||
| selections: { | ||
| elements: { | ||
| additionalProperties: true, | ||
| optionalProperties: { | ||
| name: { type: 'string' }, | ||
| namespace: { type: 'string' }, | ||
| version: { type: 'string' }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| const validateInput = ajv.compile(inputSchema) | ||
|
|
||
| /** from https://github.com/CERTCC/SSVC/blob/main/src/ssvc/namespaces.py */ | ||
| const REGISTERED_NAMESPACES = [ | ||
| 'ssvc', | ||
| 'cvss', | ||
| 'cisa', | ||
| 'basic', | ||
| 'example', | ||
| 'test', | ||
| ] | ||
|
|
||
| /** | ||
| * For each SSVC decision point given under `selections` with a registered | ||
| * `namespace`, it MUST be tested the latest decision point | ||
| * `version` available at the time of the `timestamp` was used. | ||
| * The test SHALL fail if a later `version` was used. | ||
| * Namespaces reserved for special purpose MUST be treated as per their | ||
| * definition. | ||
| * | ||
| * @param {unknown} doc | ||
| * @returns | ||
| */ | ||
| export function informativeTest_6_3_13(doc) { | ||
| const ctx = { | ||
| infos: /** @type {Array<{ message: string; instancePath: string }>} */ ([]), | ||
| } | ||
|
|
||
| if (!validateInput(doc)) { | ||
| return ctx | ||
| } | ||
|
|
||
| const decisionPointName2Version = new Map() | ||
| decision_points.decisionPoints.forEach((obj) => { | ||
| const currentVersion = decisionPointName2Version.get(obj.name) | ||
| if (!currentVersion || currentVersion < obj.version) { | ||
| decisionPointName2Version.set(obj.name, obj.version) | ||
| } | ||
| }) | ||
|
|
||
| const vulnerabilities = doc.vulnerabilities | ||
|
|
||
| vulnerabilities.forEach((vulnerability, vulnerabilityIndex) => { | ||
| /** @type {Array<Metric> | undefined} */ | ||
| const metrics = vulnerability.metrics | ||
| metrics?.forEach((metric, metricIndex) => { | ||
| const selections = metric?.content?.ssvc_v2?.selections | ||
| selections?.forEach((selection, selectionIndex) => { | ||
| const latestVersion = decisionPointName2Version.get(selection?.name) | ||
| /** @type {string | undefined} */ | ||
| const namespace = selection.namespace | ||
| if ( | ||
| selection.version !== latestVersion && | ||
| namespace && | ||
| REGISTERED_NAMESPACES.includes(namespace) | ||
| ) { | ||
| ctx.infos.push({ | ||
| instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/ssvc_v2/selections/${selectionIndex}/version`, | ||
| message: `ssvc_v1 version '${selection.version}' is not latest decision point version '${latestVersion}'`, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message is misleading as well - it is all about the decision point (esp. the part |
||
| }) | ||
| } | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| return ctx | ||
| } | ||
Oops, something went wrong.
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.
Hmm - where do we check the timestamp stuff?
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.
Did we have the Informations to check this?