Throw TruepicWebhookVerifierError for malformed signatures#36
Merged
jstayton merged 1 commit intodevelopmentfrom May 7, 2026
Merged
Throw TruepicWebhookVerifierError for malformed signatures#36jstayton merged 1 commit intodevelopmentfrom
jstayton merged 1 commit intodevelopmentfrom
Conversation
`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>
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
timingSafeEqualthrowsRangeErrorwhen its inputs differ in length, so any signature that didn't base64-decode to 32 bytes (e.g.s=Zm9v, garbage, truncated) leaked aRangeErrorout of the verifier instead of the documentedTruepicWebhookVerifierError. Pre-empt the length check so the public contract holds.digest('base64')→Buffer.from(…, 'base64')round-trip in favor ofdigest()returning raw bytes directly.Test plan
npm test— 15/15 pass, including the newif the header signature decodes to the wrong lengthcase.npm run lint— clean.🤖 Generated with Claude Code