#http-header #security #header #tower #http #service #https

tower-helmet

Helps with securing your tower servers with various HTTP headers

4 releases (2 breaking)

0.3.0 Jan 29, 2024
0.2.1 Nov 9, 2022
0.2.0 Apr 12, 2022
0.1.0 Dec 22, 2021

#41 in #https

Download history 104/week @ 2024-07-01 42/week @ 2024-07-08 68/week @ 2024-07-15 43/week @ 2024-07-22 90/week @ 2024-07-29 375/week @ 2024-08-05 573/week @ 2024-08-12 724/week @ 2024-08-19 683/week @ 2024-08-26 651/week @ 2024-09-02 488/week @ 2024-09-09 81/week @ 2024-09-16 65/week @ 2024-09-23 58/week @ 2024-09-30 36/week @ 2024-10-07 53/week @ 2024-10-14

215 downloads per month

MIT license

31KB
542 lines

tower-helmet

Crates.io Documentation License

this is still very work in progress

a port of the beautiful helmet.js in the javascript world.

tower-helmet helps you secure your tower server by setting various HTTP headers. It's not a silver bullet, but it can help!

You can find a list of all available headers under the [header] module. By default (with HelmetLayer::default) all of them are enabled. Please take a good look at [ContentSecurityPolicy]. Most of the time you will need to adapt this one to your needs.

Examples

use tower_helmet::header::{ContentSecurityPolicy, ExpectCt, XFrameOptions};
use tower_helmet::HelmetLayer;

// default layer with all security headers active
let layer = HelmetLayer::with_defaults();

// default layer with customizations applied
let mut directives = HashMap::new();
directives.insert("default-src", vec!["'self'", "https://example.com"]);
directives.insert("img-src", vec!["'self'", "data:", "https://example.com"]);
directives.insert("script-src", vec!["'self'", "'unsafe-inline'", "https://example.com"]);
let csp = ContentSecurityPolicy {
  directives,
  ..Default::default()
};

let layer = HelmetLayer::with_defaults().enable(csp);

// completely blank layer, selectively enable and add headers
let layer = HelmetLayer::blank()
  .enable(XFrameOptions::SameOrigin)
  .enable(ExpectCt::default());

Dependencies

~1.5MB
~26K SLoC