Skip to content

Validate the request body on a finding metadata PUT - #15785

Open
svader0 wants to merge 1 commit into
DefectDojo:bugfixfrom
svader0:validate-finding-metadata-edit
Open

Validate the request body on a finding metadata PUT#15785
svader0 wants to merge 1 commit into
DefectDojo:bugfixfrom
svader0:validate-finding-metadata-edit

Conversation

@svader0

@svader0 svader0 commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Description

_edit_metadata handles the PUT on /api/v2/findings/{id}/metadata/. It declares FindingMetaSerializer in its schema. It never builds that serializer. It reads name and value off request.data and writes them straight into update_or_create.

Two things go wrong:

  • If a client sends a value longer than 300 characters, Postgres raises DataError. The except IntegrityError below does not catch DataError. The caller gets a 500.
  • If a client omits name, the code writes NULL. The caller gets a 400, but the message says "Update failed because the new name already exists". That message is wrong.

_add_metadata sits directly below and handles the POST. It already validates the same body with the same serializer. This change makes the PUT branch do the same.

One other change: the 200 response now returns the serialized name and value. Before, it echoed the raw request body.

Test results

I added two tests to FindingMetadataTest in unittests/test_rest_framework.py. I ran the class both ways.

Result
With the fix Ran 22 tests ... OK (skipped=10)
Without the fix FAILED (failures=2, skipped=10)

The unfixed run shows the bug:

django.db.utils.DataError: value too long for type character varying(300)
AssertionError: 400 != 500

Ruff 0.16.0 passes.

Documentation

No documentation change. The endpoint contract stays the same. The declared schema already promised this validation.

Checklist

  • Bugfix, submitted against bugfix.
  • Code is Ruff compliant.
  • Tests added to the unit tests.
  • No model change, so no migration.
  • No new settings.

_edit_metadata declared FindingMetaSerializer in its schema. It never built
the serializer. It read name and value off request.data and wrote them
straight into update_or_create.

A value longer than 300 characters reached the column and raised DataError.
The except IntegrityError below does not catch DataError, so the caller got
a 500 instead of a 400. A missing name wrote NULL and returned the wrong
error message.

_add_metadata directly below already validates the same body with the same
serializer. The PUT branch now does the same. The response carries the
serialized name and value instead of the raw request body.
@svader0 svader0 added this to the 3.2.400 milestone Aug 24, 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.

1 participant