Skip to content

fix: auto-bracket bare IPv6 literals in serpent.URL.Set#33

Draft
rowansmithau wants to merge 1 commit into
mainfrom
rowan/serpent_ipv6_auto_bracket
Draft

fix: auto-bracket bare IPv6 literals in serpent.URL.Set#33
rowansmithau wants to merge 1 commit into
mainfrom
rowan/serpent_ipv6_auto_bracket

Conversation

@rowansmithau

@rowansmithau rowansmithau commented Jul 23, 2026

Copy link
Copy Markdown
Member

An attempt to solve 27266 in coder/coder.

net/url.Parse cannot disambiguate an unbracketed IPv6 host from its trailing port (e.g. "http://2600:2222::22:8080" fails with "invalid port ... after host"). This breaks CODER_DERP_SERVER_RELAY_URL when set from a Kubernetes IPv6 pod IP.

This adds detection of IPv6 address add brackets them accordingly.

Tested on a local build of coder with a replace directive.

➜  Downloads CODER_DERP_SERVER_RELAY_URL="http://2407:8800:bcc2:7700:81d:fc1b:cec5:8064:8080" ./coder-ipv6-test server \
  --http-address :3000 \
  --access-url http://192.168.51.15:3000
Coder v2.35.2-devel+80f8e4f624 - Your Self-Hosted Remote Development Platform
➜  Downloads CODER_DERP_SERVER_RELAY_URL="http://[2407:8800:bcc2:7700:81d:fc1b:cec5:8064]:8080" ./coder-ipv6-test server \
  --http-address :3000 \
  --access-url http://192.168.51.15:3000
Coder v2.35.2-devel+80f8e4f624 - Your Self-Hosted Remote Development Platform

I ran go mod edit -replace github.com/coder/serpent=github.com/coder/serpent@rowan/serpent_ipv6_auto_bracket && go mod tidy followed by make test on coder's main branch and those tests still passed.

net/url.Parse cannot disambiguate an unbracketed IPv6 host from its
trailing port (e.g. "http://2600:2222::22:8080" fails with
"invalid port ... after host"). This breaks CODER_DERP_SERVER_RELAY_URL
when set from a Kubernetes IPv6 pod IP (coder/coder#27266).

Detect this shape in the authority component and wrap the IPv6
literal in brackets before delegating to url.Parse. IPv4 hosts,
hostnames, and already-bracketed IPv6 hosts are left untouched, so
this is a strict superset of previously-accepted input.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant