Skip to content

Commit

Permalink
Validate the ecosystem used in queries
Browse files Browse the repository at this point in the history
Partially addresses google#892
  • Loading branch information
andrewpollock committed Jul 21, 2023
1 parent edb93e1 commit c9b6bf5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gcp/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@ def determine_version(version_query: osv_service_v1_pb2.VersionQuery,
len(version_query.file_hashes))


@ndb.tasklet
def valid_ecosystems():
"""Return the list of ecosystems considered valid."""
query = osv.Bug.query(project=[osv.Bug.ecosystem], distinct=True)
return [bug.ecosystems[0] for bug in query if bug.ecosystem]


@ndb.tasklet
def do_query(query, context: QueryContext, include_details=True):
"""Do a query."""
Expand All @@ -447,6 +454,10 @@ def do_query(query, context: QueryContext, include_details=True):
ecosystem = ''
purl_str = ''

if ecosystem and ecosystem not in valid_ecosystems():
context.service_context.abort(grpc.StatusCode.INVALID_ARGUMENT,
'Invalid ecosystem.')

purl = None
purl_version = None
if purl_str:
Expand Down

0 comments on commit c9b6bf5

Please sign in to comment.