Skip to content

Throw TruepicWebhookVerifierError for malformed signatures#36

Merged
jstayton merged 1 commit intodevelopmentfrom
fix/signature-length-check
May 7, 2026
Merged

Throw TruepicWebhookVerifierError for malformed signatures#36
jstayton merged 1 commit intodevelopmentfrom
fix/signature-length-check

Conversation

@jstayton
Copy link
Copy Markdown
Collaborator

@jstayton jstayton commented May 7, 2026

Summary

  • timingSafeEqual throws RangeError when its inputs differ in length, so any signature that didn't base64-decode to 32 bytes (e.g. s=Zm9v, garbage, truncated) leaked a RangeError out of the verifier instead of the documented TruepicWebhookVerifierError. Pre-empt the length check so the public contract holds.
  • Drop the redundant digest('base64')Buffer.from(…, 'base64') round-trip in favor of digest() returning raw bytes directly.
  • Add a regression test covering the malformed-signature case.

Test plan

  • npm test — 15/15 pass, including the new if the header signature decodes to the wrong length case.
  • npm run lint — clean.

🤖 Generated with Claude Code

`timingSafeEqual` throws `RangeError` when the buffers differ in
length, so any signature that didn't base64-decode to 32 bytes was
leaking out of the verifier instead of surfacing as the documented
`TruepicWebhookVerifierError`. Pre-empt the length check so the
public contract holds.

Also drop the redundant base64 round-trip in favor of `digest()`
returning raw bytes directly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jstayton jstayton merged commit cd02ec3 into development May 7, 2026
3 of 4 checks passed
@jstayton jstayton deleted the fix/signature-length-check branch May 7, 2026 15:53
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