diff --git a/mitmproxy/addons/dns_resolver.py b/mitmproxy/addons/dns_resolver.py index 5446f04cb..29193ab6b 100644 --- a/mitmproxy/addons/dns_resolver.py +++ b/mitmproxy/addons/dns_resolver.py @@ -110,6 +110,11 @@ async def resolve_message(message: dns.Message, loop: asyncio.AbstractEventLoop) class DnsResolver: async def dns_request(self, flow: dns.DNSFlow) -> None: - # handle regular mode requests here to not block the layer - if ctx.options.dns_mode == "regular": + should_resolve = ( + flow.live + and not flow.response + and not flow.error + and ctx.options.dns_mode == "regular" + ) + if should_resolve: flow.response = await resolve_message(flow.request, asyncio.get_running_loop()) diff --git a/mitmproxy/dns.py b/mitmproxy/dns.py index 381cb3319..51e6159ef 100644 --- a/mitmproxy/dns.py +++ b/mitmproxy/dns.py @@ -425,8 +425,8 @@ class DNSFlow(flow.Flow): _stateobject_attributes["request"] = Message _stateobject_attributes["response"] = Message - def __init__(self, client_conn: connection.Client, server_conn: connection.Server): - super().__init__("dns", client_conn, server_conn, True) + def __init__(self, client_conn: connection.Client, server_conn: connection.Server, live: bool = False): + super().__init__("dns", client_conn, server_conn, live) def __repr__(self) -> str: return f"" diff --git a/mitmproxy/proxy/layers/dns.py b/mitmproxy/proxy/layers/dns.py index 921fd384b..159746443 100644 --- a/mitmproxy/proxy/layers/dns.py +++ b/mitmproxy/proxy/layers/dns.py @@ -40,7 +40,7 @@ class DNSLayer(layer.Layer): def __init__(self, context: Context): super().__init__(context) - self.flow = dns.DNSFlow(self.context.client, self.context.server) + self.flow = dns.DNSFlow(self.context.client, self.context.server, live=True) def handle_request(self, msg: dns.Message) -> layer.CommandGenerator[None]: self.flow.request = msg # if already set, continue and query upstream again