Repository navigation
refactor(api): refactor purl API query code - #2900
Conversation
andrewpollock
left a comment
There was a problem hiding this comment.
Nice simplification!
There was a problem hiding this comment.
very nice! Is there a way we can do some kind of testing to make sure we're not introducing any regressions on matching behaviour?
i.e. some kind of comprehensive comparison between test (with this deployed) and prod (without this deployed) for specific ecosystems?
We have integration tests for the API (LONG_TESTS), which I have manually checked. These tests do not produce any 500 errors. Also, after checking in the test instance, it will be tested by performance testing, and I will monitor for any new 500 errors. I think this change should be safe. |
|
Merge it now to allow for some bake time on the test instance. |
The [OSV spec](https://ossf.github.io/osv-schema/#affectedpackage-field) requires Alpine packages to have a `:v<RELEASE-NUMBER>` suffix. Currently, our API has inconsistencies regarding Alpine queries: - It returns a 400 status code with the error message "Invalid ecosystem" for all Alpine package/ecosystem queries without a release number. - However, for Alpine PURL queries (e.g. `pkg:apk/alpine/postgresql14?arch=source`), it returns all matching vulnerabilities across all releases. Also we recently switched our PURL query from PURL string matching to package/ecosystem matching (#2900). This change causes all Alpine-related PURL API queries to fail because PURL string doesn't contain any release info and the PURL spec doesn't define how to include release numbers. Since OSV-generated Alpine PURLs (e.g. `pkg:apk/alpine/postgresql14?arch=source`) don't contain release numbers, we should allow Alpine queries without a release number for consistency. This change would return all matching vulnerabilities across different releases when no release number is specified.
We didn't have any PURL ecosystem validation until [PR 2900](#2900) was merged. [PR 2900](#2900) introduced some [breaking changes](#2960 (comment)) that affect users querying ecosystems for which we currently lack a PURL converter, especially those not specified in the PURL specification. This PR changes the response from a 400 error code to a 200 status code with an empty response unblock users. A more considered design will be discussed later with the team and implemented.
Converted PURL queries to package queries in
do_query()to remove unnecessary code. Querying the Datastore directly with PURLs gives the same results as querying by package name, so we can simplify things by treating PURLs like regular package queries after extracting thepackage/ecosystem/version.This will also resolve issue #2842 by rewriting the PURL-to-ecosystem logic. For most ecosystems, we can get the name from
purl.type, but for Linux distributions, we need to usepurl.namespace.