1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

reverseproxy: Fix parsing of source IP in case it's an ipv6 address (#5569)

This commit is contained in:
Corin Langosch 2023-06-12 17:35:22 +02:00 committed by GitHub
parent 56af1ceb32
commit 2ddb717144
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -637,7 +637,13 @@ func (h Handler) prepareRequest(req *http.Request, repl *caddy.Replacer) (*http.
addrPort, err := netip.ParseAddrPort(address) addrPort, err := netip.ParseAddrPort(address)
if err != nil { if err != nil {
// OK; probably didn't have a port // 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} proxyProtocolInfo := ProxyProtocolInfo{AddrPort: addrPort}
caddyhttp.SetVar(req.Context(), proxyProtocolInfoVarKey, proxyProtocolInfo) caddyhttp.SetVar(req.Context(), proxyProtocolInfoVarKey, proxyProtocolInfo)