fix(webhook): decode request body to string to avoid Buffer in Deno#199
Open
matingathani wants to merge 1 commit intostripe:mainfrom
Open
fix(webhook): decode request body to string to avoid Buffer in Deno#199matingathani wants to merge 1 commit intostripe:mainfrom
matingathani wants to merge 1 commit intostripe:mainfrom
Conversation
The Stripe SDK internally calls Buffer.isBuffer() when processing the webhook payload. Buffer is a Node.js global that does not exist in the Deno edge function runtime, which causes a ReferenceError. Decoding the raw ArrayBuffer to a UTF-8 string before passing it to processWebhook avoids the Buffer check entirely, since the SDK only performs the Buffer-specific code path for Buffer instances. Closes stripe#170
There was a problem hiding this comment.
Pull request overview
Updates the Supabase (Deno) edge webhook handler to avoid a runtime crash caused by the Stripe SDK referencing the Node.js-only Buffer global during webhook signature verification.
Changes:
- Read the webhook body as an
ArrayBufferand decode it to a UTF-8 string. - Pass the decoded string payload into
stripeSync.webhook.processWebhook(...)instead of aUint8Array.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
The Stripe SDK calls
Buffer.isBuffer()internally when processing the webhook payload.Bufferis a Node.js global that doesn't exist in the Deno edge function runtime, causing:Root cause:
stripe-webhook.tspassed aUint8ArraytoprocessWebhook, which forwarded it to the Stripe SDK'sconstructEventAsync. The SDK's internal signature computation checksBuffer.isBuffer(payload)— in Deno that throws instead of returningfalse.Fix: Decode the
ArrayBufferto a UTF-8 string before callingprocessWebhook. The Stripe signature verification works correctly on strings, and thestringcode path in the SDK never referencesBuffer.Test plan
{ received: true }response with noBuffer is not definederrorCloses #170