Skip to content

dsse: Raise DeserializationError for invalid payload content - #3049

Merged
jku merged 1 commit into
theupdateframework:developfrom
BahaaMattar:fix/dsse-get-signed-deserialization-error
Nov 19, 2026
Merged

jku merged 1 commit into
theupdateframework:developfrom
BahaaMattar:fix/dsse-get-signed-deserialization-error

Conversation

@BahaaMattar

Copy link
Copy Markdown
Contributor

Description of the changes being introduced by the pull request:

SimpleEnvelope.get_signed() documents that it raises DeserializationError if the payload cannot be deserialized. Only the JSON decoding and the role type lookup were inside the try block: the Signed.from_dict() call was outside of it. So a payload with a known role type but invalid content (a missing field, a wrong type, a bad date) leaked KeyError, TypeError or ValueError.

This also reached ngclient: with EnvelopeType.SIMPLE, a malformed root given to Updater() or TrustedMetadataSet() (which loads the bootstrap root without a delegator, so get_signed() is the first thing that parses it) raised e.g. KeyError instead of a RepositoryError.

The change moves the from_dict() call into the try block, so every failure becomes a DeserializationError (a RepositoryError), like Metadata.from_bytes() / JSONDeserializer already do.

test_fail_invalid_payload_content_deserialization (new, in TestSimpleEnvelope) checks four invalid payloads (missing fields, wrong type, version: 0, bad date) and that the same envelope with valid content still deserializes. It fails on current develop (4 errors: KeyError, TypeError, ValueError, ValueError) and passes with the change.

Locally: the full unittest suite (207 tests) passes, coverage report --fail-under 97 passes, ruff check, ruff format --diff and mypy are clean on the changed files.

Fixes #3048

SimpleEnvelope.get_signed() documents that it raises
DeserializationError if the payload cannot be deserialized, but
only the JSON decoding and the role type lookup were inside the
try block: the call to from_dict() was outside of it. A payload
with a known role type but invalid content (for example missing
fields) leaked KeyError, TypeError or ValueError instead.

With EnvelopeType.SIMPLE this also reached ngclient: a malformed
root passed to Updater() or TrustedMetadataSet() raised e.g.
KeyError instead of a RepositoryError.

Move the from_dict() call into the try block and add a test.

Fixes theupdateframework#3048

Signed-off-by: Bahaa Mattar <bahaa.kmattar@gmail.com>
@BahaaMattar
BahaaMattar requested a review from a team as a code owner November 19, 2026 07:13

@jku jku left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks sensible. Thank you

@jku
jku enabled auto-merge November 19, 2026 17:05
@jku
jku merged commit 668de5e into theupdateframework:develop Nov 19, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SimpleEnvelope.get_signed() raises KeyError/TypeError/ValueError instead of DeserializationError

2 participants