[GH-ISSUE #4242] Built-in DNS server ignores buffer size - implement truncate and compress #8308

Closed
opened 2026-08-05 01:17:19 -04:00 by saavagebueno · 4 comments
Owner

Originally created by @hurricanehrndz on GitHub (Jul 29, 2025).
Original GitHub issue: https://github.com/netbirdio/netbird/issues/4242

Describe the problem

The built in DNS server does not scrub messages prior to writing replies to clients. Client by default will communicate the buffer size and the server should either truncate or compress messages when the buffer has overflown, the message is simply written via the dns pkg.

Default UDP buffer by some client is 512, when supporting edns0 it is usually 1232. The server should also support TCP for client like dig that will retry with TCP when messages are truncated.

https://datatracker.ietf.org/doc/html/rfc7766

To Reproduce

Steps to reproduce the behavior:


; <<>> DiG 9.20.9 <<>> @100.122.255.254 +noedns +comments +bufsize=512 github-cloud.s3.amazonaws.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20515
;; flags: qr rd ra; QUERY: 1, ANSWER: 10, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;github-cloud.s3.amazonaws.com. IN      A

;; ANSWER SECTION:
github-cloud.s3.amazonaws.com. 24095 IN CNAME   s3-1-w.amazonaws.com.
s3-1-w.amazonaws.com.   131     IN      CNAME   s3-w.us-east-1.amazonaws.com.
s3-w.us-east-1.amazonaws.com. 2 IN      A       52.216.210.145
s3-w.us-east-1.amazonaws.com. 2 IN      A       52.217.119.1
s3-w.us-east-1.amazonaws.com. 2 IN      A       52.216.107.124
s3-w.us-east-1.amazonaws.com. 2 IN      A       3.5.16.19
s3-w.us-east-1.amazonaws.com. 2 IN      A       3.5.27.209
s3-w.us-east-1.amazonaws.com. 2 IN      A       16.15.176.156
s3-w.us-east-1.amazonaws.com. 2 IN      A       3.5.29.79
s3-w.us-east-1.amazonaws.com. 2 IN      A       52.217.125.73

;; Query time: 31 msec
;; SERVER: 100.122.255.254#53(100.122.255.254) (UDP)
;; WHEN: Tue Jul 29 15:16:46 MDT 2025
;; MSG SIZE  rcvd: 535

Expected behavior
expected either TC flag to be set and retry to occur on TCP, but netbird lacks a TCP listener, or for the message above to have been compressed. In all reality the example above should have had compression enable, as most upstream servers would have done so.

i.e.

❯ dig @8.8.8.8 +noedns +comments +bufsize=512 github-cloud.s3.amazonaws.com

; <<>> DiG 9.20.9 <<>> @8.8.8.8 +noedns +comments +bufsize=512 github-cloud.s3.amazonaws.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4052
;; flags: qr rd ra; QUERY: 1, ANSWER: 10, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;github-cloud.s3.amazonaws.com. IN      A

;; ANSWER SECTION:
github-cloud.s3.amazonaws.com. 20461 IN CNAME   s3-1-w.amazonaws.com.
s3-1-w.amazonaws.com.   1       IN      CNAME   s3-w.us-east-1.amazonaws.com.
s3-w.us-east-1.amazonaws.com. 1 IN      A       54.231.229.33
s3-w.us-east-1.amazonaws.com. 1 IN      A       52.216.86.163
s3-w.us-east-1.amazonaws.com. 1 IN      A       3.5.21.159
s3-w.us-east-1.amazonaws.com. 1 IN      A       52.217.131.169
s3-w.us-east-1.amazonaws.com. 1 IN      A       52.217.193.201
s3-w.us-east-1.amazonaws.com. 1 IN      A       3.5.25.31
s3-w.us-east-1.amazonaws.com. 1 IN      A       3.5.6.11
s3-w.us-east-1.amazonaws.com. 1 IN      A       52.217.85.116

;; Query time: 23 msec
;; SERVER: 8.8.8.8#53(8.8.8.8) (UDP)
;; WHEN: Tue Jul 29 15:20:52 MDT 2025
;; MSG SIZE  rcvd: 236

Another good test is nat.travisci.net

Are you using NetBird Cloud?
No and N/A

NetBird version

0.52.1

Is any other VPN software installed?

no

Originally created by @hurricanehrndz on GitHub (Jul 29, 2025). Original GitHub issue: https://github.com/netbirdio/netbird/issues/4242 **Describe the problem** The built in DNS server does not [scrub messages](https://github.com/coredns/coredns/blob/master/request/request.go#L216) prior to writing replies to clients. Client by default will communicate the buffer size and the server should either [truncate or compress messages](https://github.com/miekg/dns/blob/master/msg_truncate.go) when the buffer has overflown, the [message is simply written](https://github.com/netbirdio/netbird/blob/main/client/internal/dns/upstream.go#L153) via the [dns pkg](https://github.com/miekg/dns/blob/master/server.go#L748). Default UDP buffer by some client is 512, when supporting edns0 it is usually 1232. The server should also support TCP for client like dig that will retry with TCP when messages are truncated. https://datatracker.ietf.org/doc/html/rfc7766 **To Reproduce** Steps to reproduce the behavior: ```❯ dig @100.122.255.254 +noedns +comments +bufsize=512 github-cloud.s3.amazonaws.com ; <<>> DiG 9.20.9 <<>> @100.122.255.254 +noedns +comments +bufsize=512 github-cloud.s3.amazonaws.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20515 ;; flags: qr rd ra; QUERY: 1, ANSWER: 10, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;github-cloud.s3.amazonaws.com. IN A ;; ANSWER SECTION: github-cloud.s3.amazonaws.com. 24095 IN CNAME s3-1-w.amazonaws.com. s3-1-w.amazonaws.com. 131 IN CNAME s3-w.us-east-1.amazonaws.com. s3-w.us-east-1.amazonaws.com. 2 IN A 52.216.210.145 s3-w.us-east-1.amazonaws.com. 2 IN A 52.217.119.1 s3-w.us-east-1.amazonaws.com. 2 IN A 52.216.107.124 s3-w.us-east-1.amazonaws.com. 2 IN A 3.5.16.19 s3-w.us-east-1.amazonaws.com. 2 IN A 3.5.27.209 s3-w.us-east-1.amazonaws.com. 2 IN A 16.15.176.156 s3-w.us-east-1.amazonaws.com. 2 IN A 3.5.29.79 s3-w.us-east-1.amazonaws.com. 2 IN A 52.217.125.73 ;; Query time: 31 msec ;; SERVER: 100.122.255.254#53(100.122.255.254) (UDP) ;; WHEN: Tue Jul 29 15:16:46 MDT 2025 ;; MSG SIZE rcvd: 535 ``` **Expected behavior** expected either TC flag to be set and retry to occur on TCP, but netbird lacks a TCP listener, or for the message above to have been compressed. In all reality the example above should have had compression enable, as most upstream servers would have done so. i.e. ``` ❯ dig @8.8.8.8 +noedns +comments +bufsize=512 github-cloud.s3.amazonaws.com ; <<>> DiG 9.20.9 <<>> @8.8.8.8 +noedns +comments +bufsize=512 github-cloud.s3.amazonaws.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4052 ;; flags: qr rd ra; QUERY: 1, ANSWER: 10, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;github-cloud.s3.amazonaws.com. IN A ;; ANSWER SECTION: github-cloud.s3.amazonaws.com. 20461 IN CNAME s3-1-w.amazonaws.com. s3-1-w.amazonaws.com. 1 IN CNAME s3-w.us-east-1.amazonaws.com. s3-w.us-east-1.amazonaws.com. 1 IN A 54.231.229.33 s3-w.us-east-1.amazonaws.com. 1 IN A 52.216.86.163 s3-w.us-east-1.amazonaws.com. 1 IN A 3.5.21.159 s3-w.us-east-1.amazonaws.com. 1 IN A 52.217.131.169 s3-w.us-east-1.amazonaws.com. 1 IN A 52.217.193.201 s3-w.us-east-1.amazonaws.com. 1 IN A 3.5.25.31 s3-w.us-east-1.amazonaws.com. 1 IN A 3.5.6.11 s3-w.us-east-1.amazonaws.com. 1 IN A 52.217.85.116 ;; Query time: 23 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) (UDP) ;; WHEN: Tue Jul 29 15:20:52 MDT 2025 ;; MSG SIZE rcvd: 236 ``` Another good test is nat.travisci.net **Are you using NetBird Cloud?** No and N/A **NetBird version** 0.52.1 **Is any other VPN software installed?** no
saavagebueno added the triage-needed label 2026-08-05 01:17:19 -04:00
Author
Owner

@hurricanehrndz commented on GitHub (Jul 29, 2025):

I just did more reading of the code and netbird itself retries with TCP when the buffer overflows https://github.com/netbirdio/netbird/blob/main/client/internal/dns/upstream.go#L350

But it ignores buffer size when answering

Image
<!-- gh-comment-id:3134181075 --> @hurricanehrndz commented on GitHub (Jul 29, 2025): I just did more reading of the code and netbird itself retries with TCP when the buffer overflows https://github.com/netbirdio/netbird/blob/main/client/internal/dns/upstream.go#L350 But it ignores buffer size when answering <img width="933" height="505" alt="Image" src="https://github.com/user-attachments/assets/616946af-e34f-4920-a013-a4a87fb86b0f" />
Author
Owner

@hurricanehrndz commented on GitHub (Jul 29, 2025):

Is this because of the assumption that since all resolution should be local 64KB is the effective space you have?

<!-- gh-comment-id:3134184972 --> @hurricanehrndz commented on GitHub (Jul 29, 2025): Is this because of the assumption that since all resolution should be local 64KB is the effective space you have?
Author
Owner

@hurricanehrndz commented on GitHub (Jul 29, 2025):

You might wonder why this is an issue, it is mainly because DNS security tools such as Cisco's Umbrella and/or Cloudflare's Warp expect any and all upstream servers to behave. Otherwise macOS built in DNS client will get truncated response such as

❯ dns-sd -t 1 -q nat.travisci.net
DATE: ---Tue 29 Jul 2025---
20:37:36.839  ...STARTING...
Timestamp     A/R  Flags         IF  Name                          Type   Class  Rdata
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     35.229.88.230
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     35.231.37.215
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     35.196.218.48
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     34.66.178.120
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     35.243.167.131
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     34.75.144.248
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     35.196.158.85
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     34.74.15.71
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     35.192.136.167
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     35.184.226.236
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     34.74.79.111
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     35.188.73.34
20:37:36.971  Add  3              0  nat.travisci.net.             Addr   IN     207.254.16.38
20:37:36.971  Add  2              0  nat.travisci.net.             Addr   IN     34.66.200.49

Image vs disconnected Image

Please let me know if you need more info

<!-- gh-comment-id:3134684775 --> @hurricanehrndz commented on GitHub (Jul 29, 2025): You might wonder why this is an issue, it is mainly because DNS security tools such as Cisco's Umbrella and/or Cloudflare's Warp expect any and all upstream servers to behave. Otherwise macOS built in DNS client will get truncated response such as ``` ❯ dns-sd -t 1 -q nat.travisci.net DATE: ---Tue 29 Jul 2025--- 20:37:36.839 ...STARTING... Timestamp A/R Flags IF Name Type Class Rdata 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 35.229.88.230 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 35.231.37.215 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 35.196.218.48 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 34.66.178.120 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 35.243.167.131 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 34.75.144.248 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 35.196.158.85 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 34.74.15.71 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 35.192.136.167 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 35.184.226.236 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 34.74.79.111 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 35.188.73.34 20:37:36.971 Add 3 0 nat.travisci.net. Addr IN 207.254.16.38 20:37:36.971 Add 2 0 nat.travisci.net. Addr IN 34.66.200.49 ``` <img width="852" height="373" alt="Image" src="https://github.com/user-attachments/assets/f497b37c-46ad-45c8-9df4-e87f4c87b1e9" /> vs disconnected <img width="741" height="1258" alt="Image" src="https://github.com/user-attachments/assets/602f9b50-eed8-4523-97a2-a46692aa9722" /> Please let me know if you need more info
Author
Owner

@lixmal commented on GitHub (Apr 8, 2026):

Addressed by #5758 which adds TCP DNS support for the local listener in userspace mode, released in v0.68.0.

<!-- gh-comment-id:4205340194 --> @lixmal commented on GitHub (Apr 8, 2026): Addressed by #5758 which adds TCP DNS support for the local listener in userspace mode, released in v0.68.0.
Sign in to join this conversation.
No Label triage-needed
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#8308