fix(cli): mask query tokens in uvicorn access log

This commit is contained in:
hh
2026-08-30 18:30:26 +02:00
parent c438d4cb92
commit 878f7d6473
2 changed files with 41 additions and 0 deletions
+18
View File
@@ -1,5 +1,6 @@
"""``require_token`` accepts ``?token=`` only when no auth header is present."""
import logging
from types import SimpleNamespace
import pytest
@@ -57,3 +58,20 @@ async def test_bootstrap_entry_can_carry_a_scope() -> None:
assert admin is not None and admin.scope == "*"
assert hook is not None and hook.scope == "api" and hook.name == "komodo"
assert not hook.allows("admin") and hook.allows("api")
def test_access_log_filter_masks_query_tokens() -> None:
from beaver_gateway.cli import ScrubQueryTokens
record = logging.LogRecord(
"uvicorn.access",
logging.INFO,
__file__,
1,
'%s - "%s %s HTTP/%s" %d',
("1.2.3.4:1", "POST", "/hooks/komodo?token=s3cret&x=1", "1.1", 202),
None,
)
assert ScrubQueryTokens().filter(record)
assert "s3cret" not in record.getMessage()
assert "/hooks/komodo?token=<…>&x=1" in record.getMessage()