mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Use host header values only when the ports match
This commit is contained in:
parent
6f96da08c9
commit
175109e44e
@ -183,7 +183,12 @@ class Request(Message):
|
||||
This is useful in transparent mode where :py:attr:`host` is only an IP address,
|
||||
but may not reflect the actual destination as the Host header could be spoofed.
|
||||
"""
|
||||
return self._parse_host_header()[0] or self.host
|
||||
host, port = self._parse_host_header()
|
||||
if not host:
|
||||
return self.host
|
||||
if not port:
|
||||
port = 443 if self.scheme == 'https' else 80
|
||||
return host if port == self.port else self.host
|
||||
|
||||
@property
|
||||
def pretty_url(self):
|
||||
|
@ -104,19 +104,23 @@ class TestRequestUtils(object):
|
||||
|
||||
def test_pretty_host(self):
|
||||
request = treq()
|
||||
# Without host header
|
||||
assert request.pretty_host == "address"
|
||||
assert request.host == "address"
|
||||
# Same port as self.port (22)
|
||||
request.headers["host"] = "other:22"
|
||||
assert request.pretty_host == "other"
|
||||
# Different Ports
|
||||
request.headers["host"] = "other"
|
||||
assert request.pretty_host == "other"
|
||||
assert request.pretty_host == "address"
|
||||
assert request.host == "address"
|
||||
# Empty host
|
||||
request.host = None
|
||||
assert request.pretty_host is None
|
||||
assert request.host is None
|
||||
|
||||
# Invalid IDNA
|
||||
request.headers["host"] = ".disqus.com"
|
||||
request.headers["host"] = ".disqus.com:22"
|
||||
assert request.pretty_host == ".disqus.com"
|
||||
|
||||
def test_pretty_url(self):
|
||||
|
Loading…
Reference in New Issue
Block a user