Expand description
Bearer-token authentication, rate limiting, and security middlewares.
Structs§
- Auth
State - Shared authentication state holding the optional Bearer token for the MCP server.
- Rate
Limiter State - Lock-free token-bucket rate limiter using monotonic timestamps for smooth refill.
Functions§
- constant_
time_ eq - Constant-time byte comparison to prevent timing side-channel attacks on token validation.
- default_
rate_ limiter - Create a rate limiter with the default capacity of
DEFAULT_RATE_LIMITrequests per second. - dns_
rebinding_ guard - Axum middleware that blocks DNS rebinding attacks.
- generate_
token - Generate a random UUID v4 token suitable for Bearer authentication.
- is_
allowed_ origin - Returns
trueiforigin(from the HTTPOriginheader) is anhttp/httpslocalhost origin. - is_
localhost_ host - Returns
trueifhost(from the HTTPHostheader) resolves to a localhost address. - origin_
guard - Axum middleware that blocks requests a web page made a browser send.
- rate_
limit - Axum middleware that rejects requests with 429 when the token bucket is exhausted.
- require_
auth - Axum middleware that validates the
Authorization: Bearer <token>header againstAuthState. - security_
headers - Axum middleware that sets security-hardening response headers on every response.