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

Create get vulnerability details API #2207

Merged
merged 2 commits into from
Jun 4, 2024

Conversation

ZhangChen199102
Copy link
Collaborator

Issue: #2152

This PR introduces a new GET vulnerability details API

@@ -237,102 +237,6 @@ def vulnerability_redirector(potential_vuln_id):
return None


def bug_to_response(bug, detailed=True):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving these functions to utils.py so they can be used by both of api_handlers and frontend_handlers.

@@ -0,0 +1,47 @@
# Copyright 2021 Google LLC
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a new app for API

@ZhangChen199102 ZhangChen199102 force-pushed the get-vulnerability-data-endpoint branch 3 times, most recently from 985d7d8 to 4c2aee4 Compare May 16, 2024 15:14
@ZhangChen199102 ZhangChen199102 force-pushed the get-vulnerability-data-endpoint branch from 4c2aee4 to 3f12c8a Compare May 22, 2024 04:48
@another-rex another-rex self-requested a review May 28, 2024 03:57
@another-rex
Copy link
Contributor

Unless I'm misunderstanding the goal, rather than putting API code in the frontend as well, I think we can just put a link to the GET API endpoint on the page, or add a new handler to redirect requests ending in .json to the API endpoint.
https://google.github.io/osv.dev/get-v1-vulns/

E.g. https://api.osv.dev/v1/vulns/CVE-2023-45802

@andrewpollock
Copy link
Contributor

or add a new handler to redirect requests ending in .json to the API endpoint.

That was my understanding of the easiest way forward based on #2152 (comment)

@ZhangChen199102 ZhangChen199102 force-pushed the get-vulnerability-data-endpoint branch from 3f12c8a to 7a4ff83 Compare May 31, 2024 09:59
@ZhangChen199102
Copy link
Collaborator Author

So this time I just added a JSON Data field, with a GET vulnerability details link on the vulnerability details page:

image

@andrewpollock
Copy link
Contributor

So this time I just added a JSON Data field

That's cool, but doesn't address the UX intention behind #2152 (as I understand it).

Today, there's a convenience redirect where:
https://OSV.dev/GHSA-75mx-chcf-2q32 redirects to https://osv.dev/vulnerability/GHSA-75mx-chcf-2q32

An additional convenience redirect would be for:
https://OSV.dev/GHSA-75mx-chcf-2q32.json to redirect to https://api.osv.dev/v1/vulns/GHSA-75mx-chcf-2q32

Without having tried this, I think a variation on:

@blueprint.route('/<potential_vuln_id>')
def vulnerability_redirector(potential_vuln_id):
"""Convenience redirector for /VULN-ID to /vulnerability/VULN-ID."""
if not _VALID_VULN_ID.match(potential_vuln_id):
abort(404)
return None
vuln = osv_get_by_id(potential_vuln_id)
if vuln:
return redirect(f'/vulnerability/{potential_vuln_id}')
abort(404)
return None
would accomplish this redirection:

  • support .json in the URL handler
  • if the vulnerability ID exists, redirect to the existing JSON API endpoint, per my example above

@ZhangChen199102 ZhangChen199102 force-pushed the get-vulnerability-data-endpoint branch from 7a4ff83 to 1194af7 Compare June 3, 2024 03:17
@ZhangChen199102 ZhangChen199102 force-pushed the get-vulnerability-data-endpoint branch from 1194af7 to 4070c0c Compare June 3, 2024 03:58
Copy link
Contributor

@andrewpollock andrewpollock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, have you been able to do any testing to confirm it works as intended?
FYI, I wasn't averse to highlighting the availability of the API from the individual vulnerability pages on the website in addition to this. Feel free to reinstate that.

Copy link
Contributor

@another-rex another-rex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! One minor note would be this will always redirect to the production API, even when running on test.osv.dev. Not sure if there's an easy fix for that or not, if not I think that behaviour is fine.

abort(404)
return None

vuln = osv_get_by_id(potential_vuln_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: can you change the if vuln: to if not vuln: to have the final return statement be the redirect, and the if branches be the aborts.

gcp/appengine/frontend_handlers.py Dismissed Show dismissed Hide dismissed
@ZhangChen199102 ZhangChen199102 force-pushed the get-vulnerability-data-endpoint branch from 73cdeb0 to 06f20c3 Compare June 4, 2024 04:41
@ZhangChen199102
Copy link
Collaborator Author

This LGTM, have you been able to do any testing to confirm it works as intended?

Yes, I've tested http://127.0.0.1:8000/vulnerability/GHSA-vw63-824v-qf2j.json and http://127.0.0.1:8000/GHSA-vw63-824v-qf2j.json on local, and both redirects me to https://api.test.osv.dev/v1/vulns/GHSA-vw63-824v-qf2j

@ZhangChen199102
Copy link
Collaborator Author

One minor note would be this will always redirect to the production API, even when running on test.osv.dev. Not sure if there's an easy fix for that or not, if not I think that behaviour is fine.

Thanks, I've updated this and now it will redirect to api.test.osv.dev in local and test environment, and api.osv.dev for prod.

@andrewpollock andrewpollock merged commit 4014062 into google:master Jun 4, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants