Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel email verification link returns 403 Invalid signature

Error403 response on the verification link

Short answer

Laravel signs the full URL, including scheme and host. If the URL it rebuilds on the incoming request differs from the one it signed, the check fails with 403. Behind a proxy that is usually http versus https. Check the scheme first, then the host, then whether the link expired or was altered.

  • Applies to Laravel 12, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Compare the link in the email with the URL Laravel thinks it received. Log both on the verification route.

    // temporary, on the verification route
    logger()->info('verify', [
        'full_url' => request()->fullUrl(),
        'secure' => request()->isSecure(),
    ]);
  2. 2Match what you see, then jump to its fix

    1. 1The link in the email starts with https, but full_url in the log starts with httpBehind a load balancer, the app sees http while the link is httpsFix
    2. 2The email link host (APP_URL, a queue worker, localhost) is not the domain the user opensThe host in the link differs from the host serving the requestFix
    3. 3The link is old, or an email scanner or editor altered the query stringThe link expired or the URL was changedFix

What does the error look like?

  • 403 response on the verification link
  • Illuminate\Routing\Exceptions\InvalidSignatureException

Cause 1 of 3

Behind a load balancer, the app sees http while the link is https

1Check

Laravel docs say behind a TLS-terminating load balancer the app can fail to generate https links. The signature is calculated on the URL the app sees.

php artisan tinker   # then run: url('/')

2Fix

Trust your proxy so the scheme from the forwarded headers is used.

// bootstrap/app.php
->withMiddleware(function (Middleware $middleware): void {
    $middleware->trustProxies(at: '*');
})

3Verify

Send a new verification email and open the link.

php artisan optimize:clear

Confirmed by laravel.com

Did this fix it?

Cause 2 of 3

The host in the link differs from the host serving the request

1Check

By default the domain is part of the signed hash, so a link built for one host fails on another. Read APP_URL in the environment that sends the mail.

grep APP_URL .env

2Fix

Set APP_URL to the public address, clear the config cache, and resend. If you really sign without the domain, add the relative option to the middleware.

php artisan config:clear

// only if links were made with absolute: false
Route::get('/x/{id}', ...)->middleware('signed:relative');

3Verify

Resend the email and confirm the link host is the public domain.

php artisan tinker   # then run: route('verification.notice')

Confirmed by laravel.com

Did this fix it?

Cause 3 of 3

The link expired or the URL was changed

1Check

Temporary signed URLs carry an expiry timestamp that is checked on every request, and the signature proves the URL was not modified. A missing or edited part gives a 403.

php artisan route:list --name=verification

2Fix

Resend the verification email from the notice page and open the fresh link as received. Show a friendly page for the exception.

use Illuminate\Routing\Exceptions\InvalidSignatureException;

->withExceptions(function (Exceptions $exceptions): void {
    $exceptions->render(function (InvalidSignatureException $e) {
        return response()->view('errors.link-expired', status: 403);
    });
})

3Verify

Open an old link and confirm the custom page shows; open a new link and confirm verification works.

php artisan test --filter=EmailVerification

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Set trusted proxies and APP_URL in every environment before sending real mail.
  • Test the verification email on staging behind the same proxy as production.
  • Offer a resend button on the verification notice page.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.