Repository navigation
URL accepts ports above 65535 without raising InvalidURL #3823
Replies: 1 comment
|
The out-of-range port is not only accepted, it is also sent to a different port. On Linux the request to The check that is missing is in
The last row happens because I checked what happens at connect time with a local server bound to 34463 inside a srv = http.server.HTTPServer(("127.0.0.1", 99999 % 65536), Handler)
...
httpx.get("http://127.0.0.1:99999/")
# -> 200 served by port 34463
socket.getaddrinfo("127.0.0.1", 99999, type=socket.SOCK_STREAM)[0][4]
# -> ('127.0.0.1', 34463)So the failure the issue expects "later at connection time" does not happen on glibc. Until import httpx
def check_port(request):
port = request.url.port
if port is not None and not 0 <= port <= 65535:
raise httpx.InvalidURL(f"Port out of range 0-65535: {port}")
client = httpx.Client(event_hooks={"request": [check_port]})
client.get("http://127.0.0.1:99999/")
# httpx.InvalidURL: Port out of range 0-65535: 99999This does not catch |
Uh oh!
There was an error while loading. Please reload this page.
Summary
httpx.URLaccepts ports outside the valid range 0-65535.Repro
The stdlib
urllib.parse.urlparse(...).portraisesValueError: Port out of range 0-65535for this input.Expected
httpx.InvalidURL(e.g. "Invalid port") at URL construction, rather than failing later at connection time with a less clear error.Checked on current master; I found no existing issue about this.
All reactions