From 9216710dda68d0f2b58926cb78bfdb3ee4a39829 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Sat, 23 May 2026 07:07:24 +0200 Subject: [PATCH] X-Forwarded-For should only contain the IP address https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For --- src/web/proxyhttp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/web/proxyhttp.rs b/src/web/proxyhttp.rs index ddff402..771f13f 100644 --- a/src/web/proxyhttp.rs +++ b/src/web/proxyhttp.rs @@ -229,11 +229,11 @@ impl ProxyHttp for LB { } async fn upstream_request_filter(&self, session: &mut Session, upstream_request: &mut RequestHeader, ctx: &mut Self::CTX) -> Result<()> { - if let Some(client_ip) = session.client_addr() { + if let Some(ip) = session.client_addr().and_then(|a| a.as_inet()).map(|i| i.ip()) { IP_BUFFER.with(|buffer| { let mut buf = buffer.borrow_mut(); buf.clear(); - write!(buf, "{}", client_ip).unwrap_or(()); + write!(buf, "{}", ip).unwrap_or(()); upstream_request.append_header("X-Forwarded-For", buf.as_str()).unwrap_or(false); }); }