From 2ddb7171440c1045dececb9d7102a8bc28d8708d Mon Sep 17 00:00:00 2001 From: Corin Langosch Date: Mon, 12 Jun 2023 17:35:22 +0200 Subject: reverseproxy: Fix parsing of source IP in case it's an ipv6 address (#5569) --- modules/caddyhttp/reverseproxy/reverseproxy.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'modules/caddyhttp') 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) -- cgit v1.2.3