mitigate impact of missing sockaddr for UDP, refs #6204 (#6205)

This commit is contained in:
Maximilian Hils 2023-06-26 01:03:15 +02:00 committed by GitHub
parent 82b3d00f01
commit d587353ba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -437,9 +437,18 @@ class LiveConnectionHandler(ConnectionHandler, metaclass=abc.ABCMeta):
options: moptions.Options,
mode: mode_specs.ProxyMode,
) -> None:
# mitigate impact of https://github.com/mitmproxy/mitmproxy/issues/6204:
# For UDP, we don't get an accurate sockname from the transport when binding to all interfaces,
# however we would later need that to generate matching certificates.
# Until this is fixed properly, we can at least make the localhost case work.
sockname = writer.get_extra_info("sockname")
if sockname == "::":
sockname = "::1"
elif sockname == "0.0.0.0":
sockname = "127.0.0.1"
client = Client(
peername=writer.get_extra_info("peername"),
sockname=writer.get_extra_info("sockname"),
sockname=sockname,
timestamp_start=time.time(),
proxy_mode=mode,
state=ConnectionState.OPEN,