Improve X-Forwarded-* request headers handling (#38696)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch>
This commit is contained in:
19 files changed
+703
-195
No files matched your search
@@ -26,9 +26,9 @@ from homeassistant.util import ssl as ssl_util
|
||||
|
||||
from .auth import setup_auth
|
||||
from .ban import setup_bans
|
||||
from .const import KEY_AUTHENTICATED, KEY_HASS, KEY_HASS_USER, KEY_REAL_IP # noqa: F401
|
||||
from .const import KEY_AUTHENTICATED, KEY_HASS, KEY_HASS_USER # noqa: F401
|
||||
from .cors import setup_cors
|
||||
from .real_ip import setup_real_ip
|
||||
from .forwarded import async_setup_forwarded
|
||||
from .request_context import setup_request_context
|
||||
from .static import CACHE_HEADERS, CachingStaticResource
|
||||
from .view import HomeAssistantView # noqa: F401
|
||||
@@ -296,9 +296,13 @@ class HomeAssistantHTTP:
|
||||
)
|
||||
app[KEY_HASS] = hass
|
||||
|
||||
# This order matters
|
||||
# Order matters, forwarded middleware needs to go first.
|
||||
# Only register middleware if `use_x_forwarded_for` is enabled
|
||||
# and trusted proxies are provided
|
||||
if use_x_forwarded_for and trusted_proxies:
|
||||
async_setup_forwarded(app, trusted_proxies)
|
||||
|
||||
setup_request_context(app, current_request)
|
||||
setup_real_ip(app, use_x_forwarded_for, trusted_proxies)
|
||||
|
||||
if is_ban_enabled:
|
||||
setup_bans(hass, app, login_threshold)
|
||||
|
||||
Reference in new issue
Block a user