pallets / flask

The Python micro framework for building web applications.
https://flask.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
68.2k stars 16.25k forks source link

configure and check `request.trusted_hosts` #5637

Closed davidism closed 2 weeks ago

davidism commented 2 weeks ago

Add TRUSTED_HOSTS config. In Flask.create_url_adapter, which is called when creating a RequestContext, set request.trusted_hosts to the config. Call get_host with the config, and assign it to request.host to pre-cache the property.

I considered making flask.Request.trusted_hosts a property, so that setting it would trigger validation again automatically. I'm not confident this difference in behavior from Werkzeug, where only accessing request.host triggers validation, would be good. If it's a good idea, it can be done in Werkzeug.

fixes #5636