TuxInvader / nginx-dns

Sample Configuration for DNS over HTTPS (DoH/DoT gateway) and GSLB with NGINX
BSD 2-Clause "Simplified" License
194 stars 47 forks source link

modify parse post body and remove dns-query in get #10

Closed beyondkmp closed 2 years ago

beyondkmp commented 2 years ago

Post body of https dns is not always start with "\u0000"

$ echo -n 'q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB' | base64 --decode | hexdump                ✔  21:40:39
0000000 ab cd 01 00 00 01 00 00 00 00 00 00 03 77 77 77
0000010 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 00 01 00
0000020 01
0000021

$ echo -n 'q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB' | base64 --decode | curl -H 'content-type: application/dns-message' --data-binary @- https://cloudflare-dns.com/dns-query  -o - | hexdump
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    82  100    49  100    33     58     39 --:--:-- --:--:-- --:--:--    98
0000000 ab cd 81 80 00 01 00 01 00 00 00 00 03 77 77 77
0000010 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 00 01 00
0000020 01 c0 0c 00 01 00 01 00 00 37 d4 00 04 5d b8 d8
0000030 22
0000031
TuxInvader commented 2 years ago

Hi @beyondkmp

The changes look fine, but I'm curious if you have found a client that doesn't use 0 as the DNS ID? In RFC-8484 it states that the clients SHOULD use ID 0 for all queries to aid caching.

In order to maximize HTTP cache friendliness, DoH clients using media
   formats that include the ID field from the DNS message header, such
   as "application/dns-message", SHOULD use a DNS ID of 0 in every DNS
   request.
beyondkmp commented 2 years ago

@TuxInvader Yes, you are right and we should follow the rule of RTF. But I found that the DNS id is not 0 when sending a doh request in https://github.com/ogham/dog and https://github.com/Dreamacro/clash. But 'https://cloudflare-dns.com/dns-query' can still handle the situation that the DNS id is not 0. I think that nginx-dns could be compatible with this situation.