Skip to content

Fix webhook toleranceSeconds unit mismatch - #142

Merged
luismeli10 (luismeli10) merged 1 commit into
masterfrom
fix/webhook-validator-bugs
Aug 4, 2026
Merged

Fix webhook toleranceSeconds unit mismatch#142
luismeli10 (luismeli10) merged 1 commit into
masterfrom
fix/webhook-validator-bugs

Conversation

@luismeli10

Copy link
Copy Markdown
Contributor

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

  • Existing tolerance tests updated to use seconds-based timestamps
  • New regression test: sign with `ts` in seconds + `toleranceSeconds=3600` → accepted
  • New regression test (Node.js): multibyte v1 → `InvalidWebhookSignatureError`, not `RangeError`
  • All existing tests pass

Closes #458, Closes #459

🤖 Generated with Claude Code

The ts value from the x-signature header is in seconds; now() returns
milliseconds. Multiply ts by 1000 before computing drift to avoid false
TIMESTAMP_OUT_OF_TOLERANCE rejections. Update existing tolerance tests
and add a new test that signs with a seconds-based timestamp and asserts
it passes with tolerance_seconds=3600.
@luismeli10
luismeli10 (luismeli10) merged commit 1fa79b7 into master Aug 4, 2026
3 checks passed
@luismeli10
luismeli10 (luismeli10) deleted the fix/webhook-validator-bugs branch August 4, 2026 19:48
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.

2 participants