pub struct TraceRejectionMiddleware { /* private fields */ }Expand description
Middleware that rejects HTTP TRACE requests to prevent Cross-Site Tracing (XST) attacks.
The HTTP TRACE method echoes the request back to the client, which can be exploited in XSS attacks to steal sensitive headers like Authorization or cookies.
§Security Rationale
- TRACE can expose Authorization headers via XSS attacks
- No legitimate use case in modern APIs
- OWASP recommends disabling TRACE
§Example
ⓘ
use fastapi_core::middleware::TraceRejectionMiddleware;
let app = App::builder()
.middleware(TraceRejectionMiddleware::new())
.build();§Behavior
- Returns 405 Method Not Allowed for all TRACE requests
- Logs TRACE attempts as security events (when log_attempts is true)
- Cannot be disabled per-route (intentionally)
Implementations§
Source§impl TraceRejectionMiddleware
impl TraceRejectionMiddleware
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new TRACE rejection middleware with default settings.
By default, logging of TRACE attempts is enabled.
Sourcepub fn log_attempts(self, log: bool) -> Self
pub fn log_attempts(self, log: bool) -> Self
Configure whether to log TRACE attempts.
When enabled, each TRACE request is logged as a security event including the remote IP (if available) and request path.
Trait Implementations§
Source§impl Clone for TraceRejectionMiddleware
impl Clone for TraceRejectionMiddleware
Source§fn clone(&self) -> TraceRejectionMiddleware
fn clone(&self) -> TraceRejectionMiddleware
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TraceRejectionMiddleware
impl Debug for TraceRejectionMiddleware
Source§impl Default for TraceRejectionMiddleware
impl Default for TraceRejectionMiddleware
Source§impl Middleware for TraceRejectionMiddleware
impl Middleware for TraceRejectionMiddleware
Auto Trait Implementations§
impl Freeze for TraceRejectionMiddleware
impl RefUnwindSafe for TraceRejectionMiddleware
impl Send for TraceRejectionMiddleware
impl Sync for TraceRejectionMiddleware
impl Unpin for TraceRejectionMiddleware
impl UnwindSafe for TraceRejectionMiddleware
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
Mutably borrows from an owned value. Read more
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: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).