diff --git a/graphify/security.py b/graphify/security.py index a2361171a..2c06a593a 100644 --- a/graphify/security.py +++ b/graphify/security.py @@ -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