| Crates.io | tower-sec-fetch |
| lib.rs | tower-sec-fetch |
| version | 0.1.2 |
| created_at | 2025-05-24 13:56:27.834215+00 |
| updated_at | 2025-05-25 08:30:38.532377+00 |
| description | Rust Tower middleware to validate an HTTP request's Fetch Metadata |
| homepage | |
| repository | https://github.com/MatteoJoliveau/tower-sec-fetch |
| max_upload_size | |
| id | 1687453 |
| size | 74,683 |
Cookieless CSRF protection library
This crate provides a Tower middleware that implements Cross-Site-Request-Forgery protection by validating the Fetch Metadata headers of the incoming HTTP request. It does not require cookies, or signing keys, or tokens.
If you're looking for a classic CSRF cookie implementation, try [tower-surf] instead.
Check the docs for more information and usage examples.
For a more in-depth explanation of the problem CSRF protection is trying to solve, and why using signed cookies is not always the best solution, refer to this excellent writeup by Filippo Valsorda.
In short, this crate allows to protect web resources from cross-site inclusion and abuse by validating the Fetch Metadata headers and ensuring that only "safe" cross-site requests are allowed. In this context, "safe" means:
<object> or <iframe>.The examples folder contains various examples of how to use tower-sec-fetch:
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.