From 7365f185421baa85ca103af9ef13dfdd39f26416 Mon Sep 17 00:00:00 2001 From: Robert C Jensen Date: Fri, 7 Apr 2017 15:46:21 -0400 Subject: [PATCH] fixes ipv6 authority form parsing in CONNECT --- mitmproxy/net/http/http1/read.py | 4 +++- test/mitmproxy/net/http/http1/test_read.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mitmproxy/net/http/http1/read.py b/mitmproxy/net/http/http1/read.py index ef88fd6ce..491135ac0 100644 --- a/mitmproxy/net/http/http1/read.py +++ b/mitmproxy/net/http/http1/read.py @@ -271,7 +271,9 @@ def _parse_authority_form(hostport): ValueError, if the input is malformed """ try: - host, port = hostport.split(b":") + host, port = hostport.rsplit(b":", 1) + if host.startswith(b"[") and host.endswith(b"]"): + host = host[1:-1] port = int(port) if not check.is_valid_host(host) or not check.is_valid_port(port): raise ValueError() diff --git a/test/mitmproxy/net/http/http1/test_read.py b/test/mitmproxy/net/http/http1/test_read.py index 642b91c04..b3589c928 100644 --- a/test/mitmproxy/net/http/http1/test_read.py +++ b/test/mitmproxy/net/http/http1/test_read.py @@ -243,6 +243,7 @@ def test_read_request_line(): def test_parse_authority_form(): assert _parse_authority_form(b"foo:42") == (b"foo", 42) + assert _parse_authority_form(b"[2001:db8:42::]:443") == (b"2001:db8:42::", 443) with pytest.raises(exceptions.HttpSyntaxException): _parse_authority_form(b"foo") with pytest.raises(exceptions.HttpSyntaxException):