Skip to content

Preserve Test metadata when reimport fields are omitted - #17054

Open
tayfunozgur13 wants to merge 1 commit into
DefectDojo:devfrom
tayfunozgur13:fix/17053-preserve-reimport-metadata
Open

tayfunozgur13 wants to merge 1 commit into
DefectDojo:devfrom
tayfunozgur13:fix/17053-preserve-reimport-metadata

Conversation

@tayfunozgur13

Copy link
Copy Markdown

Description

Fixes #17053.

Reimporting a scan without optional Test metadata currently clears version, branch_tag, build_id, and commit_hash. ImporterOptions defaults missing values to "", and "".isspace() is false, so BaseImporter.update_test_meta() overwrites existing values. The UI also assigns an empty version before calling the importer.

Require a nonblank value before applying each metadata override, and let the importer handle the UI version update. Partial updates now preserve untouched fields. The shared fix also preserves a parser-provided version on an initial SARIF import; an explicit version still takes precedence.

Multipart empty fields continue to behave as omitted fields. Whitespace-only API values still receive HTTP 400, UI whitespace is still normalized as blank, and nonempty importer values retain their original whitespace. No migrations, dependencies, settings, or API schema changes.

Test results

Added unittests/test_reimport_metadata.py with 30 behavioral tests covering API and UI omission, empty inputs, individual/combined metadata updates, initial imports, SARIF parser versions, and importer normalization. Before the production fix: 19 failures, 0 errors. With only the shared importer fix: 6 remaining UI failures. With both changes: all 30 pass.

Executed through the supported Docker test wrapper:

./run-unittest.sh --test-case 'unittests.test_reimport_metadata unittests.test_importers_importer unittests.test_import_reimport unittests.test_importers_closeold unittests.test_importers_deduplication unittests.test_reimport_prefetch unittests.test_apiv2_scan_import_options unittests.test_import_execution_mode'
# 314 tests, OK (skipped=1)

./run-unittest.sh --test-case 'unittests.test_importers_performance unittests.test_reimport_report_memory unittests.test_reimport_dynamic_test_type_lookup'
# 21 tests, OK; includes endpoint and location performance guards

ruff check --config ruff.toml .
# All checks passed! (pinned Ruff 0.16.10)

docker compose exec -T uwsgi python manage.py makemigrations --check --dry-run
# No changes detected

docker compose exec -T uwsgi python manage.py spectacular --fail-on-warn --file /tmp/issue17053-schema.yml
# Exit 0

Also verified against the running local HTTP API: initial import and three reimports returned HTTP 201; GET requests confirmed that omitted/empty metadata is preserved and a version-only update leaves the other three fields intact.

Runtime: Python 3.14.10 and PostgreSQL 18.6 in the existing development containers. Ruff targets Python 3.13; tests were not separately executed on Python 3.13. Django reports the existing development-key and missing node_modules system warnings.

Documentation

Restores the existing reimport help-text contract. No documentation or API schema change is required.

Checklist

  • Based on current dev and targets dev.
  • Ruff checks pass.
  • Applicable behavioral regression tests added and executed.
  • No model changes or migrations.

@dryrunsecurity

Copy link
Copy Markdown

DryRun Security

This pull request contains a critical finding where a sensitive file in the dojo/importers directory was modified by an unauthorized author.

🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/importers/base_importer.py (drs_99a1fa74)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/importers/base_importer.py' matches configured sensitive codepath pattern 'dojo/importers/*.py' and was modified by 'tayfunozgur13' (commit 8cec035) who is not in the allowed authors list.

We've notified @mtesauro.


Comment to provide feedback on these findings.

Report false positive: @dryrunsecurity fp [FINDING ID] [FEEDBACK]
Report low-impact: @dryrunsecurity nit [FINDING ID] [FEEDBACK]

Example: @dryrunsecurity fp drs_90eda195 This code is not user-facing

All finding details can be found in the DryRun Security Dashboard.

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.

1 participant