summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorin Langosch <info@corinlangosch.com>2023-06-12 17:35:22 +0200
committerGitHub <noreply@github.com>2023-06-12 09:35:22 -0600
commit2ddb7171440c1045dececb9d7102a8bc28d8708d (patch)
tree44f5df19cf37b48e13179f3f6d1b8c0bd628f2c1
parent56af1ceb328dcec7e29de3c7a1c26c966bed9051 (diff)
reverseproxy: Fix parsing of source IP in case it's an ipv6 address (#5569)
-rw-r--r--modules/caddyhttp/reverseproxy/reverseproxy.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go
index d89d0ac..839c0cc 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -637,7 +637,13 @@ func (h Handler) prepareRequest(req *http.Request, repl *caddy.Replacer) (*http.
addrPort, err := netip.ParseAddrPort(address)
if err != nil {
// OK; probably didn't have a port
- addrPort, _ = netip.ParseAddrPort(address + ":0")
+ addr, err := netip.ParseAddr(address)
+ if err != nil {
+ // Doesn't seem like a valid ip address at all
+ } else {
+ // Ok, only the port was missing
+ addrPort = netip.AddrPortFrom(addr, 0)
+ }
}
proxyProtocolInfo := ProxyProtocolInfo{AddrPort: addrPort}
caddyhttp.SetVar(req.Context(), proxyProtocolInfoVarKey, proxyProtocolInfo)