File tree Expand file tree Collapse file tree 3 files changed +2915
-15
lines changed
Expand file tree Collapse file tree 3 files changed +2915
-15
lines changed Original file line number Diff line number Diff line change 11from pathlib import Path
2+ from urllib .parse import urlparse
23
34from vulnerabilities .models import AffectedByPackageRelatedVulnerability
45from vulnerabilities .models import Exploit
89from vulnerabilities .severity_systems import EPSS
910from vulnerabilities .utils import load_json
1011
11- DEFAULT_WEIGHT = 1
12+ DEFAULT_WEIGHT = 5
1213WEIGHT_CONFIG_PATH = Path (__file__ ).parent .parent / "weight_config.json"
1314WEIGHT_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 )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments