fix(security): Stop logging raw trusted proxy entries
This commit is contained in:
@@ -35,7 +35,7 @@ def _parse_trusted_networks(raw: str) -> list[IPv4Network | IPv6Network]:
|
||||
try:
|
||||
networks.append(ipaddress.ip_network(entry, strict=False))
|
||||
except ValueError:
|
||||
logger.warning("trusted_proxies: ignoring invalid entry %r", entry)
|
||||
logger.warning("trusted_proxies: ignoring invalid entry in configuration")
|
||||
return networks
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.core.client_ip import (
|
||||
@@ -103,6 +104,14 @@ def test_parse_trusted_networks_ignores_invalid() -> None:
|
||||
assert len(nets) == 2
|
||||
|
||||
|
||||
def test_parse_trusted_networks_does_not_log_invalid_value(caplog) -> None:
|
||||
with caplog.at_level(logging.WARNING, logger="app.core.client_ip"):
|
||||
_parse_trusted_networks("127.0.0.1, not-an-ip, 10.0.0.0/8")
|
||||
|
||||
assert "trusted_proxies: ignoring invalid entry in configuration" in caplog.text
|
||||
assert "not-an-ip" not in caplog.text
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Integration tests for get_client_ip
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user