fix(security): normalize IPv6-mapped IPv4 in loopback check, add tests

- Apply _normalize_addr in _is_allowed_loopback_target so
  ::ffff:127.0.0.1 is correctly identified as loopback
- Add test for contains_internal_url with IPv6-mapped addresses
- Add test for whitelist + IPv6-mapped CGNAT interaction
This commit is contained in:
chengyongru
2026-05-30 15:34:49 +08:00
committed by Xubin Ren
parent 13dec9d2c2
commit 288146315e
2 changed files with 23 additions and 2 deletions
+1 -1
View File
@@ -149,7 +149,7 @@ def _is_allowed_loopback_target(
hostname: str,
addrs: list[ipaddress.IPv4Address | ipaddress.IPv6Address],
) -> bool:
if not addrs or not all(addr.is_loopback for addr in addrs):
if not addrs or not all(_normalize_addr(addr).is_loopback for addr in addrs):
return False
normalized = hostname.rstrip(".").lower()
if normalized == "localhost":