Skip to content

Commit b2b580a

Browse files
authored
Merge pull request #73 from turingsecure/72-wrong-calculations
72 wrong calculations
2 parents 9c781d3 + df432cc commit b2b580a

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1 align="center">cvss.js by <a href="https://turingpoint.eu" target="_blank">turingpoint.</a></h1>
22
<p>
3-
<img alt="Version" src="https://img.shields.io/badge/version-1.4.4-blue.svg?cacheSeconds=2592000" />
3+
<img alt="Version" src="https://img.shields.io/badge/version-1.4.5-blue.svg?cacheSeconds=2592000" />
44
<a href="#" target="_blank">
55
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
66
</a>

dist/production.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/score.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function getEnvironmentalScore(vector) {
6161
const scopeChanged = vectorObject.MS === "X" ? vectorObject.S === "C" : vectorObject.MS === "C";
6262
const modifiedISCBase = calculateISCModifiedBase(vectorObject);
6363
const modifiedExploitability = calculateModifiedExploitability(vectorObject, scopeChanged);
64-
const modifiedISC = calculateISC(modifiedISCBase, scopeChanged, vector);
64+
const modifiedISC = calculateModifiedISC(modifiedISCBase, scopeChanged, vector);
6565

6666
if (modifiedISC <= 0) return 0;
6767

@@ -93,6 +93,15 @@ function getEnvironmentalScore(vector) {
9393
}
9494

9595
const calculateISC = function (iscBase, scopeChanged, vector) {
96+
if (!scopeChanged) return 6.42 * iscBase;
97+
if (util.getVersion(vector) === "3.0") {
98+
return 7.52 * (iscBase - 0.029) - 3.25 * Math.pow(iscBase - 0.02, 15);
99+
} else if (util.getVersion(vector) === "3.1") {
100+
return 7.52 * (iscBase - 0.029) - 3.25 * Math.pow(iscBase - 0.02, 15);
101+
}
102+
};
103+
104+
const calculateModifiedISC = function (iscBase, scopeChanged, vector) {
96105
if (!scopeChanged) return 6.42 * iscBase;
97106
if (util.getVersion(vector) === "3.0") {
98107
return 7.52 * (iscBase - 0.029) - 3.25 * Math.pow(iscBase - 0.02, 15);

lib/util.js

+13-17
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,19 @@ function roundUpApprox(num, precision) {
3535

3636
/**
3737
* @param {Number} num The number to round
38-
*
38+
*
3939
* @returns The rounded number
4040
*/
41-
function roundUpExact(num){
42-
const input = Math.round(num * 100000);
43-
if (input % 10000 === 0) {
44-
return input / 100000;
45-
}
46-
else {
47-
return (Math.floor(input / 10000) +1) / 10;
41+
function roundUpExact(num) {
42+
const int_input = Math.round(num * 100000);
43+
44+
if (int_input % 10000 === 0) {
45+
return int_input / 100000;
46+
} else {
47+
return (Math.floor(int_input / 10000) + 1) / 10;
4848
}
4949
}
5050

51-
5251
/**
5352
* Retrieves an object of vector's metrics
5453
*
@@ -67,7 +66,6 @@ function getVectorObject(vector) {
6766
return vectorObject;
6867
}
6968

70-
7169
/**
7270
* Returns a vector without undefined values
7371
*
@@ -248,18 +246,16 @@ function parseVectorObjectToString(obj) {
248246

249247
/**
250248
* Retrives the version from the vector string
251-
*
252-
* @return {String} returns the version number
249+
*
250+
* @return {String} returns the version number
253251
*/
254-
function getVersion(vector){
252+
function getVersion(vector) {
255253
const version = vector.split("/");
256254
if (version[0] === "CVSS:3.0") {
257255
return "3.0";
258-
}
259-
else if (version[0] === "CVSS:3.1") {
256+
} else if (version[0] === "CVSS:3.1") {
260257
return "3.1";
261-
}
262-
else {
258+
} else {
263259
return "Error";
264260
}
265261
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@turingpointde/cvss.js",
3-
"version": "1.4.4",
3+
"version": "1.4.5",
44
"description": "A tiny library to work with cvss vectors",
55
"scripts": {
66
"build": "webpack",

test/cvss.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ describe("Score Tests", () => {
1616
const vector4 = CVSS("CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N");
1717
expect(vector4.getScore()).toBe(8.2);
1818

19+
const vector6 = CVSS("CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H");
20+
21+
expect(vector6.getScore()).toBe(9.6);
22+
expect(vector6.getTemporalScore()).toBe(9.6);
23+
expect(vector6.getEnvironmentalScore()).toBe(9.7);
24+
1925
const vector5 = CVSS({
2026
A: "N",
2127
AC: "L",

0 commit comments

Comments
 (0)