fix(backend): verify Stripe webhooks with constructEventAsync - #2903
Closed
posthog[bot] wants to merge 1 commit into
Closed
fix(backend): verify Stripe webhooks with constructEventAsync#2903posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
Bun matches the `worker` export condition of the `stripe` package, so it loads the SubtleCrypto provider. That provider computes an HMAC only in an async context, so the synchronous `constructEvent` throws before the payload parses. Every webhook delivery returned HTTP 400 and no subscription state was written. Switch to `await constructEventAsync`, which the Node and SubtleCrypto providers both support. Add a controller test that runs real signature verification, which fails on the old sync path under Bun and passes now. Generated-By: PostHog Desktop Task-Id: 78ad5519-9602-4a28-bb96-95bea3327c03
Contributor
|
Superseded by #2905, which merged this exact change at 15:53Z today along with two tests that exercise the SDK's real crypto path (every prior webhook test stubbed the Stripe client wholesale, which is why nothing caught the bug). The diagnosis here was correct and matches ours line for line. Closing as a duplicate, not a rejection. Verified fixed rather than assumed: |
tyler-dane
deleted the
posthog-self-driving/fixbilling-use-constructeventasync-to-e8e4d8
branch
August 27, 2026 19:32
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
workerexport condition of thestripepackage, so it loads the SubtleCrypto provider. That provider computes an HMAC only in an async context, so the synchronousconstructEventthrowsCryptoProviderOnlySupportsAsyncErrorbefore the payload parses.processStripeEventnever runs.await getStripeClient().webhooks.constructEventAsync(...), which both the Node and SubtleCrypto providers support.Closes #2902
Simplicity
Automated validation
SubtleCryptoProvider cannot be used in a synchronous context; with the fix it returns HTTP 200 and records the event.Independent review
Test plan
bun packages/scripts/src/testing/test-mongo-env.ts backend -- './packages/backend/src/billing/**/*.test.ts'→ 38 pass, 0 failbunx typescript@7.0.2 --noEmit→ cleanbunx biome checkon the changed files → cleanCreated with PostHog Desktop from this inbox report.