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:
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user