pub struct TrustedProxyConfig {
pub trusted_proxies: Vec<IpAddr>,
}Expand description
Opt-in trusted-proxy allowlist for the HTTP rate limiter.
By default, RateLimitMiddleware keys rate limiting on the real TCP peer
address and never trusts X-Forwarded-For/X-Real-IP — an unauthenticated
client could otherwise send a fresh spoofed value on every request to get a
fresh rate-limit bucket, fully bypassing the limiter. Set this only for
deployments that sit behind a known reverse proxy or load balancer whose
peer address(es) are listed here; requests from any other peer always use
the real peer address regardless of these headers.
§Proxy contract
X-Forwarded-For is read right-to-left and takes precedence over
X-Real-IP when both are present. The trusted proxy must append the
address it saw the connection from to X-Forwarded-For rather than
overwrite it (e.g. nginx’s $proxy_add_x_forwarded_for, or any proxy that
merges into a single header line rather than emitting a new one). Proxies
that instead emit <ip>:<port> or bracketed IPv6 entries are not
supported by this simple allowlist — the walk fails closed on the first
unparseable entry (falls back to X-Real-IP, then the peer address)
rather than skipping it and guessing from what remains. Repeated
X-Forwarded-For header lines are read and treated as one comma-joined
list in line order, per RFC 9110.
Fields§
§trusted_proxies: Vec<IpAddr>Peer addresses (the proxy’s own TCP source address) allowed to supply
X-Forwarded-For/X-Real-IP.
Implementations§
Trait Implementations§
Source§impl Clone for TrustedProxyConfig
impl Clone for TrustedProxyConfig
Source§fn clone(&self) -> TrustedProxyConfig
fn clone(&self) -> TrustedProxyConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TrustedProxyConfig
impl Debug for TrustedProxyConfig
Source§impl Default for TrustedProxyConfig
impl Default for TrustedProxyConfig
Source§fn default() -> TrustedProxyConfig
fn default() -> TrustedProxyConfig
Auto Trait Implementations§
impl Freeze for TrustedProxyConfig
impl RefUnwindSafe for TrustedProxyConfig
impl Send for TrustedProxyConfig
impl Sync for TrustedProxyConfig
impl Unpin for TrustedProxyConfig
impl UnsafeUnpin for TrustedProxyConfig
impl UnwindSafe for TrustedProxyConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more