diff --git a/vulnerabilities/templates/vulnerability_details.html b/vulnerabilities/templates/vulnerability_details.html index 7d4119ce2..23eb455e8 100644 --- a/vulnerabilities/templates/vulnerability_details.html +++ b/vulnerabilities/templates/vulnerability_details.html @@ -81,6 +81,13 @@ {{ vulnerability.summary }} + {% if severity_score_range %} + + Severity score range + {{ severity_score_range }} + + {% endif %} + diff --git a/vulnerabilities/utils.py b/vulnerabilities/utils.py index f9dd150ee..244ee9fa2 100644 --- a/vulnerabilities/utils.py +++ b/vulnerabilities/utils.py @@ -502,3 +502,30 @@ def is_vulnerable_nginx_version(version, affected_version_range, fixed_versions) return False return True return False + + +def get_severity_range(severity_list): + """ + >>> get_severity_range({'LOW','7.5','5'}) + '0.1 - 7.5' + >>> get_severity_range({'LOW','Medium'}) + '0.1 - 6.9' + >>> get_severity_range({'9.5','critical'}) + '9.0 - 10.0' + """ + if len(severity_list) > 1: + score_map = { + "low": [0.1, 3], + "moderate": [4.0, 6.9], + "medium": [4.0, 6.9], + "high": [7.0, 8.9], + "critical": [9.0, 10.0], + } + + score_list = [] + for score in severity_list: + try: + score_list.append(float(score)) + except ValueError: + score_list.extend(score_map[score.lower()]) + return f"{min(score_list)} - {max(score_list)}" diff --git a/vulnerabilities/views.py b/vulnerabilities/views.py index ae0d95d0d..4500f6220 100644 --- a/vulnerabilities/views.py +++ b/vulnerabilities/views.py @@ -24,6 +24,7 @@ from vulnerabilities.forms import PackageSearchForm from vulnerabilities.forms import VulnerabilitySearchForm from vulnerabilities.models import Weakness +from vulnerabilities.utils import get_severity_range from vulnerablecode.settings import env PAGE_SIZE = 20 @@ -125,6 +126,9 @@ def get_context_data(self, **kwargs): "vulnerability": self.object, "vulnerability_search_form": VulnerabilitySearchForm(self.request.GET), "severities": list(self.object.severities), + "severity_score_range": get_severity_range( + {s.value for s in self.object.severities} + ), "references": self.object.references.all(), "aliases": self.object.aliases.all(), "affected_packages": self.object.affected_packages.all(),