1 unstable release
0.1.0 | Jan 5, 2024 |
---|
#66 in #http-header
253 downloads per month
Used in 2 crates
62KB
833 lines
helmet-core
- Security Middleware for popular Rust web frameworks
ntex-helmet
is a security middleware for thentex
web framework.actix-web-helmet
is a security middleware for theactix-web
web framework. Coming Soonrocket-helmet
is a security middleware for therocket
web framework. Coming Soonwarp-helmet
is a security middleware for thewarp
web framework. Coming Soonaxum-helmet
is a security middleware for theaxum
web framework.
It works by setting HTTP headers for you. These headers can help protect your app from some well-known web vulnerabilities:
- Cross-Origin-Embedder-Policy
- Cross-Origin-Opener-Policy
- Cross-Origin-Resource-Policy
- Origin-Agent-Cluster
- Referrer-Policy
- Strict-Transport-Security
- X-Content-Type-Options
- X-DNS-Prefetch-Control
- X-Download-Options
- X-Frame-Options
- X-Permitted-Cross-Domain-Policies
- X-XSS-Protection
- X-Powered-By
- Content-Security-Policy
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.