Skip to content

Commit 2efbff6

Browse files
dorianlgsFrando
andauthored
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.<id>&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 <[email protected]>
1 parent dd280b8 commit 2efbff6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

iroh-dns-server/src/http/doh/response.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ impl DnsResponse {
4848
/// Create a new JSON response from a DNS message
4949
pub fn from_message(message: proto::op::Message) -> Result<Self> {
5050
ensure_any!(
51-
message.message_type() != proto::op::MessageType::Response,
51+
message.message_type() == proto::op::MessageType::Response,
5252
"Expected message type to be response"
5353
);
5454

5555
ensure_any!(
56-
message.query_count() != message.queries().len() as u16,
56+
message.query_count() == message.queries().len() as u16,
5757
"Query count mismatch"
5858
);
5959

6060
ensure_any!(
61-
message.answer_count() != message.answers().len() as u16,
61+
message.answer_count() == message.answers().len() as u16,
6262
"Answer count mismatch"
6363
);
6464

0 commit comments

Comments
 (0)