Skip to content

Commit

Permalink
Merge pull request #296 from alanhamlett/main
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Mar 9, 2022
2 parents 3b76264 + 177196d commit 25494a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -3,6 +3,8 @@ Version 2.1.1

Unreleased

- Handle date overflow in timed unsign. :pr:`296`


Version 2.1.0
-------------
Expand Down
8 changes: 7 additions & 1 deletion src/itsdangerous/timed.py
Expand Up @@ -124,7 +124,13 @@ def unsign(
# split the value and the timestamp.
if sig_error is not None:
if ts_int is not None:
ts_dt = self.timestamp_to_datetime(ts_int)
try:
ts_dt = self.timestamp_to_datetime(ts_int)
except (ValueError, OSError) as exc:
# Windows raises OSError
raise BadTimeSignature(
"Malformed timestamp", payload=value
) from exc

raise BadTimeSignature(str(sig_error), payload=value, date_signed=ts_dt)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_itsdangerous/test_timed.py
Expand Up @@ -66,6 +66,15 @@ def test_malformed_timestamp(self, signer):
assert "Malformed" in str(exc_info.value)
assert exc_info.value.date_signed is None

def test_malformed_future_timestamp(self, signer):
signed = b"value.TgPVoaGhoQ.AGBfQ6G6cr07byTRt0zAdPljHOY"

with pytest.raises(BadTimeSignature) as exc_info:
signer.unsign(signed)

assert "Malformed" in str(exc_info.value)
assert exc_info.value.date_signed is None

def test_future_age(self, signer):
signed = signer.sign("value")

Expand Down

0 comments on commit 25494a8

Please sign in to comment.