Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch unhandled ValueError from future timestamp #296

Merged
merged 3 commits into from Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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