Typical Webhook Signature Verification Error (Stripe + Laravel)
When middleware consumes the raw HTTP stream, JSON gets re-serialized before hashing, or encoding/prefixes mismatch in Stripe + Laravel, your server logs an exception matching the output below:
Stripe\Exception\SignatureVerificationException: No signatures found matching the expected signature for payload
Raw Request Stream Handling & Replay Protection in Stripe + Laravel
Integrating Stripe webhooks into a Laravel 11 or Laravel 12 application is one of the highest-stakes backend workflows in SaaS engineering: billing upgrades, subscription renewals, and invoice failures all depend on verifying Stripe's Stripe-Signature header accurately. Yet even experienced PHP engineers routinely encounter Stripe\Exception\SignatureVerificationException or HTTP 419 Page Expired right when deploying to staging or production.
The root cause of almost every SignatureVerificationException is hashing re-serialized JSON instead of the raw HTTP request bytes. Stripe signs the literal string "{timestamp}.{raw_body}"; including every space, newline, and Unicode escape byte transmitted over TCP. Calling json_encode($request->all()) inside a Laravel controller alters formatting and key ordering, producing a completely different HMAC-SHA256 digest. In Laravel, you MUST read the untouched stream with $request->getContent().
Equally important in Laravel 11 and 12 is CSRF middleware exclusion. If you register your webhook endpoint inside routes/web.php (or any middleware group including ValidateCsrfToken), Laravel rejects Stripe's external POST request with HTTP 419 before your controller even executes. Either place webhook routes inside routes/api.php or explicitly exempt webhooks/* inside bootstrap/app.php via $middleware->validateCsrfTokens(except: ["webhooks/*"]).
Always verify the timestamp tolerance window (default 300 seconds / 5 minutes) to defeat replay attacks, compare digests with PHP's constant-time hash_equals() function rather than ===, and immediately dispatch heavy database or email work onto a Redis/MySQL Laravel queue job so Stripe receives an HTTP 200 OK within 200 milliseconds; preventing timeout retries and duplicate fulfillment.
Finally, double-check that STRIPE_WEBHOOK_SECRET in your production .env holds the endpoint-specific signing secret (starting with whsec_) from your live Stripe Dashboard rather than the temporary stripe listen CLI secret or your sk_live_ API key, and clear Laravel's config cache whenever rotating secrets.
In production Laravel billing systems, combine raw-body Stripe signature verification with a dedicated webhook_events ledger table indexed by unique stripe_event_id and processed_at columns. Logging rejected signature failures (without logging the raw secret) alongside HTTP status codes lets on-call engineers spot secret-rotation mismatches within seconds, while Laravel Horizon or Redis queue retries guarantee zero lost subscription upgrades during transient database blips.
Step-by-Step Stripe + Laravel Webhook Verification Setup
Follow each step below to preserve untouched raw request bytes, enforce constant-time HMAC verification, and offload webhook jobs asynchronously for fast 2xx acknowledgments.
1Exclude Webhook Routes From Laravel 11/12 CSRF Verification
bootstrap/app.phpEnsure external Stripe POST calls are never blocked with 419 Page Expired by either mounting them in routes/api.php or explicitly excluding webhooks/* in bootstrap/app.php.
bootstrap/app.phpphp<?php use Illuminate\Foundation\Application; use Illuminate\Foundation\Configuration\Middleware; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', api: __DIR__.'/../routes/api.php', ) ->withMiddleware(function (Middleware $middleware) { $middleware->validateCsrfTokens(except: [ 'webhooks/stripe', ]); }) ->create();2Verify Raw Request Bytes With $request->getContent() and Stripe SDK
app/Http/Controllers/StripeWebhookController.phpPass $request->getContent() directly to Stripe\Webhook::constructEvent() (or manual hash_hmac + hash_equals) and dispatch an idempotent queued job immediately.
app/Http/Controllers/StripeWebhookController.phpphp<?php namespace App\Http\Controllers; use App\Jobs\ProcessStripeEvent; use Illuminate\Http\Request; use Illuminate\Http\Response; use Stripe\Exception\SignatureVerificationException; use Stripe\Webhook; class StripeWebhookController extends Controller { public function __invoke(Request $request): Response { $rawBody = $request->getContent(); $signature = (string) $request->header('Stripe-Signature', ''); $secret = (string) config('services.stripe.webhook_secret'); try { $event = Webhook::constructEvent($rawBody, $signature, $secret); } catch (SignatureVerificationException|\UnexpectedValueException $e) { return response('Invalid Stripe webhook signature', 400); } ProcessStripeEvent::dispatch($event->id, $event->type, $event->toArray()); return response('Webhook handled', 200); } }3Store Endpoint Secret in config/services.php for config:cache Compatibility
config/services.phpNever call env("STRIPE_WEBHOOK_SECRET") inside your controller; map it in config/services.php so php artisan config:cache preserves the secret in production.
config/services.phpphp'stripe' => [ 'secret' => env('STRIPE_SECRET'), 'webhook_secret' => env('STRIPE_WEBHOOK_SECRET'), ],4Test End-to-End Locally With Stripe CLI Before Deploying
terminalForward live test events to your local Laravel endpoint and confirm HTTP 200 OK with zero signature errors.
terminalbashstripe listen --forward-to http://127.0.0.1:8000/api/webhooks/stripe stripe trigger checkout.session.completed
Common Stripe + Laravel Webhook Pitfalls
Avoid these three subtle production failure modes when verifying external webhook signatures.
Mixing Up Local stripe listen whsec_ Secret With Production Dashboard Secret
Every Stripe webhook endpoint has its own unique whsec_ signing secret. Leaving the temporary local CLI secret in production .env causes 100% of live webhooks to fail with SignatureVerificationException.
Using json_encode($request->all()) Instead of $request->getContent()
Re-encoding Laravel's parsed request array strips whitespace, escapes forward slashes differently, and alters float formatting; guaranteeing HMAC mismatch on every Stripe event.
Nginx 301 Trailing-Slash Redirects Turning POST Webhooks Into GET
If Stripe posts to https://api.example.com/api/webhooks/stripe and Nginx redirects to /api/webhooks/stripe/ via 301, Stripe does not follow redirects on webhooks and marks delivery as failed.
Audit Your Webhook Signing Secrets & Nginx Reverse Proxy Headers
Make sure your .env signing secret has no trailing spaces or unquoted # truncation and your Nginx proxy forwards raw POST payloads without 301 redirects:
Validate Laravel 11/12 .env files locally in your browser. Fix InvalidFileException, unquoted # in DB_PASSWORD, invalid base64 APP_KEY, and config:cache traps.
Configure Nginx reverse proxy for Laravel Octane (FrankenPHP/Swoole) on port 8000 and Laravel Reverb WebSockets on port 8080 with SSL and 3600s timeouts.
Frequently Asked Questions
- Why does Stripe return SignatureVerificationException only in production on Laravel?
- Most often either php artisan config:cache made env("STRIPE_WEBHOOK_SECRET") return null (switch to config("services.stripe.webhook_secret")), or the production .env still has the local stripe listen signing secret instead of the live endpoint secret.
- Should I use Laravel Cashier or a custom Stripe webhook controller?
- Laravel Cashier ships with built-in VerifyWebhookSignature middleware and handles subscription lifecycle events cleanly. Use a custom controller when integrating one-off Checkout payments, Connect accounts, or non-Cashier billing schemas.
- How do I make Laravel Stripe webhook processing idempotent?
- Store each processed Stripe event ID ($event->id) in a unique database column (stripe_event_id) before applying credits or provisioning access. If Stripe retries the same event, skip duplicates cleanly and return HTTP 200.
- Why does Stripe-Signature sometimes contain multiple v1= values?
- During zero-downtime webhook secret rotation, Stripe signs payloads with both the old and new whsec_ secrets simultaneously (t=..,v1=sig1,v1=sig2). Always check whether ANY v1 token matches your expected digest via hash_equals().
Related Webhook HMAC Verification Guides
Browse all 10 webhook guides →Stripe Webhook Verification in Next.js App Router (request.text() Guide)
Fix Stripe webhook signature mismatch in Next.js App Router Route Handlers. Use await request.text() instead of request.json() with timingSafeEqual.
GitHub Webhook X-Hub-Signature-256 Verification in Laravel (Queues & Raw Body)
Verify GitHub X-Hub-Signature-256 webhooks in Laravel 11/12 using $request->getContent(), hash_equals(), CSRF bypass, and async Redis queue job dispatch.
Shopify Base64 HMAC Webhook Verification in Laravel (Binary hash_hmac Fix)
Verify Shopify X-Shopify-Hmac-Sha256 webhooks in Laravel 11/12 using base64_encode with binary hash_hmac, $request->getContent(), and hash_equals.
Stripe Webhook Signature Verification in FastAPI (request.body() Guide)
Fix Stripe webhook signature errors in Python FastAPI. Read raw bytes with await request.body() before Pydantic parsing and compare via hmac.compare_digest.