-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.x] Calling Middleware::trustHosts()
with arguments breaks entire application
#50845
Comments
I second this issue. Is there any alternative to set TrustHosts while it is not fixed? |
Is there any alternative to set TrustHosts while it is not fixed? |
You can copy the middleware from 10.x https://github.com/laravel/laravel/blob/10.x/app/Http/Middleware/TrustHosts.php and replace the middleware in you ->withMiddleware(function (\Illuminate\Foundation\Configuration\Middleware $middleware) {
$middleware->replace(\Illuminate\Http\Middleware\TrustHosts::class, \App\Http\Middleware\TrustHosts::class);
}) |
Thank you, buddy I'll take a look and implement it this way! |
…ion file Document the fix from laravel/framework#50877, triggered by issue laravel/framework#50845
* Add trustHosts() documentation when hosts are fetched from configuration file Document the fix from laravel/framework#50877, triggered by issue laravel/framework#50845 * Update requests.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
Laravel Version
11.1
PHP Version
11.1.1
Database Driver & Version
n/a
Description
The new bootstrapping process breaks when calling
$middleware->trustHosts(...)
with any arguments while$subdomains
is set to true. This is because doing so will cause the middleware to prepare its list of trusted domains, hen the middleware does this it calls theconfig()
helper which hasn't yet been resolved at this point.PS. I'm open to fixing this myself; I think the easiest way to fix this is to defer the configuration of the middleware to a booted callback, that way we can be sure that the config has been resolved.
PPS. If the above is agreeable, I'd like to also add the ability to call
$middleware->trustHosts()
with a callback. I initially ran into the problem described in this issue in my own code, because I was trying to register additional domains from my config (which cannot be done currently as I can only pass an array of already resolved domains)Steps To Reproduce
I've made an example repo here which shows the problem.
Basically:
The text was updated successfully, but these errors were encountered: