From d587353ba0fd485d88161a042f2774f5de804234 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 26 Jun 2023 01:03:15 +0200 Subject: [PATCH] mitigate impact of missing sockaddr for UDP, refs #6204 (#6205) --- mitmproxy/proxy/server.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mitmproxy/proxy/server.py b/mitmproxy/proxy/server.py index feaab5f27..8972ce783 100644 --- a/mitmproxy/proxy/server.py +++ b/mitmproxy/proxy/server.py @@ -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,