fix(importers): accept scan severities case-insensitively - #15864
Conversation
Scan imports aborted with a ValidationError when a finding's severity was supplied in the wrong letter case (e.g. a Generic Findings Import carrying "severity": "medium"). BaseImporter.sanitize_severity only case-normalized the Info/Informational/None family and matched every other severity case-sensitively against SEVERITIES, so "medium", "high", "critical" and "low" fell through to the "not supported" error and stopped the whole import. Normalize the severity's case against the supported set before the membership check, mapping a value whose lowercase form matches a supported severity to its canonical spelling. Genuinely unsupported values still raise ValidationError, and the existing Info/None handling is unchanged. Add TestSanitizeSeverity covering the wrong-case inputs, canonical-case controls, the info/none normalization, and rejection of an unsupported value. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DUqP65vyMekyL3ZgTBCkmw
|
CI note: the only red check is This is unrelated to this PR. The change here is confined to Locally against a PostgreSQL test DB, the six wrong-case severity inputs fail before this fix with the exact production I'll re-run the failed job once the workflow finishes (a re-run is currently blocked while the run is still in progress) to confirm the flake clears. Generated by Claude Code |
|
Update: the merge queue dequeued this PR ( This time it failed on the Since the flaky test is outside this PR's scope, I'm not modifying it here (that would widen an importer bugfix into an unrelated test-isolation fix). This PR just needs to be re-queued — the merge-queue check should pass on a clean run, as it did on the PR head. Re-queuing/merging is a maintainer action I can't perform. The underlying flake is worth a separate fix so it stops blocking the queue. Generated by Claude Code |
Description
Scan imports fail with a hard
ValidationErrorwhen a finding's severity is supplied in the wrong letter case — for example a Generic Findings Import whose findings carry"severity": "medium":The whole async import task aborts, so a single lowercase severity value stops the entire report from being ingested.
Root cause
BaseImporter.sanitize_severity(dojo/importers/base_importer.py) only normalized case for theInfo/Informational/Nonefamily. Every other severity was matched case-sensitively againstSEVERITIES(['Info', 'Low', 'Medium', 'High', 'Critical']), so"medium","high","critical"and"low"fell straight through to the "not supported"ValidationError. Several parsers (Generic Findings Import among them) pass a user-provided severity string through untouched, which is how a wrong-case value reaches the sanitizer.Fix
Normalize the severity's case against the supported set before the membership check: a value whose lowercase form matches a supported severity is mapped to the canonical spelling (
"medium"→"Medium"). Genuinely unsupported values still raiseValidationError, and the existingInfo/Nonehandling is unchanged. This makes severity matching consistently case-insensitive, matching the leniency already applied to theInfofamily. No migration — this is pure importer-validation logic.Impact on DefectDojo Pro
sanitize_severityis inherited unchanged by the Pro importers: Pro's importer goes through the OSSprocess_findings/_process_findings_internalpath, and Pro's Smart Upload importer callsself.sanitize_severitydirectly. Neither overrides it, so the fix flows through to Pro's importers and Smart Upload with no Pro-side change and no override to update.Test results
Added
TestSanitizeSeverityinunittests/test_importers_importer.py:medium,MEDIUM,high,HIGH,critical,low) alongside control inputs already in canonical case (Medium,Critical,Info) and the existinginfo/informational/nonenormalization. It asserts both the normalizedseverityand thatnumerical_severityis set correctly.bogus) still raisesValidationError, locking in that the sanitizer stays strict for real garbage.Verified locally against a PostgreSQL test database: the six wrong-case cases fail before the fix with the exact
ValidationErrorabove and pass after; the fulltest_importers_importer.pymodule is green (63 passed, 23 subtests) with no collateral damage.Documentation
No documentation change needed — this restores acceptance of a value users already reasonably expect to work; there is no new setting or user-facing behavior to document.
Checklist
bugfixbranch.🤖 Generated with Claude Code
https://claude.ai/code/session_01DUqP65vyMekyL3ZgTBCkmw
Generated by Claude Code