fix: reject multicast and reserved egress addresses
Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a0726e-5232-73f2-aaca-2c05ceb62efb
This commit is contained in:
parent
d477c3b5d9
commit
e45e3e6401
2 changed files with 9 additions and 4 deletions
|
|
@ -25,7 +25,8 @@ def destinations(entries: list[str]) -> frozenset[str]:
|
|||
|
||||
def connect_public(host: str) -> socket.socket:
|
||||
addresses = socket.getaddrinfo(host, 443, type=socket.SOCK_STREAM)
|
||||
if not addresses or any(not ipaddress.ip_address(a[4][0]).is_global for a in addresses):
|
||||
ips = [ipaddress.ip_address(a[4][0]) for a in addresses]
|
||||
if not ips or any(not ip.is_global or ip.is_multicast or ip.is_reserved for ip in ips):
|
||||
raise ValueError("non-public destination")
|
||||
# Connect to the already checked numeric address; never resolve a second time.
|
||||
for family, kind, proto, _, address in addresses:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue