Repository navigation
fix(api_v3): validate PURLs in packages and advisories query serializers - #2468
Open
shubhamrai9122-creator wants to merge 1 commit into
Open
shubhamrai9122-creator wants to merge 1 commit into
shubhamrai9122-creator wants to merge 1 commit into
Conversation
In api_v3, passing malformed or invalid Package URLs to POST /api/v3/packages or POST /api/v3/advisories either causes an unhandled ValueError (500 Internal Server Error) when details/ignore_qualifiers_subpath is set, or silently returns empty results. Add validate_purls validation methods to both PackageQuerySerializer and AdvisoryQuerySerializer using PackageURL.from_string, ensuring consistent HTTP 400 Bad Request responses with descriptive validation error messages for malformed PURLs across all v3 query endpoints. Add test cases in test_api_v3 covering invalid PURL submissions for both endpoints. Signed-off-by: Shubham Rai <shubhamrai9122@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In API v3 (
POST /api/v3/packagesandPOST /api/v3/advisories), passing malformed or invalid Package URLs (PURLs) causes either:ValueErrorfromPackageURL.from_stringresulting in an HTTP 500 Internal Server Error whenignore_qualifiers_subpathor detailed package processing is enabled.Changes
validate_purls()validator toPackageQuerySerializerto ensure all elements inpurlsare valid Package URLs according to thepackageurlspecification, raisingserializers.ValidationErroron malformed inputs.validate_purls()validator toAdvisoryQuerySerializerensuring consistent behavior and validation across the v3 API endpoints.vulnerabilities/tests/test_api_v3.py(test_packages_post_with_invalid_purlandtest_advisories_post_with_invalid_purl) verifying that HTTP 400 with descriptive error details is returned for malformed PURLs.Builds upon and completes the API validation improvements proposed in #2466.