Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for severity range #1179

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading