Skip to content

Commit

Permalink
httpcaddyfile: Fix incorrect handling of IPv6 bind addresses (#4532)
Browse files Browse the repository at this point in the history
The `net.JoinHostPort()` function has some naiive logic for handling IPv6, it just checks if the host part has a `:` and if so it wraps the host part with `[ ]` but this causes our network type prefix to get wrapped as well, which is invalid for `caddy.NetworkAddress`. Instead, we can just concatenate the host and port manually here to avoid this side-effect.
  • Loading branch information
francislavoie committed Jan 18, 2022
1 parent 1a7a78a commit 93a7a45
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion caddyconfig/httpcaddyfile/addresses.go
Expand Up @@ -223,7 +223,7 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str
if err == nil && addr.IsUnixNetwork() {
listeners[host] = struct{}{}
} else {
listeners[net.JoinHostPort(host, lnPort)] = struct{}{}
listeners[host+":"+lnPort] = struct{}{}
}
}

Expand Down
29 changes: 29 additions & 0 deletions caddytest/integration/caddyfile_adapt/bind_ipv6.txt
@@ -0,0 +1,29 @@
example.com {
bind tcp6/[::]
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
"tcp6/[::]:443"
],
"routes": [
{
"match": [
{
"host": [
"example.com"
]
}
],
"terminal": true
}
]
}
}
}
}
}

0 comments on commit 93a7a45

Please sign in to comment.