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
@@ -127,7 +127,6 @@ from homeassistant.auth.models import (
|
||||
User,
|
||||
)
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.components.http import KEY_REAL_IP
|
||||
from homeassistant.components.http.auth import async_sign_path
|
||||
from homeassistant.components.http.ban import log_invalid_auth
|
||||
from homeassistant.components.http.data_validator import RequestDataValidator
|
||||
@@ -252,14 +251,10 @@ class TokenView(HomeAssistantView):
|
||||
return await self._async_handle_revoke_token(hass, data)
|
||||
|
||||
if grant_type == "authorization_code":
|
||||
return await self._async_handle_auth_code(
|
||||
hass, data, str(request[KEY_REAL_IP])
|
||||
)
|
||||
return await self._async_handle_auth_code(hass, data, request.remote)
|
||||
|
||||
if grant_type == "refresh_token":
|
||||
return await self._async_handle_refresh_token(
|
||||
hass, data, str(request[KEY_REAL_IP])
|
||||
)
|
||||
return await self._async_handle_refresh_token(hass, data, request.remote)
|
||||
|
||||
return self.json(
|
||||
{"error": "unsupported_grant_type"}, status_code=HTTP_BAD_REQUEST
|
||||
|
||||
@@ -66,12 +66,13 @@ associate with an credential if "type" set to "link_user" in
|
||||
"version": 1
|
||||
}
|
||||
"""
|
||||
from ipaddress import ip_address
|
||||
|
||||
from aiohttp import web
|
||||
import voluptuous as vol
|
||||
import voluptuous_serialize
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.http import KEY_REAL_IP
|
||||
from homeassistant.components.http.ban import (
|
||||
log_invalid_auth,
|
||||
process_success_login,
|
||||
@@ -183,7 +184,7 @@ class LoginFlowIndexView(HomeAssistantView):
|
||||
result = await self._flow_mgr.async_init(
|
||||
handler,
|
||||
context={
|
||||
"ip_address": request[KEY_REAL_IP],
|
||||
"ip_address": ip_address(request.remote),
|
||||
"credential_only": data.get("type") == "link_user",
|
||||
},
|
||||
)
|
||||
@@ -231,7 +232,7 @@ class LoginFlowResourceView(HomeAssistantView):
|
||||
for flow in self._flow_mgr.async_progress():
|
||||
if flow["flow_id"] == flow_id and flow["context"][
|
||||
"ip_address"
|
||||
] != request.get(KEY_REAL_IP):
|
||||
] != ip_address(request.remote):
|
||||
return self.json_message("IP address changed", HTTP_BAD_REQUEST)
|
||||
|
||||
result = await self._flow_mgr.async_configure(flow_id, data)
|
||||
|
||||
Reference in new issue
Block a user