Fix crash bugs in Aqua and Snyk parsers caused by None field concatenation - #16021
Open
Jaimin2687 wants to merge 2 commits into
Open
Jaimin2687 wants to merge 2 commits into
Jaimin2687 wants to merge 2 commits into
Conversation
…ation The Aqua parser crashes with TypeError when scan reports contain null or missing resource objects, or when fields like cpe, file, or name are absent. This affects all three report format variants (apiv1, apiv2, and CICD). The Snyk parser crashes with TypeError when the identifiers field is present in the JSON report but set to null instead of a dict. Guard all affected code paths with inline fallbacks so that missing or null fields produce empty strings instead of raising exceptions.
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.
Description
The Aqua and Snyk parsers crash with
TypeErrorwhen processing scan reports that containnullor missing fields in their JSON output.Aqua parser — three independent crash paths:
get_findings): When a result item has"resource": null, accessingresource.get("cpe")raisesAttributeError. Whenresourceexists butcpeis absent,None + "string"raisesTypeError.get_findings): When a CVE entry is missing thefileornamefield, theunique_keyconcatenation crashes withTypeError.vulnerability_tree): SameNoneconcatenation pattern onresource.get("cpe")and related fields.Snyk parser — one crash path:
identifiersfield is present in the vulnerability JSON but set tonullinstead of a dict, the expression"CVE" in vulnerability["identifiers"]raisesTypeErrorbecause theinoperator cannot iterate overNone.All four crash paths cause the entire scan import to fail with zero findings recorded.
Root Cause
The parsers used
dict.get()which correctly returnsNonefor missing keys, but then fed thatNonedirectly into string concatenation (+operator) or membership tests (inoperator) without guarding against it.Fix
resourcereferences withor {}so that anullresource object falls back to an empty dict instead of raisingAttributeError.or ""so that missing fields fall back to empty strings instead of raisingTypeErroron concatenation.identifiersdict via.get() or {}so that anullvalue safely resolves to an empty dict.No behavioral change for well-formed scan reports — the fallback values only activate when fields are absent or null.
Test Results
Added 4 new regression tests with dedicated fixtures that reproduce each crash path:
Aqua:
test_aqua_parser_api_v2_with_missing_fields— apiv2 report withnullresource and missingcpetest_aqua_parser_api_v1_with_missing_fields— apiv1 report with missingfileandnullnametest_aqua_parser_cicd_with_missing_resource_fields— CICD report withnullresource in vulnerability treeSnyk:
test_snykParser_null_identifiers— report with"identifiers": nulland"identifiers": {}All existing parser tests continue to pass. Ruff clean.
Checklist
bugfixbranch