Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 01:45 UTC
reverseproxy: Fix parsing of source IP in case it's an ipv6 address (#5569)
Corin Langosch committed
Jun 12, 2023 at 17:35 UTC
2ddb7171440c1045dececb9d7102a8bc28d8708d
1 file changed
+7
-1
modules/caddyhttp/reverseproxy/reverseproxy.go
+7
-1
@@ -637,7 +637,13 @@ func (h Handler) prepareRequest(req *http.Request, repl *caddy.Replacer) (*http.
637
addrPort, err := netip.ParseAddrPort(address)
638
if err != nil {
639
// OK; probably didn't have a port
640
- addrPort, _ = netip.ParseAddrPort(address + ":0")
640
+ addr, err := netip.ParseAddr(address)
641
+ if err != nil {
642
+ // Doesn't seem like a valid ip address at all
643
+ } else {
644
+ // Ok, only the port was missing
645
+ addrPort = netip.AddrPortFrom(addr, 0)
646
+ }
647
}
648
proxyProtocolInfo := ProxyProtocolInfo{AddrPort: addrPort}
649
caddyhttp.SetVar(req.Context(), proxyProtocolInfoVarKey, proxyProtocolInfo)