Skip to content

Commit a121f44

Browse files
committed
Update the weight_config dict and modify it to use domain names.
Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent 0e114ac commit a121f44

File tree

3 files changed

+2915
-15
lines changed

3 files changed

+2915
-15
lines changed

vulnerabilities/risk.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
from urllib.parse import urlparse
23

34
from vulnerabilities.models import AffectedByPackageRelatedVulnerability
45
from vulnerabilities.models import Exploit
@@ -8,7 +9,7 @@
89
from vulnerabilities.severity_systems import EPSS
910
from vulnerabilities.utils import load_json
1011

11-
DEFAULT_WEIGHT = 1
12+
DEFAULT_WEIGHT = 5
1213
WEIGHT_CONFIG_PATH = Path(__file__).parent.parent / "weight_config.json"
1314
WEIGHT_CONFIG = load_json(WEIGHT_CONFIG_PATH)
1415

@@ -32,17 +33,10 @@ def get_weighted_severity(severities):
3233

3334
score_list = []
3435
for severity in severities:
35-
weights = []
36-
for key, value in WEIGHT_CONFIG.items():
37-
if severity.reference.url.startswith(key):
38-
weights.append(value)
39-
continue
40-
weights.append(DEFAULT_WEIGHT)
41-
42-
if not weights:
43-
return 0
44-
45-
max_weight = float(max(weights)) / 10
36+
parsed_url = urlparse(severity.reference.url)
37+
severity_source = parsed_url.netloc.replace("www.", "", 1)
38+
weight = WEIGHT_CONFIG.get(severity_source, DEFAULT_WEIGHT)
39+
max_weight = float(weight) / 10
4640
vul_score = severity.value
4741
try:
4842
vul_score = float(vul_score)

vulnerabilities/tests/test_risk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def test_get_weighted_severity(vulnerability):
156156

157157
VulnerabilityRelatedReference.objects.create(reference=reference2, vulnerability=vulnerability)
158158
new_severities = vulnerability.severities.all()
159-
assert get_weighted_severity(new_severities) == 9
159+
assert get_weighted_severity(new_severities) == 7
160160

161161

162162
@pytest.mark.django_db

0 commit comments

Comments
 (0)