Skip to content

Commit

Permalink
add support for calculating CVSS score from the CVSS vector
Browse files Browse the repository at this point in the history
Reference: aboutcode-org#713

Signed-off-by: Ziad <[email protected]>

resolve conflicts requirements.txt

Signed-off-by: Ziad <[email protected]>
  • Loading branch information
ziadhany committed Sep 12, 2022
1 parent 377826e commit 3797be8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ install_requires =
defusedxml>=0.7.1
Markdown>=3.3.0
dateparser>=1.1.1
cvss>=2.4

# networking
GitPython>=3.1.17
Expand Down
16 changes: 13 additions & 3 deletions vulnerabilities/severity_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#

import dataclasses
from decimal import Decimal

from cvss import CVSS2
from cvss import CVSS3

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

@dataclasses.dataclass(order=True)
class ScoringSystem:

# a short identifier for the scoring system.
identifier: str
# a name which represents the scoring system such as `RedHat bug severity`.
Expand All @@ -28,13 +31,20 @@ class ScoringSystem:
# notes about that scoring system
notes: str = ""

def as_score(self, value):
def as_score(self, value) -> Decimal:
"""
Return a normalized numeric score for this scoring system given a raw
value. For instance this can be used to convert a CVSS vector to a base
score.
"""
raise NotImplementedError
if self.identifier == "cvssv2_vector":
c = CVSS2(value)
return c.base_score
elif self.identifier in ["cvssv3_vector", "cvssv3.1_vector"]:
c = CVSS3(value)
return c.base_score
else:
raise NotImplementedError


CVSSV2 = ScoringSystem(
Expand Down

0 comments on commit 3797be8

Please sign in to comment.