pub enum KeyExtractor {
ForwardedIp,
PeerIp,
UserId,
TenantId,
LoginIdentifier,
Header(String),
}Expand description
What to use as the rate-limit bucket key.
Variants§
ForwardedIp
Rate limit by client IP from a trusted reverse proxy header.
Reads X-Real-IP then X-Forwarded-For (first entry). Use this only
when deployed behind a reverse proxy (NGINX, Envoy, ALB, Cloudflare)
that sets these headers from the real peer address and strips
client-supplied values.
Without a trusted proxy, clients can spoof these headers to bypass
rate limiting entirely. For direct-to-client deployments, use
PeerIp instead.
PeerIp
Rate limit by TCP peer address via axum’s ConnectInfo.
Requires Router::into_make_service_with_connect_info::<SocketAddr>()
on your axum server. Falls back to a shared bucket ("unknown") if
ConnectInfo is not available; this is fail-closed (all requests
share one bucket = stricter limiting).
UserId
Rate limit by authenticated user (reads x-user-id header or request extension).
TenantId
Rate limit by tenant (reads x-tenant-id header or request extension).
LoginIdentifier
Rate limit by the login identifier (username/email submitted to a
login route). Reads the RateLimitLoginIdentifier request extension
that the application sets after parsing the login form.
§Why it exists
PeerIp rate-limits the source. LoginIdentifier rate-limits the
target. Without this layer, an attacker rotating IPs (or simply
using a botnet) can issue 5 wrong-password POSTs per known username
and lock the legitimate user out of their account: a per-account
denial-of-service that needs no compromised credentials.
Always pair this with PeerIp on login routes; see the module-level
example.
Falls back to a shared anonymous-bucket sentinel when no extension is present, so a misconfigured route fails closed (one shared bucket) rather than evading the limit.
Header(String)
Rate limit by an arbitrary header value.
Trait Implementations§
Source§impl Clone for KeyExtractor
impl Clone for KeyExtractor
Source§fn clone(&self) -> KeyExtractor
fn clone(&self) -> KeyExtractor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for KeyExtractor
impl RefUnwindSafe for KeyExtractor
impl Send for KeyExtractor
impl Sync for KeyExtractor
impl Unpin for KeyExtractor
impl UnsafeUnpin for KeyExtractor
impl UnwindSafe for KeyExtractor
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.