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

dependencies: enhance CVE and version links. #13434

Merged
merged 1 commit into from
Oct 8, 2020
Merged
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
42 changes: 40 additions & 2 deletions docs/generate_external_dep_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def RstLink(text, url):
# NIST CPE database search URL for a given CPE.
def NistCpeUrl(cpe):
encoded_cpe = urllib.parse.quote(cpe)
return 'https://nvd.nist.gov/products/cpe/search/results?keyword=%s&status=FINAL&orderBy=CPEURI&namingFormat=2.3' % encoded_cpe
return f'https://nvd.nist.gov/vuln/search/results?form_type=Advanced&results_type=overview&query={encoded_cpe}&search_type=all'


# Render version strings human readable.
Expand All @@ -57,6 +57,44 @@ def RenderTitle(title):
return f'\n{title}\n{underline}\n\n'


# Determine the version link URL. If it's GitHub, use some heuristics to figure
# out a release tag link, otherwise point to the GitHub tree at the respective
# SHA. Otherwise, return the tarball download.
def GetVersionUrl(metadata):
# Figure out if it's a GitHub repo.
github_repo = None
github_version = None
for url in metadata['urls']:
if url.startswith('https://github.com/'):
components = url.split('/')
github_repo = f'https://github.com/{components[3]}/{components[4]}'
if components[5] == 'archive':
# Only support .tar.gz, .zip today. Figure out the release tag from this
# filename.
if components[6].endswith('.tar.gz'):
github_version = components[6][:-len('.tar.gz')]
else:
assert (components[6].endswith('.zip'))
github_version = components[6][:-len('.zip')]
else:
# Release tag is a path component.
assert (components[5] == 'releases')
github_version = components[7]
break
# If not, direct download link for tarball
download_url = metadata['urls'][0]
if not github_repo:
return download_url
# If it's not a GH hash, it's a tagged release.
tagged_release = len(metadata['version']) != 40
if tagged_release:
# The GitHub version should look like the metadata version, but might have
# something like a "v" prefix.
return f'{github_repo}/releases/tag/{github_version}'
assert (metadata['version'] == github_version)
return f'{github_repo}/tree/{github_version}'


if __name__ == '__main__':
security_rst_root = sys.argv[1]

Expand All @@ -72,7 +110,7 @@ def RenderTitle(title):
project_name = v['project_name']
project_url = v['project_url']
name = RstLink(project_name, project_url)
version = RstLink(RenderVersion(v['version']), v['urls'][0])
version = RstLink(RenderVersion(v['version']), GetVersionUrl(v))
last_updated = v['last_updated']
dep = Dep(name, project_name.lower(), version, cpe, last_updated)
for category in v['use_category']:
Expand Down