Skip to content

ts_control_serde: handle unicode escapes in Resolver - #418

Open
dylan-tailscale wants to merge 1 commit into
mainfrom
dylan/dns-escaping
Open

dylan-tailscale wants to merge 1 commit into
mainfrom
dylan/dns-escaping

Conversation

@dylan-tailscale

@dylan-tailscale dylan-tailscale commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Updates ResolverAddr to use alloc::string::String instead of &'a str in its variants, allowing DoH/DoT/WireGuard DNS resolver addresses to contain Unicode escapes without panicking. Adds a fake NextDNS address with escaped ampersands to map_response.json so test_map_response_parse to confirm the fix.

The control plane escapes ampersands in JSON that it sends as \u0026, which affects NextDNS users with per-device configuration profiles on their tailnet, as their DoH URLs contain ampersands. serde_json can't deserialize this without mutating it, leading to "expected a borrowed string" panics that kill the control runner. Moving to alloc::string::String lets serde_json mutate a ResolverAddr's JSON representation if necessary to deserialize it.

This originally used Cow<'a, &str>, but @npry reminded me that Cow<'a, &str> unconditionally allocates on deserialization anyway, so we might as well go with alloc::string::String. To avoid unnecessary allocation, we'll need to come up with an approach/custom types to allocate only when necessary to decode, since we'll need this in way more fields than just DNS-related ones. Putting this PR up to fix the issue while we cook up a different solution; opened #420 to track developing a better approach.

Closes #400.

Updates ResolverAddr to use alloc::string::String instead of &'a str in its variants, allowing DoH/DoT/WireGuard DNS resolver addresses to contain Unicode escapes without panicking. Adds a fake NextDNS address with escaped ampersands to map_response.json so test_map_response_parse can confirm the fix.

The control plane escapes ampersands in JSON that it sends as "\u0026", which affects NextDNS users with per-device configuration profiles on their tailnet, as their DoH URLs contain ampersands. serde_json can't deserialize this in-place, leading to "expected a borrowed string" panics that kill the control runner. Moving to alloc::string::String allows the field to be mutated during deserialization. I originally went for Cow<'a, str> to avoid the unconditional allocation, but apparently a Cow becomes an unconditional allocation on deserialization, so we gain nothing over an alloc::string::String.

Signed-off-by: Dylan Bargatze <dylan@tailscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ts_control_serde: netmap deserialization fails on a peer's NextDNS split-DNS URL field

1 participant