A tiny library to work with CVSS vectors (v3.0 and v3.1) in JavaScript. The Common Vulnerability Scoring System (CVSS) is a free and open standard. It is owned and managed by FIRST.Org.
Installation
Install the @turingpointde/cvss.js
package:
yarn add @turingpointde/cvss.js
Import the library to use it in your code:
const CVSS = require("@turingpointde/cvss.js");
import CVSS from "@turingpointde/cvss.js";
You can also use the library directly from the CDN (instead of yarn or npm):
<script src="https://unpkg.com/@turingpointde/cvss.js@latest/dist/production.min.js"></script>
Usage
After importing the library, the CVSS function must first be called with the vector as parameter.
const vector1 = CVSS("CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L");
const vector2 = CVSS(
"CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:U/RL:T/RC:R"
);
const vector3 = CVSS(
"CVSS:3.0/AV:L/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N/CR:M/IR:H/AR:M/MAV:N/MAC:H/MPR:L/MUI:N/MS:C/MC:N/MI:L/MA:L"
);
It is possible to pass in an object as well
const vectorObject = {
CVSS: "3.0",
AV: "N",
AC: "H",
PR: "H",
UI: "R",
S: "U",
C: "H",
I: "N",
A: "N",
};
console.log(CVSS(vectorObject).vector);
To get the scores, simply call the respective function.
const vector = CVSS(
"CVSS:3.0/AV:L/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N/E:P/RL:O/CR:M/IR:H/AR:M/MAV:N/MAC:H/MPR:L/MUI:N/MS:C/MC:N/MI:L/MA:L"
);
console.log(vector.getScore());
console.log(vector.getTemporalScore());
console.log(vector.getEnvironmentalScore());
console.log(vector.getImpactSubScore());
console.log(vector.getExploitabilitySubScore());
Sometimes it is useful to get a qualitative rating of a score
const vector = CVSS("CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L");
console.log(vector.getRating());
console.log(vector.getTemporalRating());
console.log(vector.getEnvironmentalRating());
A few useful variables/functions to work with the vectors:
const vector = CVSS("CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L");
console.log(vector.isValid);
console.log(vector.vector);
console.log(vector.getVersion());
The following functions are suitable for displaying the vector in a human-readable form or for performing your own calculations with the vector
const vector = CVSS(
"CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:U/RL:T/RC:R/MAC:X/MUI:X/MA:X/MI:X"
);
console.log(vector.getVectorObject());
console.log(vector.getCleanVectorString());
console.log(vector.getDetailedVectorObject());
Output of vector.getDetailedVectorObject
{
CVSS: '3.0',
metrics: {
AV: {
name: 'Attack Vector',
abbr: 'AV',
fullName: 'Attack Vector (AV)',
value: 'Network',
valueAbbr: 'N'
},
AC: {
name: 'Attack Complexity',
abbr: 'AC',
fullName: 'Attack Complexity (AC)',
value: 'High',
valueAbbr: 'H'
},
PR: {
name: 'Privileges Required',
abbr: 'PR',
fullName: 'Privileges Required (PR)',
value: 'Low',
valueAbbr: 'L'
},
UI: {
name: 'User Interaction',
abbr: 'UI',
fullName: 'User Interaction (UI)',
value: 'Required',
valueAbbr: 'R'
},
S: {
name: 'Scope',
abbr: 'S',
fullName: 'Scope (S)',
value: 'Changed',
valueAbbr: 'C'
},
C: {
name: 'Confidentiality',
abbr: 'C',
fullName: 'Confidentiality (C)',
value: 'Low',
valueAbbr: 'L'
},
I: {
name: 'Integrity',
abbr: 'I',
fullName: 'Integrity (I)',
value: 'Low',
valueAbbr: 'L'
},
A: {
name: 'Availability',
abbr: 'A',
fullName: 'Availability (A)',
value: 'Low',
valueAbbr: 'L'
},
E: {
name: 'Exploit Code Maturity',
abbr: 'E',
fullName: 'Exploit Code Maturity (E)',
value: 'Unproven',
valueAbbr: 'U'
},
RL: {
name: 'Remediation Level',
abbr: 'RL',
fullName: 'Remediation Level (RL)',
value: 'Temporary Fix',
valueAbbr: 'T'
},
RC: {
name: 'Report Confidence',
abbr: 'RC',
fullName: 'Report Confidence (RC)',
value: 'Reasonable',
valueAbbr: 'R'
},
MAC: {
name: 'Modified Attack Complexity',
abbr: 'MAC',
fullName: 'Modified Attack Complexity (MAC)',
value: 'Not Defined',
valueAbbr: 'X'
},
MUI: {
name: 'Modified User Interaction',
abbr: 'MUI',
fullName: 'Modified User Interaction (MUI)',
value: 'Not Defined',
valueAbbr: 'X'
},
MA: {
name: 'Modified Availability',
abbr: 'MA',
fullName: 'Modified Availability (MA)',
value: 'Not Defined',
valueAbbr: 'X'
},
MI: {
name: 'Modified Integrity',
abbr: 'MI',
fullName: 'Modified Integrity (MI)',
value: 'Not Defined',
valueAbbr: 'X'
}
}
}
To update a vector's metric:
const vector = CVSS(
"CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N/RL:X/RC:X"
).updateVectorValue("AV", "L");
console.log(vector);
Contributing
Contributions, issues and feature requests are welcome.
Feel free to check out the issues page if you want to contribute.
License
Copyright © 2022 turingpoint GmbH.
This project is MIT licensed.