Skip to content

Metadata API: Do not store a rejected expires value - #3055

Open
BahaaMattar wants to merge 1 commit into
theupdateframework:developfrom
BahaaMattar:fix/expires-setter-validate-first
Open

BahaaMattar wants to merge 1 commit into
theupdateframework:developfrom
BahaaMattar:fix/expires-setter-validate-first

Conversation

@BahaaMattar

Copy link
Copy Markdown
Contributor

Description of the changes being introduced by the pull request:

The Signed.expires setter normalizes the datetime (drops microseconds, treats a naive value as UTC) and rejects a timezone-aware value that is not UTC with ValueError. It stored the value in self._expires first and checked the timezone afterwards, so a rejected value stayed on the object: after the ValueError, expires returned the non-UTC datetime, and to_dict()/to_bytes() wrote its local time followed by Z (a 12:00+02:00 value is written as 12:00:00Z, two hours later than the real instant).

This builds the normalized value in a local variable, validates it, and assigns self._expires only at the end, so a rejected assignment leaves the object unchanged. Accepted values behave exactly as before, including in Signed.__init__, which uses the same setter.

The new test test_signed_expires_setter_invalid_timezone sets a +02:00 datetime on a Timestamp, expects ValueError, and checks that expires and the serialized expires are unchanged. Without the change it fails on the expires assertion.

Fixes #3054

The Signed.expires setter assigned the new value to self._expires before
checking its timezone. When the value was rejected with ValueError (a
timezone-aware datetime that is not UTC), the object kept the rejected
value: reading expires returned the non-UTC datetime, and to_dict() then
serialized its local time with a "Z" suffix, so the stored expiry was
off by the UTC offset.

Validate first and only assign once the value is known to be valid.

Add a test that a rejected value leaves expires, and the serialized
expiry, unchanged.

Fixes theupdateframework#3054

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Signed.expires setter keeps the value it rejects (non-UTC timezone)

1 participant