Iron middleware providing CSRF protection.
```rust extern crate irondsccsrf; extern crate iron;
use irondsccsrf::Csrf; use iron::AroundMiddleware; use iron::prelude::*; use iron::status;
fn main() { let csrf = Csrf::new(extract_token);
let handler = csrf.around(Box::new(index));
// Make and start the server
Iron::new(handler).http("localhost:8080").unwrap();
}
fn extract_token(request: &Request) -> Option
request.url.query().map(|x| x.to_owned())
}
fn index(request: &mut Request) -> IronResult
iron-dsc-csrf
is an Iron middleware that provides protection against Cross-Site
Request Forgery attacks. For more information on CSRF attacks, see OWASP's,
and Wikipedia's articles.
This middleware uses an approach called Double Submit Cookie, where a random
token is generated and stored client-side in a cookie. Any time an unsafe HTTP
method (ex. POST
, PUT
, etc) is used, the submission must also include the
token from the cookie. OWASP has a more detailed description.