Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions homeassistant/components/websocket_api/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from homeassistant.core import Context, HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError, Unauthorized
from homeassistant.helpers.http import current_request
from homeassistant.helpers.redact import async_redact_data
from homeassistant.util.json import JsonValueType

from . import const, messages
Expand All @@ -32,6 +33,15 @@
"current_connection", default=None
)

REDACT_KEYS = {
"access_token",
"password",
"api_password",
"refresh_token",
"token",
"auth_token",
}

type MessageHandler = Callable[[HomeAssistant, ActiveConnection, dict[str, Any]], None]
type BinaryHandler = Callable[[HomeAssistant, ActiveConnection, bytes], None]

Expand Down Expand Up @@ -201,6 +211,7 @@ def async_handle(self, msg: JsonValueType) -> None:
or type(type_) is not str
)
):
msg = async_redact_data(msg, REDACT_KEYS)
self.logger.error("Received invalid command: %s", msg)
id_ = msg.get("id") if isinstance(msg, dict) else 0
Comment thread
ch604 marked this conversation as resolved.
self.send_message(
Expand Down Expand Up @@ -264,6 +275,7 @@ def _connect_closed_error(
self, msg: bytes | str | dict[str, Any] | Callable[[], str]
) -> None:
"""Send a message when the connection is closed."""
msg = async_redact_data(msg, REDACT_KEYS)
self.logger.debug("Tried to send message %s on closed connection", msg)

@callback
Expand Down Expand Up @@ -315,4 +327,5 @@ def async_handle_exception(self, msg: dict[str, Any], err: Exception) -> None:
err_message += f" ({code})"
err_message += " " + self.get_description(current_request.get())

err_message = async_redact_data(err_message, REDACT_KEYS)
log_handler("Error handling message: %s", err_message)
Comment thread
ch604 marked this conversation as resolved.
Loading