mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Do not log RESTful Command header values (#193394)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user