-
Notifications
You must be signed in to change notification settings - Fork 547
feat: recommending safe packages #1284
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
Changes from 41 commits
37d2d7d
d303f2e
375b4f4
eedfbe1
ad6d2b1
31ca3b0
1a5ce74
117e325
77e9021
2338715
6288d52
105d2b8
c7615dd
5941d75
3ddbb06
ec8a220
8ca0c91
3171111
6bbc0af
227ddf8
c4ec775
eca217c
53c0ad8
1ba41bd
4b4fbf5
167fe44
f5e3d9f
7898bc8
2ca3ac9
b5f60b9
11da696
e9fc05d
f03ab41
9c7d359
1a455a2
ca10757
e8a493f
3641b07
01a7c5f
bb1e80c
c61e9d0
709fd69
0e1ca78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,12 +16,58 @@ | |||||||||||||||||||||||||||||||||||||
from ..input_engine import Remarks | ||||||||||||||||||||||||||||||||||||||
from ..linkify import linkify_cve | ||||||||||||||||||||||||||||||||||||||
from ..theme import cve_theme | ||||||||||||||||||||||||||||||||||||||
from ..util import ProductInfo | ||||||||||||||||||||||||||||||||||||||
from ..util import ProductInfo, VersionInfo | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
def format_version_range( | ||||||||||||||||||||||||||||||||||||||
start_including, start_excluding, end_including, end_excluding | ||||||||||||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||
formats version info to desirable output | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Just to be consistent with another function in this module |
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
Example: | ||||||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||||||
format_version_info('2.2.8', '', '2.2.11', '') => "[2.2.8 - 2.2.11]" | ||||||||||||||||||||||||||||||||||||||
format_version_info('2.2.8', '', '', '2.2.11') => "[2.2.8 - 2.2.11)" | ||||||||||||||||||||||||||||||||||||||
format_version_info('', '2.2.8', '2.2.11', '') => "(2.2.8 - 2.2.11]" | ||||||||||||||||||||||||||||||||||||||
format_version_info('', '2.2.8', '', '2.2.11') => "(2.2.8 - 2.2.11])" | ||||||||||||||||||||||||||||||||||||||
format_version_info('2.2.8', '', '', '') => ">= 2.2.8" | ||||||||||||||||||||||||||||||||||||||
format_version_info('', '2.2.8', '', '') => "> 2.2.8" | ||||||||||||||||||||||||||||||||||||||
format_version_info('', '', '2.2.11', '') => "<= 2.2.11" | ||||||||||||||||||||||||||||||||||||||
format_version_info('', '', '', '2.2.11') => "< 2.2.11" | ||||||||||||||||||||||||||||||||||||||
format_version_infor([]) => "-" | ||||||||||||||||||||||||||||||||||||||
peb-peb marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
Reference for Interval terminologies: https://en.wikipedia.org/wiki/Interval_(mathematics) | ||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
versions = (start_including, start_excluding, end_including, end_excluding) | ||||||||||||||||||||||||||||||||||||||
if versions: | ||||||||||||||||||||||||||||||||||||||
# should refactor to use python 3.10's "Structural Pattern Matching" | ||||||||||||||||||||||||||||||||||||||
if start_including and end_including: | ||||||||||||||||||||||||||||||||||||||
return f"[{start_including} - {end_including}]" | ||||||||||||||||||||||||||||||||||||||
elif start_including and end_excluding: | ||||||||||||||||||||||||||||||||||||||
return f"[{start_including} - {end_excluding})" | ||||||||||||||||||||||||||||||||||||||
elif start_excluding and end_including: | ||||||||||||||||||||||||||||||||||||||
return f"({start_excluding} - {end_including}]" | ||||||||||||||||||||||||||||||||||||||
elif start_excluding and end_excluding: | ||||||||||||||||||||||||||||||||||||||
return f"({start_excluding} - {end_excluding})" | ||||||||||||||||||||||||||||||||||||||
elif start_including: | ||||||||||||||||||||||||||||||||||||||
return f">= {start_including}" | ||||||||||||||||||||||||||||||||||||||
elif start_excluding: | ||||||||||||||||||||||||||||||||||||||
return f"> {start_excluding}" | ||||||||||||||||||||||||||||||||||||||
elif end_including: | ||||||||||||||||||||||||||||||||||||||
return f"<= {end_including}" | ||||||||||||||||||||||||||||||||||||||
elif end_excluding: | ||||||||||||||||||||||||||||||||||||||
return f"< {end_excluding}" | ||||||||||||||||||||||||||||||||||||||
return "-" | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can anyone think of a better approach for this? OR we could just wait for python 3.10 and add the "Structural Pattern Matching" (Maybe we should open a "good first issue" issue for this as a reminder for future) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Waiting for Python 3.10 is not an option as cve-bin-tool supports all currently supported Python versions. So 3.9 will go out of support in 2025, only then 3.10 will become the minimum supported version (of course if cve-bin-tool continues to support all versions). I would still rewrite it a bit because def format_version_range(version_info: VersionInfo) -> str:
(start_including, start_excluding, end_including, end_excluding) = version_info
if start_including and end_including:
return f"[{start_including} - {end_including}]"
if start_including and end_excluding:
return f"[{start_including} - {end_excluding})"
if start_excluding and end_including:
return f"({start_excluding} - {end_including}]"
if start_excluding and end_excluding:
return f"({start_excluding} - {end_excluding})"
if start_including:
return f">= {start_including}"
if start_excluding:
return f"> {start_excluding}"
if end_including:
return f"<= {end_including}"
if end_excluding:
return f"< {end_excluding}"
return "-" |
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
def output_console( | ||||||||||||||||||||||||||||||||||||||
all_cve_data: Dict[ProductInfo, CVEData], | ||||||||||||||||||||||||||||||||||||||
all_cve_version_info: Dict[str, VersionInfo], | ||||||||||||||||||||||||||||||||||||||
time_of_last_update, | ||||||||||||||||||||||||||||||||||||||
affected_versions: int, | ||||||||||||||||||||||||||||||||||||||
console=Console(theme=cve_theme), | ||||||||||||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||||||||||||
"""Output list of CVEs in a tabular format with color support""" | ||||||||||||||||||||||||||||||||||||||
|
@@ -65,6 +111,35 @@ def output_console( | |||||||||||||||||||||||||||||||||||||
"cvss_version": cve.cvss_version, | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
if affected_versions != 0: | ||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||
start_including = dict(all_cve_version_info)[ | ||||||||||||||||||||||||||||||||||||||
cve.cve_number | ||||||||||||||||||||||||||||||||||||||
].start_including | ||||||||||||||||||||||||||||||||||||||
start_excluding = dict(all_cve_version_info)[ | ||||||||||||||||||||||||||||||||||||||
cve.cve_number | ||||||||||||||||||||||||||||||||||||||
].start_excluding | ||||||||||||||||||||||||||||||||||||||
end_including = dict(all_cve_version_info)[ | ||||||||||||||||||||||||||||||||||||||
cve.cve_number | ||||||||||||||||||||||||||||||||||||||
].end_including | ||||||||||||||||||||||||||||||||||||||
end_excluding = dict(all_cve_version_info)[ | ||||||||||||||||||||||||||||||||||||||
cve.cve_number | ||||||||||||||||||||||||||||||||||||||
].end_excluding | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First of all,
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or go further and:
if affected_versions != 0:
try:
version_info = all_cve_version_info[cve.cve_number]
except KeyError: # TODO: handle 'UNKNOWN' and some cves more cleanly
version_info = VersionInfo()
cve_by_remarks[cve.remarks][-1].update(
{"affected_versions": format_version_range(version_info)}
) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was using
This was a very clean change :) |
||||||||||||||||||||||||||||||||||||||
except KeyError: # TODO: handle 'UNKNOWN' and some cves more cleanly | ||||||||||||||||||||||||||||||||||||||
start_including = "" | ||||||||||||||||||||||||||||||||||||||
start_excluding = "" | ||||||||||||||||||||||||||||||||||||||
end_including = "" | ||||||||||||||||||||||||||||||||||||||
end_excluding = "" | ||||||||||||||||||||||||||||||||||||||
cve_by_remarks[cve.remarks][-1].update( | ||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||
"affected_versions": format_version_range( | ||||||||||||||||||||||||||||||||||||||
start_including, | ||||||||||||||||||||||||||||||||||||||
start_excluding, | ||||||||||||||||||||||||||||||||||||||
end_including, | ||||||||||||||||||||||||||||||||||||||
end_excluding, | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote a comment for this, but am not able to find it now. So, I'm writing it again :( Can we do something else (instead of For But, when some cves are not found in the I'm facing this issue when running it over
here,
Here, |
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
for remarks in sorted(cve_by_remarks): | ||||||||||||||||||||||||||||||||||||||
color = remarks_colors[remarks] | ||||||||||||||||||||||||||||||||||||||
|
@@ -79,24 +154,43 @@ def output_console( | |||||||||||||||||||||||||||||||||||||
table.add_column("CVE Number") | ||||||||||||||||||||||||||||||||||||||
table.add_column("Severity") | ||||||||||||||||||||||||||||||||||||||
table.add_column("Score (CVSS Version)") | ||||||||||||||||||||||||||||||||||||||
if affected_versions != 0: | ||||||||||||||||||||||||||||||||||||||
table.add_column("Affected Versions") | ||||||||||||||||||||||||||||||||||||||
# table.add_column("CVSS Version") | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
for cve_data in cve_by_remarks[remarks]: | ||||||||||||||||||||||||||||||||||||||
color = cve_data["severity"].lower() | ||||||||||||||||||||||||||||||||||||||
table.add_row( | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["vendor"], color), | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["product"], color), | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["version"], color), | ||||||||||||||||||||||||||||||||||||||
linkify_cve(Text.styled(cve_data["cve_number"], color)), | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["severity"], color), | ||||||||||||||||||||||||||||||||||||||
Text.styled( | ||||||||||||||||||||||||||||||||||||||
str(cve_data["score"]) | ||||||||||||||||||||||||||||||||||||||
+ " (v" | ||||||||||||||||||||||||||||||||||||||
+ str(cve_data["cvss_version"]) | ||||||||||||||||||||||||||||||||||||||
+ ")", | ||||||||||||||||||||||||||||||||||||||
color, | ||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
if affected_versions != 0: | ||||||||||||||||||||||||||||||||||||||
table.add_row( | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["vendor"], color), | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["product"], color), | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["version"], color), | ||||||||||||||||||||||||||||||||||||||
linkify_cve(Text.styled(cve_data["cve_number"], color)), | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["severity"], color), | ||||||||||||||||||||||||||||||||||||||
Text.styled( | ||||||||||||||||||||||||||||||||||||||
str(cve_data["score"]) | ||||||||||||||||||||||||||||||||||||||
+ " (v" | ||||||||||||||||||||||||||||||||||||||
+ str(cve_data["cvss_version"]) | ||||||||||||||||||||||||||||||||||||||
+ ")", | ||||||||||||||||||||||||||||||||||||||
color, | ||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["affected_versions"], color), | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||
table.add_row( | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["vendor"], color), | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["product"], color), | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["version"], color), | ||||||||||||||||||||||||||||||||||||||
linkify_cve(Text.styled(cve_data["cve_number"], color)), | ||||||||||||||||||||||||||||||||||||||
Text.styled(cve_data["severity"], color), | ||||||||||||||||||||||||||||||||||||||
Text.styled( | ||||||||||||||||||||||||||||||||||||||
str(cve_data["score"]) | ||||||||||||||||||||||||||||||||||||||
+ " (v" | ||||||||||||||||||||||||||||||||||||||
+ str(cve_data["cvss_version"]) | ||||||||||||||||||||||||||||||||||||||
+ ")", | ||||||||||||||||||||||||||||||||||||||
color, | ||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to deduplicate this? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah cells = [
Text.styled(cve_data["vendor"], color),
Text.styled(cve_data["product"], color),
Text.styled(cve_data["version"], color),
linkify_cve(Text.styled(cve_data["cve_number"], color)),
Text.styled(cve_data["severity"], color),
Text.styled(
f"{cve_data['score']} (v{cve_data['cvss_version']})", color
),
]
if affected_versions != 0:
cells.append(Text.styled(cve_data["affected_versions"], color))
table.add_row(*cells) |
||||||||||||||||||||||||||||||||||||||
# Print the table to the console | ||||||||||||||||||||||||||||||||||||||
console.print(table) | ||||||||||||||||||||||||||||||||||||||
for cve_data in cve_by_remarks[remarks]: | ||||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.