Skip to content

Commit 20a9ccf

Browse files
cskConrad Stein K (csk)
andauthored
Bugfix: Issue with score when CIA triad is None (#108)
* Add test of vector that must return 0.0 but is returning 6.9 * Fix issue when all metrics are N which was failing * Build project and upload changes which somehow are being tracked --------- Co-authored-by: Conrad Stein K (csk) <[email protected]>
1 parent 70ec41b commit 20a9ccf

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

dist/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,12 @@ function eq3eq6CalculateLowerMacroVector(eqLevels) {
12671267
}
12681268
function getScore2(vector) {
12691269
const vectorObj = util.getVectorObject(vector);
1270+
const allMetrics = ["VC", "VI", "VA", "SC", "SI", "SA"];
1271+
const allMetricsAreN = allMetrics.every((metric) => vectorObj[metric] === "N");
1272+
if (allMetricsAreN) {
1273+
const score2 = 0;
1274+
return parseFloat(score2.toFixed(1));
1275+
}
12701276
const metrics = {
12711277
AV: {},
12721278
PR: {},

dist_node/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,12 @@ function eq3eq6CalculateLowerMacroVector(eqLevels) {
12671267
}
12681268
function getScore2(vector) {
12691269
const vectorObj = util.getVectorObject(vector);
1270+
const allMetrics = ["VC", "VI", "VA", "SC", "SI", "SA"];
1271+
const allMetricsAreN = allMetrics.every((metric) => vectorObj[metric] === "N");
1272+
if (allMetricsAreN) {
1273+
const score2 = 0;
1274+
return parseFloat(score2.toFixed(1));
1275+
}
12701276
const metrics = {
12711277
AV: {},
12721278
PR: {},

lib/score_4_0.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ function eq3eq6CalculateLowerMacroVector(eqLevels: any) {
100100
function getScore(vector: string) {
101101
const vectorObj = util.getVectorObject(vector);
102102

103+
// Special case: if all metrics are N, return 0.0
104+
const allMetrics = ['VC', 'VI', 'VA', 'SC', 'SI', 'SA'] as const;
105+
const allMetricsAreN = allMetrics.every(metric => vectorObj[metric as keyof CvssVectorObject] === 'N');
106+
if (allMetricsAreN) {
107+
const score = 0.0;
108+
return parseFloat(score.toFixed(1));
109+
}
110+
103111
const metrics = {
104112
AV: {} as Metric, // EQ1
105113
PR: {} as Metric, // EQ1

test/cvss_4_0.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ const examples = [
6464
score: 9.7,
6565
vector: "CVSS:4.0/AV:A/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N/MSI:S/S:P"
6666
},
67-
{ score: 8.7, vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N/V:C" }
67+
{ score: 8.7, vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N/V:C" },
68+
{ score: 0.0, vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:N/SI:N/SA:N" },
6869
];
6970

7071
describe("Score Tests", () => {

0 commit comments

Comments
 (0)