Skip to content

Commit 4014062

Browse files
Create get vulnerability details API (#2207)
Issue: #2152 This PR introduces a new GET vulnerability details API
1 parent f3ad15e commit 4014062

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

gcp/appengine/frontend3/src/templates/vulnerability.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ <h1 class="title">
3434
<dt>Import Source</dt>
3535
<dd><a href="{{ vulnerability.source_link }}" target="_blank" rel="noopener noreferrer">{{
3636
vulnerability.source }}</a></dd>
37+
38+
<dt>JSON Data</dt>
39+
<dd><a href="https://{{ api_url }}/v1/vulns/{{ vulnerability.id }}" target="_blank" rel="noopener noreferrer">
40+
https://{{ api_url }}/v1/vulns/{{ vulnerability.id }}</a>
41+
</dd>
3742
{% if vulnerability.aliases -%}
3843
<dt>Aliases</dt>
3944
<dd>

gcp/appengine/frontend_handlers.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,14 @@ def list_vulnerabilities():
224224
def vulnerability(vuln_id):
225225
"""Vulnerability page."""
226226
vuln = osv_get_by_id(vuln_id)
227-
return render_template('vulnerability.html', vulnerability=vuln)
227+
228+
if utils.is_prod():
229+
api_url = 'api.osv.dev'
230+
else:
231+
api_url = 'api.test.osv.dev'
232+
233+
return render_template(
234+
'vulnerability.html', vulnerability=vuln, api_url=api_url)
228235

229236

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

244251

252+
@blueprint.route('/<potential_vuln_id>.json')
253+
@blueprint.route('/vulnerability/<potential_vuln_id>.json')
254+
def vulnerability_json_redirector(potential_vuln_id):
255+
"""Convenience redirector for /VULN-ID.json and /vulnerability/VULN-ID.json to
256+
https://api.osv.dev/v1/vulns/VULN-ID.
257+
"""
258+
if not _VALID_VULN_ID.match(potential_vuln_id):
259+
abort(404)
260+
return None
261+
262+
vuln = osv_get_by_id(potential_vuln_id)
263+
if not vuln:
264+
abort(404)
265+
return None
266+
267+
if utils.is_prod():
268+
api_url = 'api.osv.dev'
269+
else:
270+
api_url = 'api.test.osv.dev'
271+
return redirect(f'https://{api_url}/v1/vulns/{potential_vuln_id}')
272+
273+
245274
def bug_to_response(bug, detailed=True):
246275
"""Convert a Bug entity to a response object."""
247276
response = osv.vulnerability_to_dict(

0 commit comments

Comments
 (0)