Fix webhook toleranceSeconds unit mismatch - #393
Merged
Conversation
The ts value in the x-signature header is Unix time in seconds, but the tolerance check was comparing it directly against Instant.toEpochMilli(), causing valid webhooks with recent timestamps to be rejected as out of tolerance. Multiply ts by 1000 to convert to milliseconds before the comparison. Updated existing tolerance tests to use getEpochSecond() consistently and added a dedicated test covering the seconds-based path.
Diego Barajas (barajas-d)
approved these changes
Aug 3, 2026
2 tasks
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.
Summary
Fixes two bugs in WebhookSignatureValidator reported in issues #458 and #459:
Bug #458 — toleranceSeconds comparing seconds against milliseconds
The `ts` value in the `x-signature` header is in seconds (e.g. `1704908010`), but the clock was read in milliseconds. This made any `toleranceSeconds` value effectively reject every legitimate webhook notification.
Fix: Convert `ts` to milliseconds before computing drift.
Bug #459 — RangeError on multibyte v1 hash (Node.js only)
`constantTimeEquals` compared string `length` (characters) but `Buffer.from()` operates on bytes. A 64-character v1 with one multibyte character has 65 bytes, passing the guard and throwing `RangeError` instead of `InvalidWebhookSignatureError`.
Fix: Use `Buffer.byteLength()` in the length guard.
Test plan
Closes #458, Closes #459
🤖 Generated with Claude Code