From 2efbff6a21398753136cb1c8aed4e63d86e625d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20Gonz=C3=A1lez?= <49845852+dorianlgs@users.noreply.github.com> Date: Mon, 8 Dec 2025 07:36:53 -0500 Subject: [PATCH] fix(iroh-dns-server): inverted validation logic in DoH JSON response handler (#3737) ## Description Fix inverted validation logic in the DNS-over-HTTPS (DoH) JSON response handler. Previously, JSON DoH queries (`accept: application/dns-json`) failed with a 500 error: ```json {"status": "500", "detail": "Expected message type to be response"} ``` ## Changes made Corrected three ensure_any! validation checks from != to ==: message_type() == Response query_count() == queries().len() answer_count() == answers().len() ## Testing Tested locally with iroh-dns-server v0.95.1: Before fix: ```sh curl --header "accept: application/dns-json" \ "http://localhost:8080/dns-query?name=_iroh.&type=TXT" # {"status":"500","detail":"Expected message type to be response"} ``` After fix: ```sh { "Status": 0, "Answer": [{ "name": "_iroh.nskwmm4rh...", "type": 16, "TTL": 30, "data": "relay=https://..." }] } ``` ## Notes Only affects JSON DoH responses. The binary POST format worked fine in my tests Co-authored-by: Franz Heinzmann --- iroh-dns-server/src/http/doh/response.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iroh-dns-server/src/http/doh/response.rs b/iroh-dns-server/src/http/doh/response.rs index 22eeaa5e55..de5abe415d 100644 --- a/iroh-dns-server/src/http/doh/response.rs +++ b/iroh-dns-server/src/http/doh/response.rs @@ -48,17 +48,17 @@ impl DnsResponse { /// Create a new JSON response from a DNS message pub fn from_message(message: proto::op::Message) -> Result { ensure_any!( - message.message_type() != proto::op::MessageType::Response, + message.message_type() == proto::op::MessageType::Response, "Expected message type to be response" ); ensure_any!( - message.query_count() != message.queries().len() as u16, + message.query_count() == message.queries().len() as u16, "Query count mismatch" ); ensure_any!( - message.answer_count() != message.answers().len() as u16, + message.answer_count() == message.answers().len() as u16, "Answer count mismatch" );