-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.py
89 lines (68 loc) · 2.35 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import re
from datetime import datetime
def is_valid_cve(cve_id):
"""
AA
Check if a given CVE ID is valid.
A CVE ID is considered valid if it is in the format CVE-YYYY-NNNN or
CVE-YYYY-NNNNN, where YYYY is a year from 1999 up to (and including) the
current year.
Args:
cve_id (str): The CVE ID to check.
Returns:
bool: True if the CVE ID is valid, False otherwise.
"""
current_year = datetime.now().year
# CVE-YYYY-NNNN or CVE-YYYY-NNNNN format where YYYY can be any year from 1999 up to the current year
# cve_regex = rf"(?i)^CVE-(19\d{{2}}|20\d{{2}})-\d{{4,}}$"
cve_regex = rf"(?i)^CVE-(19\d{{2}}|20\d{{2}})-\d{{4,8}}$"
# Ensure the year in the CVE ID is not greater than the current year
match = re.match(cve_regex, cve_id)
# Check if the year in the CVE ID is not greater than the current year
if match:
year = int(match.group(1))
if 1999 <= year <= current_year:
return True
return False
def cvss_color_calc(cvss_score):
"""
AA
Maps a CVSS severity score to a hex color.
Args:
cvss_score (str): The CVSS severity score to map.
Returns:
str: A hex color code corresponding to the CVSS severity score.
"""
# Dictionary mapping severity keywords to hex colors
severity_colors = {
"CRITICAL": "#d9534f", # Red
"HIGH": "#FFA500", # Orange
"MEDIUM": "#FFFF00", # Yellow
"LOW": "#008000", # Green
"INFORMATIONAL": "#5bc0de", # Blue
}
# Convert the text to uppercase for case-insensitive comparison
text_upper = cvss_score.upper()
# Iterate over the severity levels and find if any keyword is in the text
for severity, color in severity_colors.items():
if severity in text_upper:
return color
# Default color if no keyword is found
return "#808080" # Gray
def cve_status_color_calc(status):
"""
AA
Maps a CVE status to a hex color.
Args:
status (str): The CVE status to map.
Returns:
str: A hex color code corresponding to the CVE status.
"""
# Dictionary mapping status keywords to hex colors
status_colors = {
"published": "#BBCAE4",
"rejected": "#FACF4C",
"disputed": "#783DB9",
"reserved": "#A8AEB1",
}
return status_colors[status.lower()]