v0.34.0_12

This commit is contained in:
Mateusz Gruszczyński committed 2026-10-18 10:38:06 +02:00
1 parent 9f20d5195e
commit 929854898f
16 files changed
+186 -285

No files matched your search

+7 -14
View File
@@ -100,7 +100,7 @@ fn cloudflare_peer(peer: SocketAddr) -> bool {
/// Return CF-Connecting-IP only when the TCP peer itself is in Cloudflare's
/// published edge ranges. The header is otherwise untrusted user input.
pub fn cloudflare_client_ip(headers: &HeaderMap, peer: SocketAddr) -> Option<IpAddr> {
if !headers.contains_key("cf-connecting-ip") || !cloudflare_peer(peer) {
if !cloudflare_peer(peer) {
return None;
}
let mut values = headers.get_all("cf-connecting-ip").iter();
@@ -120,7 +120,7 @@ pub fn cloudflare_client_ip(headers: &HeaderMap, peer: SocketAddr) -> Option<IpA
/// Return a trusted ISO country code supplied by Cloudflare. `CF-IPCountry` is
/// accepted only from a Cloudflare edge and only as one two-letter code.
pub fn cloudflare_country(headers: &HeaderMap, peer: SocketAddr) -> Option<String> {
if !headers.contains_key("cf-ipcountry") || !cloudflare_peer(peer) {
if !cloudflare_peer(peer) {
return None;
}
let mut values = headers.get_all("cf-ipcountry").iter();
@@ -319,18 +319,11 @@ impl Compiled {
values,
});
}
let mut proxy_chain = chain(incoming).unwrap_or_default();
// No forwarded hops: borrow the actual peer from the stack instead of
// allocating a one-element Vec on every trusted-proxy request.
let direct_peer = [peer_ip];
let ips: &[IpAddr] = if proxy_chain.is_empty() {
&direct_peer
} else {
proxy_chain.push(peer_ip);
// Discard untrusted upstream prefixes without shifting the Vec.
let first = proxy_chain.iter().rposition(|ip| !self.trusted(*ip)).unwrap_or(0);
&proxy_chain[first..]
};
let mut ips = chain(incoming).unwrap_or_default();
ips.push(peer_ip);
// Discard everything left of the first untrusted hop walking from us.
let first = ips.iter().rposition(|ip| !self.trusted(*ip)).unwrap_or(0);
ips.drain(..first);
let client_ip = ips[0];
let mut scheme = if tls { "https" } else { "http" };
if trusted_peer