Skip to content

fix(trivy): prevent import crash on legacy reports with missing Class field#15006

Open
stevewallone wants to merge 1 commit into
DefectDojo:devfrom
stevewallone:fix/trivy-none-tag-import-crash
Open

fix(trivy): prevent import crash on legacy reports with missing Class field#15006
stevewallone wants to merge 1 commit into
DefectDojo:devfrom
stevewallone:fix/trivy-none-tag-import-crash

Conversation

@stevewallone

Copy link
Copy Markdown

Description

Fixes #15005. Importing a legacy-format Trivy report that has no Class field crashes the import pipeline after parsing succeeds, with TypeError: expected string or bytes-like object, got 'NoneType' in clean_tags. The parser set unsaved_tags entries to None (e.g. ['debian', None]); clean_tags then ran TAG_PATTERN.sub("_", None) and raised, aborting the whole import.

Two-part fix:

  • dojo/validators.pyclean_tags now drops None entries instead of crashing. This defends the pipeline against any parser that emits a None tag, not just Trivy.
  • dojo/tools/trivy/parser.py — all four unsaved_tags assignments now filter out falsy values at the source, so legacy reports keep their real tag (debian) and simply omit the missing Class.

Test results

Extended the suite (both run green):

  • unittests/test_validators.py (new) — clean_tags with None entries, mixed, all-None, plus existing string/list/empty/invalid-type behavior.
  • unittests/tools/test_trivy_parser.py — asserts the legacy fixture's findings contain no None tags.

Verified end-to-end on a live 2.59.0 instance: before the fix the import returns HTTP 500 (and leaks 1 partial finding); after, HTTP 201 with all 93 findings (0 Critical / 18 High / 9 Medium / 65 Low / 1 Info), each tagged debian.

Documentation

None needed — bug fix, no behavior/config/model surface change.

Checklist

  • Rebased against the very latest dev.
  • Submitted against dev (a bug fix; CONTRIBUTING.md permits dev or bugfix).
  • Meaningful PR name (usable in release notes).
  • Ruff compliant (ruff.toml).
  • Python 3.13 compliant.
  • Not a new feature — no docs required.
  • No model changes — no migrations.
  • Tests added.
  • Label bugfix — I can't set labels as an external contributor; please apply on triage.

Targeted dev per CONTRIBUTING.md; happy to retarget to bugfix if you'd prefer it in a patch release.

Trivy legacy-format reports have no "Class" field, so the parser set
unsaved_tags entries to None (e.g. ['debian', None]). clean_tags then
crashed the whole import with TypeError in TAG_PATTERN.sub, after
parsing had already succeeded (regression from DefectDojo#14111 in 2.55.0).

- clean_tags: drop None entries instead of crashing (defends every parser)
- trivy parser: filter falsy values at all four unsaved_tags sites
- regression tests: clean_tags None handling; legacy fixture tags contain
  no None

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@valentijnscholten valentijnscholten added this to the 2.59.2 milestone Jun 14, 2026
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