[edge] Proxy socket: a Unix peer has no address in Pingora, so the socket is recognised by its listening side

This commit is contained in:
2026-11-10 21:30:26 +01:00
parent c7eb190c3b
commit c4777a5477
+7 -2
View File
@@ -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<IpAddr> {
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)