Skip to content

Treat out-of-range timestamps and non-ASCII signatures as invalid - #140

Open
nlathia wants to merge 1 commit into
mainfrom
fix-webhook-timestamp-errors
Open

nlathia wants to merge 1 commit into
mainfrom
fix-webhook-timestamp-errors

Conversation

@nlathia

@nlathia nlathia commented Nov 13, 2026

Copy link
Copy Markdown
Member

Problem

Webhook.parse_event is documented to raise SignatureVerificationError for bad signatures, but some malformed headers escaped as other exceptions:

  • t=253402300800,... -> ValueError (year 10000)
  • t=10**30,... -> OverflowError; negative out-of-range -> ValueError
  • non-ASCII v1= value -> TypeError from hmac.compare_digest

Callers catching only SignatureVerificationError could return a 500 instead of rejecting the request. No auth bypass; this is hardening.

Change

  • Convert the timestamp inside the existing try in parse_signature_header, before any HMAC work.
  • Catch TypeError from the signature comparison.
  • Both return WebhookSignature(valid=False, timestamp=None).

Tests

Added parametrized tests for parse_signature_header and parse_event covering all four cases. uv run pytest tests: 36 passed.

🤖 Generated with Claude Code

…on-ASCII signatures

parse_signature_header converted the timestamp to a datetime outside its
try/except, so out-of-range timestamps raised ValueError/OverflowError, and
non-ASCII signatures raised TypeError from hmac.compare_digest. Treat all of
these as invalid signatures.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@nlathia
nlathia requested review from a team and stevewithey November 13, 2026 22:56
@nlathia
nlathia enabled auto-merge (squash) November 13, 2026 22:57
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.

1 participant