]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Validate URL scheme and ensure host presence lovelydinosaur-patch-1 3729/head
authorKim Christie <kim@encode.io>
Wed, 17 Dec 2025 13:57:56 +0000 (13:57 +0000)
committerGitHub <noreply@github.com>
Wed, 17 Dec 2025 13:57:56 +0000 (13:57 +0000)
Add validation for URL scheme and netloc in requests.

src/httpx/_request.py

index 1b739b1872926717939dceda92b1739ba74ed187..03c78dfea2e5a8475869a72ab1a436067191158f 100644 (file)
@@ -28,6 +28,11 @@ class Request:
         # A client MUST include a Host header field in all HTTP/1.1 request messages.
         if "Host" not in self.headers:
             self.headers = self.headers.copy_set("Host", self.url.netloc)
+        
+        if self.url.scheme not in ('http', 'https'):
+            raise ValueError(f'Invalid scheme for URL {str(self.url)!r}.')
+        if not self.url.netloc:
+            raise ValueError(f'Missing host for URL {str(self.url)!r}.')
 
         if content is not None:
             if isinstance(content, bytes):