Skip to content

Return None for signed values with a non-decimal timestamp - #3714

Open
ShamikOfficial wants to merge 1 commit into
tornadoweb:masterfrom
ShamikOfficial:fix/decode-signed-value-malformed-timestamp
Open

Return None for signed values with a non-decimal timestamp#3714
ShamikOfficial wants to merge 1 commit into
tornadoweb:masterfrom
ShamikOfficial:fix/decode-signed-value-malformed-timestamp

Conversation

@ShamikOfficial

Copy link
Copy Markdown

Fixes #3701

decode_signed_value raises ValueError when a v1 or v2 signed value has a syntactically malformed (non-decimal) timestamp, even after the HMAC signature has verified. RequestHandler.get_signed_cookie documents that invalid signed values return None, so this path should reject rather than raise into request handling.

This is not a signature bypass: producing such an input requires the signing key. A malformed value from a key-holding component (or during key rotation) can still turn into an unhandled exception instead of a clean rejection.

Fix

Wrap the int() conversion in both _decode_signed_value_v1 and _decode_signed_value_v2 and return None on ValueError, consistent with the other rejection paths in those functions.

Test

Added test_malformed_timestamp_v1 and test_malformed_timestamp_v2, which build correctly signed values with non-decimal timestamps and assert they decode to None. The full SignedValueTest suite passes (12 tests).

decode_signed_value raised ValueError from int() in the v1 and v2
decoders when a signed value carried a syntactically malformed
timestamp after HMAC verification. Reject with None instead, matching
get_signed_cookie's documented behavior for invalid cookies.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

decode_signed_value raises ValueError for authenticated malformed timestamps

1 participant