Skip to content

Commit c21f9e6

Browse files
authored
fix(api): skip alpine/ubuntu on new api, check vuln ID length (#4008)
- Repeated #3980 for the new API matching logic - Added a length check to GetVulnById to avoid 500 errors from Datastore
1 parent 2718b40 commit c21f9e6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

gcp/api/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ class OSVServicer(osv_service_v1_pb2_grpc.OSVServicer,
167167
@ndb.synctasklet
168168
def GetVulnById(self, request, context: grpc.ServicerContext):
169169
"""Return a `Vulnerability` object for a given OSV ID."""
170+
# Datastore has a limit of how large indexed properties can be (<=1500B).
171+
# Vulnerability IDs aren't going to be that long.
172+
if len(request.id) > 100:
173+
context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'ID too long')
174+
return None
170175

171176
if get_gcp_project() in ('oss-vdb-test', 'test-osv'):
172177
# Get vuln from GCS

gcp/api/server_new.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ def _match_versions(version: str, affected: osv.AffectedVersions) -> bool:
161161

162162
def _match_events(version: str, affected: osv.AffectedVersions) -> bool:
163163
"""Check if the given version matches in the AffectedVersions' events list."""
164+
# TODO(michaelkedar): We don't support grabbing the release number from PURLs
165+
# https://github.com/google/osv.dev/issues/3126
166+
# This causes many false positive matches in Ubuntu and Alpine in particular
167+
# when doing range-based matching.
168+
# We have version enumeration for Alpine, and Ubuntu provides versions for us.
169+
# Just skip range-based matching if they don't have release numbers for now.
170+
if affected.ecosystem in ('Alpine', 'Ubuntu'):
171+
return False
164172
ecosystem_helper = osv.ecosystems.get(affected.ecosystem)
165173
if ecosystem_helper is None:
166174
# Ecosystem does not support comparisons.

0 commit comments

Comments
 (0)