-
Notifications
You must be signed in to change notification settings - Fork 9
Feat/199 informative tests csaf2.1 6.3.13 #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
4
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
4 commits
Select commit
Hold shift + click to select a range
e12dc36
feat: update csaf and exclude new tests
domachine 6867f76
feat(CSAF2.1): #199 test 6.3.13 for CSAF 2.1
rainer-exxcellent a7f24a9
feat(CSAF2.1): #199 test 6.3.13 for CSAF 2.1 - change optionalPropert…
rainer-exxcellent 8006afb
feat(CSAF2.1): #199 test 6.3.13 for CSAF 2.1 - move test in README to…
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import Ajv from 'ajv/dist/jtd.js' | ||
import decision_points from '../../lib/cvss/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_v1: { | ||
additionalProperties: true, | ||
optionalProperties: { | ||
selections: { | ||
elements: { | ||
additionalProperties: true, | ||
optionalProperties: { | ||
name: { type: 'string' }, | ||
namespace: { type: 'string' }, | ||
version: { type: 'string' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
const validateInput = ajv.compile(inputSchema) | ||
|
||
/** | ||
* For each SSVC decision point given under selections with the namespace of ssvc, | ||
* 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. | ||
* @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_v1?.selections | ||
selections?.forEach((selection, selectionIndex) => { | ||
const latestVersion = decisionPointName2Version.get(selection?.name) | ||
if ( | ||
selection.version !== latestVersion && | ||
selection.namespace === 'ssvc' | ||
) { | ||
ctx.infos.push({ | ||
instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/ssvc_v1/selections/${selectionIndex}/version`, | ||
message: `ssvc_v1 version '${selection.version}' is not latest decision point version '${latestVersion}'`, | ||
}) | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
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,148 @@ | ||
export default { | ||
decisionPoints: [ | ||
{ | ||
name: 'Automatable', | ||
namespace: 'ssvc', | ||
version: '2.0.0', | ||
key: 'A', | ||
}, | ||
{ name: 'Exploitation', namespace: 'ssvc', version: '1.0.0', key: 'E' }, | ||
{ | ||
name: 'Exploitation', | ||
namespace: 'ssvc', | ||
version: '1.1.0', | ||
key: 'E', | ||
}, | ||
{ name: 'Human Impact', namespace: 'ssvc', version: '1.0.0', key: 'HI' }, | ||
{ | ||
name: 'Human Impact', | ||
namespace: 'ssvc', | ||
version: '2.0.0', | ||
key: 'HI', | ||
}, | ||
{ | ||
name: 'Human Impact', | ||
namespace: 'ssvc', | ||
version: '2.0.1', | ||
key: 'HI', | ||
}, | ||
{ | ||
name: 'Mission and Well-Being Impact', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'MWI', | ||
}, | ||
{ name: 'Mission Impact', namespace: 'ssvc', version: '1.0.0', key: 'MI' }, | ||
{ | ||
name: 'Mission Impact', | ||
namespace: 'ssvc', | ||
version: '2.0.0', | ||
key: 'MI', | ||
}, | ||
{ | ||
name: 'Public Safety Impact', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'PSI', | ||
}, | ||
{ | ||
name: 'Public Safety Impact', | ||
namespace: 'ssvc', | ||
version: '2.0.0', | ||
key: 'PSI', | ||
}, | ||
{ | ||
name: 'Public Safety Impact', | ||
namespace: 'ssvc', | ||
version: '2.0.1', | ||
key: 'PSI', | ||
}, | ||
{ | ||
name: 'Public Value Added', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'PVA', | ||
}, | ||
{ | ||
name: 'Public Well-Being Impact', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'PWI', | ||
}, | ||
{ | ||
name: 'Report Credibility', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'RC', | ||
}, | ||
{ | ||
name: 'Report Public', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'RP', | ||
}, | ||
{ name: 'Safety Impact', namespace: 'ssvc', version: '1.0.0', key: 'SI' }, | ||
{ | ||
name: 'Safety Impact', | ||
namespace: 'ssvc', | ||
version: '2.0.0', | ||
key: 'SI', | ||
}, | ||
{ | ||
name: 'Supplier Cardinality', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'SC', | ||
}, | ||
{ | ||
name: 'Supplier Contacted', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'SC', | ||
}, | ||
{ | ||
name: 'Supplier Engagement', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'SE', | ||
}, | ||
{ | ||
name: 'Supplier Involvement', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'SI', | ||
}, | ||
{ | ||
name: 'System Exposure', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'EXP', | ||
}, | ||
{ | ||
name: 'System Exposure', | ||
namespace: 'ssvc', | ||
version: '1.0.1', | ||
key: 'EXP', | ||
}, | ||
{ | ||
name: 'Technical Impact', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'TI', | ||
}, | ||
{ | ||
name: 'Utility', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'U', | ||
}, | ||
{ name: 'Utility', namespace: 'ssvc', version: '1.0.1', key: 'U' }, | ||
{ | ||
name: 'Value Density', | ||
namespace: 'ssvc', | ||
version: '1.0.0', | ||
key: 'VD', | ||
}, | ||
{ name: 'Virulence', namespace: 'ssvc', version: '1.0.0', key: 'V' }, | ||
], | ||
} |
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,96 @@ | ||
/* | ||
Script to read all CVSS decision points from github and create a json File with all defined decision points | ||
*/ | ||
|
||
import fs from 'node:fs' | ||
|
||
const CVSS_DECISION_POINT_URL = | ||
'https://api.github.com/repos/CERTCC/SSVC/contents/data/json/decision_points?ref=main' | ||
const OUTPUT_FILE = '../lib/cvss/decision_points.js' | ||
|
||
const GITHUB_TOKEN = '' | ||
|
||
/** | ||
* @typedef {object} GithubResponse | ||
* @property {string} name | ||
* @property {string} path | ||
* @property {string} sha | ||
* @property {number} size | ||
* @property {string} url | ||
* @property {string} html_url | ||
* @property {string} git_url | ||
* @property {string} download_url | ||
* @property {string} type | ||
*/ | ||
|
||
/** | ||
* @typedef {object} DecisionPoint | ||
* @property {string} name | ||
* @property {string} description | ||
* @property {string} namespace | ||
* @property {string} version | ||
* @property {string} schemaVersion | ||
* @property {string} key | ||
*/ | ||
|
||
/** | ||
* @typedef {object} DecisionPointInfo | ||
* @property {string} name | ||
* @property {string} namespace | ||
* @property {string} version | ||
* @property {string} key | ||
*/ | ||
|
||
/** | ||
* Read Json from given URL | ||
* @param {string | URL | Request} dataUrl | ||
* @param {string} githubToken | ||
*/ | ||
async function readJson(dataUrl, githubToken) { | ||
/** @type {any} */ | ||
const headers = { Accept: 'application/vnd.github.v3+json' } | ||
if (GITHUB_TOKEN) { | ||
headers['Authorization'] = `Bearer ${githubToken}` | ||
} | ||
const response = await fetch(dataUrl, { headers }) | ||
if (!response.ok) { | ||
throw new Error(`Response status: ${response.status}`) | ||
} | ||
|
||
return await response.json() | ||
} | ||
|
||
/** | ||
* Read decision points from github and write them to a JSON file | ||
* @param {string} githubToken | ||
*/ | ||
async function readDecisionPoints(githubToken) { | ||
/** @type {Array<GithubResponse>} */ | ||
const data = await readJson(CVSS_DECISION_POINT_URL, githubToken) | ||
/** @type {Array<DecisionPointInfo>} */ | ||
const result = [] | ||
for (const item of data) { | ||
if (item.name.endsWith('.json')) { | ||
/** @type {DecisionPoint} */ | ||
const decisionPoint = await readJson(item.download_url, githubToken) | ||
result.push({ | ||
name: decisionPoint.name, | ||
namespace: decisionPoint.namespace, | ||
version: decisionPoint.version, | ||
key: decisionPoint.key, | ||
}) | ||
} | ||
} | ||
return result | ||
} | ||
|
||
readDecisionPoints(GITHUB_TOKEN).then((points) => { | ||
console.log(points) | ||
const pointsObject = { decisionPoints: points } | ||
const pointsJson = 'export default ' + JSON.stringify(pointsObject) | ||
fs.writeFile(OUTPUT_FILE, pointsJson, (err) => { | ||
if (err) { | ||
console.log(err) | ||
} | ||
}) | ||
}) |
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.
The error message is misleading as well - it is all about the decision point (esp. the part
ssvc_v1 version '${selection.version}
)