GithubHelp home page GithubHelp logo

baitcenter / actix-csrf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from snoozetime/actix-csrf

0.0 1.0 0.0 32 KB

Middleware for CSRF protection for actix-web

License: Apache License 2.0

Rust 100.00%

actix-csrf's Introduction

actix-csrf

Middleware for Actix-web 1.0 to add CSRF attack mitigation. It is early work so please don't hesitate to contribute.

Mitigation techniques

Right now, the middleware will used token-based mitigations. In particular, double token submit is implemented and I'd like to also use the synchronizer token pattern.

Please take a look at https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.md for a lot of details. In particular, it describes the conditions in which Double submit cookie is safer:

So, unless you are sure that your subdomains are fully secured and only accept HTTPS connections (we believe it’s difficult to guarantee at large enterprises), you should not rely on the Double Submit Cookie technique as a primary mitigation for CSRF.

Usage

Basic usage is

use actix_csrf::Csrf;
use actix_web::{HttpServer, web, App, HttpResponse};

// switch off during testing to not check CSRF
let enabled = true;

let server = HttpServer::new(move || {
    App::new()
        .wrap(Csrf::new().enable(enabled))
        .service(web::resource("/")
            // by default will not check get
            .route(web::get().to(|| HttpResponse::Ok()))
            // by default will check post
            .route(web::post().to(|| HttpResponse::Ok())))
});

Roadmap

  • More flexibility (add whitelist, other ways of extracting token)
  • Implement synchronizer token pattern. This will most likely need the session middleware in combinaison with a template language such as askama.
  • More testing

License

Licensed under either of

at your option.

Contribution

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.

actix-csrf's People

Contributors

snoozetime avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.