mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-11-06 11:57:26 +00:00
Keep the session token out of the HTTP client's debug log (#1835)
Camera logins over `SslAesTransport` send their requests to `/stok=<token>/ds`, and `HttpClient` logs every URL it posts to at debug, so the session token ends up in the debug logs people paste into issues. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import builtins
|
||||
import logging
|
||||
import re
|
||||
import ssl
|
||||
import time
|
||||
from typing import Any
|
||||
@@ -22,6 +23,9 @@ from .json import loads as json_loads
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# The session token in /stok=<token>/ds URLs, e.g. after a camera's secure login
|
||||
_SESSION_TOKEN = re.compile(r"(stok=)[^/?#]+")
|
||||
|
||||
|
||||
def get_cookie_jar() -> aiohttp.CookieJar:
|
||||
"""Return a new cookie jar with the correct options for device communication."""
|
||||
@@ -86,7 +90,8 @@ class HttpClient:
|
||||
)
|
||||
await asyncio.sleep(sleep)
|
||||
|
||||
_LOGGER.debug("Posting to %s", url)
|
||||
if _LOGGER.isEnabledFor(logging.DEBUG):
|
||||
_LOGGER.debug("Posting to %s", _SESSION_TOKEN.sub(r"\1REDACTED", str(url)))
|
||||
response_data = None
|
||||
self._last_url = url
|
||||
self.client.cookie_jar.clear()
|
||||
|
||||
Reference in New Issue
Block a user