fix(security): reject malformed URL ports

This commit is contained in:
Rishi Gupta committed 2026-10-21 22:28:24 +05:30
1 parent 847a93f3ca
commit 55a4fbcddc
1 file changed
+7
+7
View File
@@ -115,6 +115,13 @@ def validate_url(url: str) -> str:
f"Got: {url!r}"
)
try:
port = parsed.port
except ValueError as exc:
raise ValueError(f"Blocked URL with an invalid port. Got: {url!r}") from exc
if port == 0:
raise ValueError(f"Blocked URL with port 0. Got: {url!r}")
hostname = parsed.hostname
if hostname:
# Block known cloud metadata hostnames