Skip to content

Commit

Permalink
Add support for severity range (#1179)
Browse files Browse the repository at this point in the history
Signed-off-by: ziadhany <ziadhany2016@gmail.com>
  • Loading branch information
ziadhany authored Sep 5, 2023
1 parent eec05bb commit 2800d6a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions vulnerabilities/templates/vulnerability_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
<td class="two-col-right wrap-strings">{{ vulnerability.summary }}
</td>
</tr>
{% if severity_score_range %}
<tr>
<td class="two-col-left">Severity score range</td>
<td class="two-col-right">{{ severity_score_range }}
</td>
{% endif %}
</tr>
</tbody>
</table>
</div>
Expand Down
27 changes: 27 additions & 0 deletions vulnerabilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
4 changes: 4 additions & 0 deletions vulnerabilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 2800d6a

Please sign in to comment.