fix: sync redirect bypass, Host header port, redirect loop dead code

Pass follow_redirects through in HTTPHandler.get() — previously the
parameter was accepted but never forwarded to the underlying httpx
client, making sync redirect protection ineffective.

Include port in Host header when non-default (e.g. example.com:8080).

Fix redirect loop to read Location header directly instead of
response.next_request (which is None when follow_redirects=False).
This commit is contained in:
user 2026-04-16 04:55:56 +00:00
parent e2a0c96663
commit 00b25d6ca4
No known key found for this signature in database
2 changed files with 8 additions and 2 deletions

View file

@ -1019,6 +1019,7 @@ class HTTPHandler:
url,
params=params,
headers=headers,
follow_redirects=_follow_redirects,
)
return response

View file

@ -87,6 +87,11 @@ def validate_url(url: str) -> Tuple[str, str]:
port = parsed.port
default_port = 443 if parsed.scheme == "https" else 80
# Build the Host header value — include port when non-default
host_header = (
hostname if (port is None or port == default_port) else f"{hostname}:{port}"
)
# Resolve hostname and validate ALL addresses
try:
addrinfo = socket.getaddrinfo(
@ -113,7 +118,7 @@ def validate_url(url: str) -> Tuple[str, str]:
# we rewrite to the validated IP like HTTP.
ssl_verify = getattr(litellm, "ssl_verify", True)
if parsed.scheme == "https" and ssl_verify is not False:
return url, hostname
return url, host_header
# For HTTP, rewrite URL to connect to the validated IP directly
# to prevent DNS rebinding (no TLS to bind the connection).
@ -130,7 +135,7 @@ def validate_url(url: str) -> Tuple[str, str]:
(parsed.scheme, new_netloc, parsed.path, parsed.params, parsed.query, "")
)
return rewritten, hostname
return rewritten, host_header
_MAX_REDIRECTS = 10