diff --git a/crates/edge/src/proxy.rs b/crates/edge/src/proxy.rs index a13ea89..d22118e 100644 --- a/crates/edge/src/proxy.rs +++ b/crates/edge/src/proxy.rs @@ -91,8 +91,13 @@ fn canonical(ip: IpAddr) -> IpAddr { /// construction: only the socket's owner and group can connect to it, so its peer is trusted /// and its `X-Forwarded-For` names the client. With no usable entry there is no address. pub fn client_ip(session: &Session, trusted: &[IpAddr]) -> Option { - let addr = session.client_addr()?; - let peer = addr.as_inet().map(|a| canonical(a.ip())); + // A Unix-socket peer is unnamed, so Pingora has no client address for it; the listening + // side (the proxy socket's path) is what tells the two apart. + let peer = match session.client_addr().and_then(|a| a.as_inet()) { + Some(a) => Some(canonical(a.ip())), + None if session.server_addr().is_some_and(|a| a.as_inet().is_none()) => None, + None => return None, + }; let trusted_ip = |ip: &IpAddr| trusted.iter().any(|t| canonical(*t) == *ip); if let Some(p) = peer && !trusted_ip(&p)