Repository navigation
fix(plugin-ecommerce): use constructEventAsync for Stripe webhook verification (Workers/edge runtimes) - #18125
Closed
LuigiNicaPRO wants to merge 1 commit into
Conversation
…tEventAsync
The Stripe webhooks endpoint verified the signature with the synchronous
stripe.webhooks.constructEvent(). On Workers runtimes (workerd) the Stripe SDK
selects SubtleCryptoProvider, whose HMAC is async-only, so the call throws
"SubtleCryptoProvider cannot be used in a synchronous context" before any
registered handler runs. The catch sets returnStatus = 400 while the body still
reads {"received": true}, so every webhook is rejected while looking healthy.
The handler is already async and the call already sits inside the try, so the
awaited form lands a rejected promise in the same 400 branch.
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.
What?
One line in the Stripe adapter's webhooks endpoint:
Why?
webhooksEndpointverifies the Stripe signature with the synchronousstripe.webhooks.constructEvent(...). On Workers runtimes (workerd) the Stripe SDK selectsSubtleCryptoProvider, whose HMAC is async-only, so the call throws before any handler runs:The catch block sets
returnStatus = 400, but the response body is still{"received": true}. So onWorkers every Stripe webhook is rejected while looking superficially healthy: Stripe retries, then
gives up, and no registered
webhooks[event.type]handler ever fires. A paid order is never confirmed.How?
The handler is already
asyncand the call already sits inside thetry, so the fix is one line anda rejected promise still lands in the same 400 branch. No signature, type, or control-flow change.
Measured
Against
@payloadcms/[email protected]on a built OpenNext/Cloudflare Worker(
opennextjs-cloudflare build+wrangler dev, local D1), with[email protected]resolved through itsworkerdexport condition, and a real Stripe test key. Apayment_intent.succeededbody wassigned in Node with
stripe.webhooks.generateTestHeaderString({ payload, secret })and the identicalbytes POSTed to
/api/payments/stripe/webhooks:SubtleCryptoProvider cannot be used in a synchronous context. Use await constructEventAsync(...) instead of constructEvent(...)No signatures found matching the expected signature for payload.The third row is what makes the second mean something: it shows the 200 is a real verification rather
than a handler that stopped checking. A fourth control, with
webhookSecretunset, returns a bare 200for both a valid and a corrupted signature — that is the existing short-circuit at the top of the
handler, unchanged by this PR.
Not measured: behaviour on Node. Every run above was on workerd.
constructEventAsyncisdocumented as the Workers-safe form of the same verification and the call is already inside the
existing try/catch, but this PR carries no Node before/after, so it should not be described as
verified-unchanged there.
Notes
main(v4). The identical synchronous call is also present on3.xat the sameline of the same file, if you want the fix backported there as maintenance.
issue rather than a plugin bug, so this PR does not close it.