Skip to content

Fix crash bugs in Aqua and Snyk parsers caused by None field concatenation - #16021

Open
Jaimin2687 wants to merge 2 commits into
DefectDojo:bugfixfrom
Jaimin2687:fix/aqua-snyk-none-crash
Open

Jaimin2687 wants to merge 2 commits into
DefectDojo:bugfixfrom
Jaimin2687:fix/aqua-snyk-none-crash

Conversation

@Jaimin2687

Copy link
Copy Markdown
Contributor

Description

The Aqua and Snyk parsers crash with TypeError when processing scan reports that contain null or missing fields in their JSON output.

Aqua parser — three independent crash paths:

  • apiv2 path (get_findings): When a result item has "resource": null, accessing resource.get("cpe") raises AttributeError. When resource exists but cpe is absent, None + "string" raises TypeError.
  • apiv1 path (get_findings): When a CVE entry is missing the file or name field, the unique_key concatenation crashes with TypeError.
  • CICD path (vulnerability_tree): Same None concatenation pattern on resource.get("cpe") and related fields.

Snyk parser — one crash path:

  • When the identifiers field is present in the vulnerability JSON but set to null instead of a dict, the expression "CVE" in vulnerability["identifiers"] raises TypeError because the in operator cannot iterate over None.

All four crash paths cause the entire scan import to fail with zero findings recorded.

Root Cause

The parsers used dict.get() which correctly returns None for missing keys, but then fed that None directly into string concatenation (+ operator) or membership tests (in operator) without guarding against it.

Fix

  • Guard resource references with or {} so that a null resource object falls back to an empty dict instead of raising AttributeError.
  • Guard individual field lookups with or "" so that missing fields fall back to empty strings instead of raising TypeError on concatenation.
  • Extract the Snyk identifiers dict via .get() or {} so that a null value 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 with null resource and missing cpe
  • test_aqua_parser_api_v1_with_missing_fields — apiv1 report with missing file and null name
  • test_aqua_parser_cicd_with_missing_resource_fields — CICD report with null resource in vulnerability tree

Snyk:

  • test_snykParser_null_identifiers — report with "identifiers": null and "identifiers": {}

All existing parser tests continue to pass. Ruff clean.

Checklist

  • Submitted against bugfix branch
  • Ruff compliant
  • Python 3.13 compliant
  • Unit tests added
  • No model changes, no migrations needed
  • No documentation changes needed

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants