Skip to content

Commit 4d3ae93

Browse files
committed
add support for calculating CVSS score from the CVSS vector
Reference: #713 Signed-off-by: Ziad <[email protected]>
1 parent f71776b commit 4d3ae93

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,5 @@ wcwidth==0.2.5
113113
websocket-client==0.59.0
114114
yarl==1.7.2
115115
zipp==3.8.0
116-
dateparser==1.1.1
116+
dateparser==1.1.1
117+
cvss==2.4

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ install_requires =
7676
defusedxml>=0.7.1
7777
Markdown>=3.3.0
7878
dateparser>=1.1.1
79+
cvss>=2.4
7980

8081
# networking
8182
GitPython>=3.1.17

vulnerabilities/severity_systems.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
# Visit https://github.com/nexB/vulnerablecode/ for support and download.
2222

2323
import dataclasses
24+
from decimal import Decimal
25+
26+
from cvss import CVSS2
27+
from cvss import CVSS3
2428

2529
"""
2630
Vulnerability scoring systems define scales, values and approach to score a
@@ -30,7 +34,6 @@
3034

3135
@dataclasses.dataclass(order=True)
3236
class ScoringSystem:
33-
3437
# a short identifier for the scoring system.
3538
identifier: str
3639
# a name which represents the scoring system such as `RedHat bug severity`.
@@ -41,13 +44,20 @@ class ScoringSystem:
4144
# notes about that scoring system
4245
notes: str = ""
4346

44-
def as_score(self, value):
47+
def as_score(self, value) -> Decimal:
4548
"""
4649
Return a normalized numeric score for this scoring system given a raw
4750
value. For instance this can be used to convert a CVSS vector to a base
4851
score.
4952
"""
50-
raise NotImplementedError
53+
if self.identifier == "cvssv2_vector":
54+
c = CVSS2(value)
55+
return c.base_score
56+
elif self.identifier in ["cvssv3_vector", "cvssv3.1_vector"]:
57+
c = CVSS3(value)
58+
return c.base_score
59+
else:
60+
raise NotImplementedError
5161

5262

5363
CVSSV2 = ScoringSystem(

0 commit comments

Comments
 (0)