Skip to content

fix(billing): register the Stripe plugin only when the webhook secret is configured - #9363

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/stripe-webhook-secret-fail-closed
Oct 24, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/stripe-webhook-secret-fail-closed

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The Better Auth Stripe plugin was configured with stripeWebhookSecret: env.STRIPE_WEBHOOK_SECRET || ''. Stripe's verifier accepts a signature computed with an empty key, so with billing on and the secret unset, the plugin's own falsy-secret check was the only thing keeping /api/auth/stripe/webhook from accepting forged events
  • Not exploitable on the pinned @better-auth/stripe@1.6.27 (it 500s with STRIPE_WEBHOOK_SECRET_NOT_FOUND before verifying), but we shouldn't depend on that
  • resolveStripeBilling() now returns the client + secret only when billing is on and both STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET are set; otherwise it logs an error and the plugin (and stripeCustomerId user field) stay unregistered, the same state as billing on with no Stripe key
  • Didn't throw at auth init (would take down sign-in for the deployment) and didn't add an env refinement (env.ts runs with skipValidation: true)
  • sim-setup preflight now requires STRIPE_WEBHOOK_SECRET alongside STRIPE_SECRET_KEY when BILLING_ENABLED is on

Type of Change

  • Bug fix

Testing

  • Loaded the real @/lib/auth/auth module under each billing env config on origin/staging and on this branch, posting forged (empty-key HMAC) and correctly signed events to /api/auth/stripe/webhook and an unauthenticated /api/auth/subscription/upgrade:
Config staging this branch
billing on, key, secret unset webhook 500 / upgrade 400 webhook 404 / upgrade 404 + startup error log
billing on, key, secret set forged 400, signed 200, upgrade 400 identical
billing on, no key 404 / 404 / 404 identical
billing off 404 / 404 / 404 identical
  • Confirmed directly that stripe.webhooks.constructEvent(payload, sig, '') accepts a signature forged with an empty key (Node crypto provider)
  • packages/sim-setup/src/checks.test.ts, biome, comment hygiene; type-check and audits left to CI

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

… is configured

The Better Auth Stripe plugin was passed `STRIPE_WEBHOOK_SECRET || ''`. Stripe's verifier accepts signatures computed with an empty key, so the plugin's own falsy-secret check was the only thing keeping the receiver from accepting forged events. Billing now registers only when the webhook secret is set, logging an error otherwise, and the setup preflight requires it alongside STRIPE_SECRET_KEY.
@vercel

vercel Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 24, 2026 6:35pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Stripe billing now registers only when billing is enabled and both Stripe secrets are present.

  • Stripe billing starts only when its webhook secret is configured.
  • Setup preflight requires both Stripe secrets when billing is on.

Reviews (2) · Last reviewed commit: "fix(billing): treat a whitespace-only St..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/auth/auth.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 06fee1b into staging Oct 24, 2026
68 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/stripe-webhook-secret-fail-closed branch October 24, 2026 19:04

This branch was previously deployed

1 inactive deployment
Preview — bc2ad3ea Deployed Oct 24, 2026 by vercel[bot]
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