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 description to amazon provider #278

Merged
merged 2 commits into from
Sep 20, 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
19 changes: 16 additions & 3 deletions src/vunnel/providers/amazon/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,11 @@ def get(self, skip_if_exists=False):
# split the package name and version of the fixed in packages and construct a set
fixed_in = {self.get_package_name_version(pkg_name) for pkg_name in parser.fixes}

# concat the descriptions paragraph
description = "".join(parser.issue_overview_text)

# construct a vulnerability object and yield it
yield map_to_vulnerability(version, alas, fixed_in)
yield map_to_vulnerability(version, alas, fixed_in, description)


class JsonifierMixin:
Expand Down Expand Up @@ -211,6 +214,9 @@ class PackagesHTMLParser(HTMLParser):

def __init__(self):
self.fixes = []
self.issue_overview_text = []
self.issue_overview_tag = None
self.issue_overview_hit = False
self.fix_tag = None
self.fix_hit = False
self.arch_hit = False
Expand All @@ -221,6 +227,9 @@ def handle_starttag(self, tag, attrs):
# print('Encountered element with ID new_packages, start tag: {}'.format(tag))
self.fix_hit = True
self.fix_tag = tag
if tag == "div" and ("id", "issue_overview") in attrs:
self.issue_overview_hit = True
self.issue_overview_tag = tag
# else:
# print('Ignoring start tag: {}'.format(tag))

Expand All @@ -229,6 +238,8 @@ def handle_endtag(self, tag):
# print('Encountered end tag for element with ID new_packages')
self.fix_hit = False
self.arch_hit = False
if self.issue_overview_hit and self.issue_overview_tag == tag:
self.issue_overview_hit = False
# else:
# print('Ignoring end tag: {}'.format(tag))

Expand All @@ -247,18 +258,20 @@ def handle_data(self, data):
# print('Found relevant package: {}'.format(data))
self.fixes.append(data)

if self.issue_overview_hit and data and not data.__contains__("Issue Overview:"):
self.issue_overview_text.append(data)
# else:
# print('Ignoring data: {}'.format(data.strip()))


def map_to_vulnerability(version, alas, fixed_in):
def map_to_vulnerability(version, alas, fixed_in, description):
if not alas:
raise ValueError("Invalid reference to AlasSummary")

v = Vulnerability()
v.Name = alas.id
v.NamespaceName = namespace + ":" + version
v.Description = ""
v.Description = description
v.Severity = severity_map.get(alas.sev, "Unknown")
v.Metadata = {
"CVE": [],
Expand Down
1 change: 1 addition & 0 deletions tests/unit/providers/amazon/test_amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_html_parsing(self, helpers):

assert p.fixes is not None
assert new_packages == p.fixes
assert p.issue_overview_text is not None
# TODO: beef up these assertions (should cover the full data shape)

def test_get_pkg_name_version(self):
Expand Down