#web-framework #middleware #security #http-header #helmet #web #rust

helmet-core

HTTP security headers middleware core for various web frameworks

1 unstable release

0.1.0 Jan 5, 2024

#66 in #http-header

Download history 81/week @ 2024-06-08 53/week @ 2024-06-15 108/week @ 2024-06-22 72/week @ 2024-06-29 94/week @ 2024-07-06 144/week @ 2024-07-13 93/week @ 2024-07-20 95/week @ 2024-07-27 111/week @ 2024-08-03 107/week @ 2024-08-10 159/week @ 2024-08-17 83/week @ 2024-08-24 33/week @ 2024-08-31 106/week @ 2024-09-07 47/week @ 2024-09-14 65/week @ 2024-09-21

253 downloads per month
Used in 2 crates

MIT license

62KB
833 lines

helmet-core - Security Middleware for popular Rust web frameworks

crate docs

  • ntex-helmet is a security middleware for the ntex web framework.
  • actix-web-helmet is a security middleware for the actix-web web framework. Coming Soon
  • rocket-helmet is a security middleware for the rocket web framework. Coming Soon
  • warp-helmet is a security middleware for the warp web framework. Coming Soon
  • axum-helmet is a security middleware for the axum web framework.

It works by setting HTTP headers for you. These headers can help protect your app from some well-known web vulnerabilities:

Usage

Add this to your Cargo.toml:

[dependencies]
helmet-core = "0.1"

Implementing the middleware is different for each framework. See the README for your framework of choice to see how to use it.

Example

use helmet_core::Helmet;

let helmet = Helmet::default();

struct MyCustomFrameworkMiddleware(Helmet);

// Imagine this is a middleware for your favorite framework
impl<S, B> Middleware<S, B> for MyCustomFrameworkMiddleware {
    fn start(&self, req: &mut Request<S>) -> Result<Started> {
        self.0.headers.iter().for_each(|(k, v)| {
            req.headers_mut().insert(k, v.clone());
        });
        Ok(Started::Done)
    }
}

License

This project is licensed under the MIT license.

No runtime deps