Do not log RESTful Command header values (#193394)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Duco Sebel
2026-11-19 16:09:16 +01:00
committed by GitHub
co-authored by Claude
parent 27fc7e38b9
commit 0c58eaae97
2 changed files with 28 additions and 1 deletions
@@ -108,11 +108,12 @@ def async_register_rest_command(
if content_type:
headers[hdrs.CONTENT_TYPE] = content_type
# Header values often hold tokens, so only their names are logged
_LOGGER.debug(
"Calling %s %s with headers: %s and payload: %s",
method,
request_url,
headers,
list(headers),
payload,
)
@@ -2,6 +2,7 @@
import base64
from http import HTTPStatus
import logging
from unittest.mock import patch
import aiohttp
@@ -223,6 +224,31 @@ async def test_rest_command_configured_authorization_header_wins(
assert CIMultiDict(headers).getall("Authorization") == ["Bearer configured"]
async def test_rest_command_header_values_not_logged(
hass: HomeAssistant,
setup_component: ComponentSetup,
aioclient_mock: AiohttpClientMocker,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Call a rest command and check its header values stay out of the log."""
caplog.set_level(logging.DEBUG, logger="homeassistant.components.rest_command")
await setup_component(
{
"header_test": {
"url": TEST_URL,
"headers": {"Authorization": "Bearer secret"},
}
}
)
aioclient_mock.get(TEST_URL, content=b"success")
caplog.clear()
await hass.services.async_call(DOMAIN, "header_test", {}, blocking=True)
assert "Authorization" in caplog.text
assert "Bearer secret" not in caplog.text
@pytest.mark.usefixtures("aioclient_mock")
async def test_rest_command_digest_auth(
hass: HomeAssistant,