Return None for signed values with a non-decimal timestamp - #3714
Open
ShamikOfficial wants to merge 1 commit into
Open
Return None for signed values with a non-decimal timestamp#3714ShamikOfficial wants to merge 1 commit into
ShamikOfficial wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3701
decode_signed_valueraisesValueErrorwhen a v1 or v2 signed value has a syntactically malformed (non-decimal) timestamp, even after the HMAC signature has verified.RequestHandler.get_signed_cookiedocuments that invalid signed values returnNone, 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_v1and_decode_signed_value_v2and returnNoneonValueError, consistent with the other rejection paths in those functions.Test
Added
test_malformed_timestamp_v1andtest_malformed_timestamp_v2, which build correctly signed values with non-decimal timestamps and assert they decode toNone. The fullSignedValueTestsuite passes (12 tests).