Stripe webhook · Stripe Dashboard

401 / 403 from auth middleware or Vercel Deployment Protection

what it looks like
Webhook delivery failed: HTTP status code 401 (Unauthorized)

What it means

Something answered before your handler ran. Stripe has no session cookie, so auth middleware rejects it or redirects it to sign-in. On Vercel, Deployment Protection (Vercel Authentication) blocks preview deployments, and sometimes production, with a 401.

Common causes

  • proxy.ts / middleware.ts protects /api/* and the matcher doesn't exclude the webhook
  • Vercel Deployment Protection is on for the URL Stripe calls (often a preview URL)
  • Cloudflare / WAF bot protection challenges Stripe's requests
  • Basic auth on a staging site

How to fix it

  1. Exclude /api/stripe/webhook from the middleware matcher: the Stripe signature is its authentication
  2. Point Stripe at your production domain, not a *.vercel.app preview URL
  3. Or turn off Deployment Protection for that URL, or use Vercel's Protection Bypass for Automation
  4. Allow Stripe's webhook IPs through your WAF if needed
src/proxy.ts
export const config = {
  // run everywhere except static files and the Stripe webhook
  matcher: ["/((?!api/stripe/webhook|_next/static|_next/image|favicon.ico).*)"],
};
verify the fix
curl -i -X POST https://<your-domain>/api/stripe/webhook
# expect 400 (missing signature) from your handler, not 3xx, 401, 403, 404 or 405
stripe events resend evt_... --webhook-endpoint=we_...
# we_... is the endpoint id in the Dashboard; add --live for a live-mode event

pass if curl gets 400 from your own handler, and the resent event shows a 200 delivery on the endpoint in the Dashboard.

works with stripe-node 23.0.0 · Next.js 16.4.3 App Routerlast verified CLI steps: Stripe CLI 1.55.2, Oct 27, 2026

prevent it · stripe-webhooks.mdc (free Cursor Rules Pack): Keeps the webhook path out of your auth layer, since a 401 counts as a failed delivery.

Prompt for Cursor or Claude Code

Stripe gets 401/403 from my webhook. Find every proxy.ts/middleware.ts matcher, auth check or wrapper that runs on /api/stripe/webhook and exclude that route, keeping signature verification as its only auth. Also tell me if the URL in Stripe is a Vercel preview URL behind Deployment Protection.

Not quite your error? Paste yours into the free VibeBoot Doctor or browse the Stripe webhook fixer.

next: skip the next one

Skip the setup. The VibeBoot SaaS Starter ships Stripe Checkout, the billing portal and a signature-verified webhook already wired, plus auth and a database on Next.js 16.4.3. $49, one-time.

14-day money-back guarantee · lifetime updates

$ fixed it? get the next one first

New fixes for what AI agents break, by email.

When we add a fix or a Cursor rule for a new Next.js, Auth.js, Prisma or Stripe break, it goes out in the VibeBoot newsletter. Free, occasional, unsubscribe in one click.

Subscribe free