laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

TrustHosts 404 response difficult to trace #2494

Closed fabriciojs closed 3 years ago

fabriciojs commented 3 years ago

Description:

If the APP_ENV is set to production the TrustHosts middleware, in case of failure, will raise a SuspiciousOperationException exception which will be translated to a NotFoundHttpException exception with a clear message Bad hostname provided.

image

The problem is that NONE of these details reach the user, nor logs are generated, as the response is nothing else but a standard 404.

image

This is very, very, very misleading, at the point I decided to open this report. Is it fair to say that the expected behavior here would be a more semantic response? Like a 400. That by itself should improve observability in this situation.

The broader context here to imagine the impact is:

Steps To Reproduce:

Proposed Solution

Can we stop translating this into a NotFoundHttpException and then make it return a 400 instead?

driesvints commented 3 years ago

Heya, since this is more of a request to change the current behavior I'm moving this to the ideas repo.

On the issue at hand: I'm a bit torn myself. I think I also more lean to making it a 400 instead. You're free to attempt a PR if you want. This would need to go into master as it's a breaking change. Please make sure you're very thorough in your PR description. Thanks

fabriciojs commented 3 years ago

Hello @driesvints !

I have been looking into this trying to format a PR. But I reached a point I believe it is best we discuss first what to do:

What we know:


Given the situation laid out above, my suggestion would be to compromise between the spirit from PR 28866 was made and the practical acknowledgment that hiding out SuspiciousOperationException behind a 404 is not ideal and more observability should be given here.

Ideas on what to do:

or


I am not sure about how big is the impact of this - as well as how much of a share of Laravel 8.x applications have made to the production environment already. I do believe that the semantics needs to be improved for TrustHosts to bring the value it proposes.

driesvints commented 3 years ago

Hey @fabriciojs. I've talked this over with the team and at this time we're not going to take any actions here and leave things be. In the past we've already experimented with adjusting the behavior here and it broke a few things for us on Forge. This could potential have another big impact. So we're not keen to make changes here, sorry.

We are going to try to document the usage of TrustHosts soon.

Thanks for raising this.