mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Sanitize user-agent in wrong_login message (#45251)
This commit is contained in:
parent
b2f914823d
commit
cf9ea6f82d
@ -105,16 +105,18 @@ async def process_wrong_login(request):
|
|||||||
except herror:
|
except herror:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
msg = f"Login attempt or request with invalid authentication from {remote_host} ({remote_addr})"
|
base_msg = f"Login attempt or request with invalid authentication from {remote_host} ({remote_addr})."
|
||||||
|
|
||||||
|
# The user-agent is unsanitized input so we only include it in the log
|
||||||
user_agent = request.headers.get("user-agent")
|
user_agent = request.headers.get("user-agent")
|
||||||
if user_agent:
|
log_msg = f"{base_msg} ({user_agent})"
|
||||||
msg = f"{msg} ({user_agent})"
|
|
||||||
|
|
||||||
_LOGGER.warning(msg)
|
notification_msg = f"{base_msg} See the log for details."
|
||||||
|
|
||||||
|
_LOGGER.warning(log_msg)
|
||||||
|
|
||||||
hass.components.persistent_notification.async_create(
|
hass.components.persistent_notification.async_create(
|
||||||
msg, "Login attempt failed", NOTIFICATION_ID_LOGIN
|
notification_msg, "Login attempt failed", NOTIFICATION_ID_LOGIN
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if ban middleware is loaded
|
# Check if ban middleware is loaded
|
||||||
|
@ -174,8 +174,8 @@ async def test_ip_bans_file_creation(hass, aiohttp_client):
|
|||||||
|
|
||||||
assert len(notification_calls) == 3
|
assert len(notification_calls) == 3
|
||||||
assert (
|
assert (
|
||||||
"Login attempt or request with invalid authentication from example.com (200.201.202.204) (Python"
|
notification_calls[0].data["message"]
|
||||||
in notification_calls[0].data["message"]
|
== "Login attempt or request with invalid authentication from example.com (200.201.202.204). See the log for details."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user