Closed davidism closed 2 weeks ago
Map.bind_to_environ
is called when creating the request context, and MapAdapter.match
is called when the context is pushed. Both of these places catch routing exceptions, which are then raised during dispatch after before_request
and before the view. I think it makes sense to check this in Flask.create_url_adapter
, as then no matching be attempted if the host is invalid.
This should be moved up into Map.bind_to_environ
, but can be implemented in Flask until Werkzeug 3.2. See pallets/werkzeug#3007
If
request.trusted_hosts
is set, it will be checked when accessingrequest.host
/url
/etc. AddTRUSTED_HOSTS
config, and check it during routing.