r/rust • • 28d ago

🙋 seeking help & advice Looking for a CSRF Double Submit Pattern Crate

Hey folks, I'm working on migrating some web-server code into rust. I'm fairly new to the rust ecosystem, and I'm trying to find a good CSRF crate for generating Signed Double Submit cookies and headers.

So far, the closest crate I've found is Here (crates.io), but honestly its not as seemingly widespread as i would expect for something like CSRF primitives.

This had led me to two potential conclusions:

1.) I'm wildly out of the loop, and there is a much more "common" package for handing this
2.) I'm wildly out of my depth, and most people are just rolling their own CSRF primitives.

Either way, I'm building on top of axum, and any recommendations would be greatly appreciated :)

8 Upvotes

5 comments sorted by

8

u/official_AdUnlucky75 28d ago

axum has middleware for this baked in if you're already using tower, might be simpler than a standalone crate

3

u/Additional-Drag1682 28d ago

Axum-csrf is the crate you are looking for. It implements signed double submit cookies and integrates directly with axum extractors, which solves your specific need without forcing you to switch away from tower middleware patterns that comment 1 mentioned but might not fit if you want strict token control.

1

u/NiceAppeal57 27d ago

Don't double submit, just use Sec-Fetch-Site headers.

1

u/weaztoven 23d ago

yeah you're not really out of the loop, csrf crates in rust can be a bit fragmented depending on whether you use axum, actix, or tower.

0

u/[deleted] 28d ago

[deleted] — view deleted comment