miekg / dns

DNS library in Go
https://miek.nl/2014/august/16/go-dns-package
BSD 3-Clause "New" or "Revised" License
7.86k stars 1.12k forks source link

TXT entry more than 255 characters will cause SERVFAIL #1566

Closed matiniamirhossein closed 3 weeks ago

matiniamirhossein commented 2 months ago

Hello,

I wanted to know if there is any solution to send responses more than 255 characters other than splitting them into multiple responses?

Or at least send them in one response if separated:

Response when more than 255 characters:

; <<>> DiG 9.10.6 <<>> @localhost -p 5003 -t txt example.com
; (2 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 40878
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
; example.com.           IN      TXT

;; Query time: 1 msec
;; SERVER: 127.0.0.1#5003(127.0.0.1)
;; WHEN: Fri May 03 23:26:48
;; MSG SIZE  rcvd: 37

Separated each 255 chars txt response:

;; ANSWER SECTION:
example.com.    900     IN      TXT     "DTjg7c+PQ+3UaEkZyF5wNOrxdLf4acWleZBb23pScEXPrF35DkLGajur7aUILYSKd2xTuG96bRzGhSmv/79eV9iAlh2FntHvU317Y5yMTJjHbJ6Di7uYBm6TT7o/WYEgjd4jUUbEjEhLpPNSu6mC8pQxzw9vSHhnAjt7Bl+BcImQSVlqVGTTcyqM0hPHankwLPZX2JJJwbmKAIGpJIb6d0PJvgDfSuDwizAHKs4JLXa5+WV7wwY8UKi+l0S2yCG"
example.com.    900     IN      TXT     "670138636944419053743028302293916462782093931773842086509700182855525152055471340011472=="

Cloudns response:

; <<>> DiG 9.16.48-Ubuntu <<>> -t txt example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50129
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
; example.com.           IN      TXT

;; ANSWER SECTION:
example.com.    60      IN      TXT     "DTjg7c+PQ+3UaEkZyF5wNOrxdLf4acWleZBb23pScEXPrF35DkLGajur7aUILYSKd2xTuG96bRzGhSmv/79eV9iAlh2FntHvU317Y5yMTJjHbJ6Di7uYBm6TT7o/WYEgjd4jUUbEjEhLpPNSu6mC8pQxzw9vSHhnAjt7Bl+BcImQSVlqVGTTcyqM0hPHankwLPZX2JJJwbmKAIGpJIb6d0PJvgDfSuDwizAHKs4JLXa5+WV7wwY8UKi+l0S2yCG" "670138636944419053743028302293916462782093931773842086509700182855525152055471340011472=="

I do know that there is no difference in processing them but in golang for example we have to join 2 separate txt lookups.

gibson042 commented 2 months ago

The definition of TXT RDATA is "One or more \s", i.e. a sequence in which each element is a \ (which itself is "a single length octet followed by that number of characters… can be up to 256 characters in length (including the length octet)"). Not only is a single string with more than 255 octets of content invalid, it would be literally impossible to represent in wire format.

See also #422 (which would have done a better job surfacing the underlying issue but was ultimately rejected) and #1428.