Skip to content

Commit 3797be8

Browse files
committed
add support for calculating CVSS score from the CVSS vector
Reference: #713 Signed-off-by: Ziad <ziadhany2016@gmail.com> resolve conflicts requirements.txt Signed-off-by: Ziad <ziadhany2016@gmail.com>
1 parent 377826e commit 3797be8

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ install_requires =
7878
defusedxml>=0.7.1
7979
Markdown>=3.3.0
8080
dateparser>=1.1.1
81+
cvss>=2.4
8182

8283
# networking
8384
GitPython>=3.1.17

vulnerabilities/severity_systems.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#
99

1010
import dataclasses
11+
from decimal import Decimal
12+
13+
from cvss import CVSS2
14+
from cvss import CVSS3
1115

1216
"""
1317
Vulnerability scoring systems define scales, values and approach to score a
@@ -17,7 +21,6 @@
1721

1822
@dataclasses.dataclass(order=True)
1923
class ScoringSystem:
20-
2124
# a short identifier for the scoring system.
2225
identifier: str
2326
# a name which represents the scoring system such as `RedHat bug severity`.
@@ -28,13 +31,20 @@ class ScoringSystem:
2831
# notes about that scoring system
2932
notes: str = ""
3033

31-
def as_score(self, value):
34+
def as_score(self, value) -> Decimal:
3235
"""
3336
Return a normalized numeric score for this scoring system given a raw
3437
value. For instance this can be used to convert a CVSS vector to a base
3538
score.
3639
"""
37-
raise NotImplementedError
40+
if self.identifier == "cvssv2_vector":
41+
c = CVSS2(value)
42+
return c.base_score
43+
elif self.identifier in ["cvssv3_vector", "cvssv3.1_vector"]:
44+
c = CVSS3(value)
45+
return c.base_score
46+
else:
47+
raise NotImplementedError
3848

3949

4050
CVSSV2 = ScoringSystem(

0 commit comments

Comments
 (0)