Prevent transparent mode from connecting to itself in the basic cases, references #4128 (#4135)

This commit is contained in:
Alexander Prinzhorn 2020-08-11 13:13:09 +02:00 committed by GitHub
parent 218e69ddb2
commit 5ebc338fde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View File

@ -6,6 +6,7 @@ Unreleased: mitmproxy next
* Use `@charset` to decode CSS files if available (@prinzhorn) * Use `@charset` to decode CSS files if available (@prinzhorn)
* Fix links to anticache docs in mitmweb and use HTTPS for links to documentation (@rugk) * Fix links to anticache docs in mitmweb and use HTTPS for links to documentation (@rugk)
* Updated typing for WebsocketMessage.content (@prinzhorn) * Updated typing for WebsocketMessage.content (@prinzhorn)
* Prevent transparent mode from connecting to itself in the basic cases (@prinzhorn)
* --- TODO: add new PRs above this line --- * --- TODO: add new PRs above this line ---

View File

@ -10,7 +10,7 @@ class TransparentProxy(protocol.Layer, protocol.ServerConnectionMixin):
def __call__(self): def __call__(self):
try: try:
self.server_conn.address = platform.original_addr(self.client_conn.connection) self.set_server(platform.original_addr(self.client_conn.connection))
except Exception as e: except Exception as e:
raise exceptions.ProtocolException("Transparent mode failure: %s" % repr(e)) raise exceptions.ProtocolException("Transparent mode failure: %s" % repr(e))

View File

@ -107,9 +107,14 @@ class ServerConnectionMixin:
""" """
address = self.server_conn.address address = self.server_conn.address
if address: if address:
forbidden_hosts = ["localhost", "127.0.0.1", "::1"]
if self.config.options.listen_host:
forbidden_hosts.append(self.config.options.listen_host)
self_connect = ( self_connect = (
address[1] == self.config.options.listen_port and address[1] == self.config.options.listen_port and
address[0] in ("localhost", "127.0.0.1", "::1") address[0] in forbidden_hosts
) )
if self_connect: if self_connect:
raise exceptions.ProtocolException( raise exceptions.ProtocolException(