Fix missing redirect after login by trusting reverse proxy headers - #7971
Open
wakqasahmed wants to merge 1 commit into
Open
Fix missing redirect after login by trusting reverse proxy headers#7971wakqasahmed wants to merge 1 commit into
wakqasahmed wants to merge 1 commit into
Conversation
…onicahq#7696) Laravel 11's bootstrap/app.php never wired up TrustProxies, so requests behind a TLS-terminating reverse proxy (the common Docker/Apache/nginx self-hosted setup) were always seen as plain HTTP. Fortify's post-login redirect() and other absolute URL generation then used http://, which gets blocked as mixed content on an https page, leaving the SPA stuck until a manual refresh forced a fresh page load.
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
bootstrap/app.phpnever registeredTrustProxies, unlike the legacy4.xbranch which had it wired inApp\Http\Middleware\TrustProxiesvia the HTTP kernel. As a result, requests arriving through a TLS-terminating reverse proxy (the common self-hosted Docker/Apache/nginx setup) are always seen by Laravel as plain HTTP.redirect()->intended(...)(and other absolute URL generation) then buildshttp://URLs even though the page is served overhttps://. The browser blocks the resulting request/navigation as mixed content, so the Inertia SPA appears to hang with "no redirect" after login — a manual refresh works because the fresh full page load re-derives auth state independently of the blocked request.config/trustedproxy.php(with itsAPP_TRUSTED_PROXIESenv var, already documented in.env.example) existed but was unused/orphaned after the Laravel 11 rewrite.$middleware->trustProxies(at: ...)inbootstrap/app.php, reading the existingAPP_TRUSTED_PROXIESenv var (supports*, a comma-separated IP/CIDR list, or unset = trust none, matching the previously documented behavior).Fixes #7696
Test plan
tests/Feature/Http/TrustedProxiesTest.php: withAPP_TRUSTED_PROXIES=*and anX-Forwarded-Proto: httpsheader, POST/loginnow redirects to anhttps://location (previously it would generatehttp://).php artisan test --filter=TrustedProxiesTest(not runnable in this environment — no PHP binary available; verified by code inspection).