pub struct CsrfLayer { /* private fields */ }Expand description
Tower Layer that implements the CSRF double-submit cookie pattern.
Apply with Axum’s .layer() call. Use CsrfLayer::default() for a 403 rejection with
the csrf_token cookie and x-csrf-token header, or CsrfLayer::new() to supply a
custom CsrfConfig.
[!NOTE] The middleware inspects only the
x-csrf-tokenheader and thecsrf_tokencookie. Safe methods (GET, HEAD, OPTIONS, TRACE) always pass through; a fresh CSRF cookie is set in the response if one is absent.
§Examples
use axum::{routing::post, Router};
use rune_axum_csrf::CsrfLayer;
let app: Router = Router::new()
.route("/submit", post(|| async { "ok" }))
.layer(CsrfLayer::default());Implementations§
Source§impl CsrfLayer
impl CsrfLayer
Sourcepub fn new(config: CsrfConfig) -> CsrfLayer
pub fn new(config: CsrfConfig) -> CsrfLayer
Creates a CsrfLayer from a custom CsrfConfig.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for CsrfLayer
impl RefUnwindSafe for CsrfLayer
impl Send for CsrfLayer
impl Sync for CsrfLayer
impl Unpin for CsrfLayer
impl UnsafeUnpin for CsrfLayer
impl UnwindSafe for CsrfLayer
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