Skip to content

Commit

Permalink
Create get vulnerability details API (#2207)
Browse files Browse the repository at this point in the history
Issue: #2152 

This PR introduces a new GET vulnerability details API
  • Loading branch information
ZhangChen199102 authored Jun 4, 2024
1 parent f3ad15e commit 4014062
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions gcp/appengine/frontend3/src/templates/vulnerability.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ <h1 class="title">
<dt>Import Source</dt>
<dd><a href="{{ vulnerability.source_link }}" target="_blank" rel="noopener noreferrer">{{
vulnerability.source }}</a></dd>

<dt>JSON Data</dt>
<dd><a href="https://{{ api_url }}/v1/vulns/{{ vulnerability.id }}" target="_blank" rel="noopener noreferrer">
https://{{ api_url }}/v1/vulns/{{ vulnerability.id }}</a>
</dd>
{% if vulnerability.aliases -%}
<dt>Aliases</dt>
<dd>
Expand Down
31 changes: 30 additions & 1 deletion gcp/appengine/frontend_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,14 @@ def list_vulnerabilities():
def vulnerability(vuln_id):
"""Vulnerability page."""
vuln = osv_get_by_id(vuln_id)
return render_template('vulnerability.html', vulnerability=vuln)

if utils.is_prod():
api_url = 'api.osv.dev'
else:
api_url = 'api.test.osv.dev'

return render_template(
'vulnerability.html', vulnerability=vuln, api_url=api_url)


@blueprint.route('/<potential_vuln_id>')
Expand All @@ -242,6 +249,28 @@ def vulnerability_redirector(potential_vuln_id):
return None


@blueprint.route('/<potential_vuln_id>.json')
@blueprint.route('/vulnerability/<potential_vuln_id>.json')
def vulnerability_json_redirector(potential_vuln_id):
"""Convenience redirector for /VULN-ID.json and /vulnerability/VULN-ID.json to
https://api.osv.dev/v1/vulns/VULN-ID.
"""
if not _VALID_VULN_ID.match(potential_vuln_id):
abort(404)
return None

vuln = osv_get_by_id(potential_vuln_id)
if not vuln:
abort(404)
return None

if utils.is_prod():
api_url = 'api.osv.dev'
else:
api_url = 'api.test.osv.dev'
return redirect(f'https://{api_url}/v1/vulns/{potential_vuln_id}')


def bug_to_response(bug, detailed=True):
"""Convert a Bug entity to a response object."""
response = osv.vulnerability_to_dict(
Expand Down

0 comments on commit 4014062

Please sign in to comment.