Provide automatic templates for Referer-Policy, Content-Security-Policy and other related headers

This an extension of Security Headers , in a Caddy-style, make it easy to make is secure, and provide good and secure defaults.

Wouldn’t it be cool if I could just say:

security_template HIGH

and it will:

  1. upgrade all my Cookie requests to Secure; HttpOnly if they miss that.
  2. Set Referer-Policy: no-referrer, strict-origin-when-cross-origin
  3. Remove (not set) Server and Version headers.
  4. Remove any set cookies (i.e. from proxied requests, manual header calls, or from cgi) that do not set Max-Age.
  5. Set X-Frame-Options: SAMEORIGIN // for older browsers that do not support CSP
  6. Strict-Transport-Security: max-age=63072000; // I guess this is already done by Caddy?
  7. X-XSS-Protection: 1; mode=block // for older browsers that do not support CSP
  8. X-Content-Type-Options: nosniff
  9. Remove any Access-Control-Allow-Origin: *, if it is set by accident.
  10. Set X-Content-Security-Policy automatically based on Content-Security-Policy for older browsers.
  11. Set Content-Security-Policy: default-src ‘none’; img-src ‘self’ data: https:; font-src ‘self’ ‘’; object-src ‘none’; script-src ‘self’ ‘unsafe-inline’; style-src ‘self’; frame-ancestors ‘self’; connect-src ‘self’

security_template ULTRA

could have few tweaks.

  1. Reject all cookies in both ways, and clear cookies that are sent by client, unless they are on a whitelist or prefixed with __Secure
  2. Set Referrer-Policy: no-referrer
  3. Set X-Frame-Options: DENY
  4. Strict-Transport-Security: like before, but with “includeSubDomains; preload”
  5. Require configuring Public-Key-Pins: header.
  6. Automatically serve /robots.txt with blocking all crawling.
  7. Even stricter CSP. (no google fonts, no external images, even over https, and no unsafe-inline for scripts). frame-ancestors ‘none’; connect-src ‘none’ , etc.
  8. Require setting up report-uri for CSP.
  9. Require that the proper single Domain is set on Set-Cookie.
  10. Strip Referer from clients, and do not send to cgi scripts.

security_template NONE - do not do any magic, beyond maybe Strict-Transport-Security

security_template NORMAL - disable few things, similar to HIGH, but maybe allow object-src, plugin-types, connect-src, frame-ancestors in CSP (from self only or self + https).

There should be a way to:

  1. Modify CSP manually (i.e. append, or modify existing items on the list).
  2. Remove or set headers manually after setting up the template. Warn if they are redundant with the template!
  3. Version templates. Caddy developers should have a way to upgrade templates to better default in the future, but users should be able to pin to specific template version. I.e. HIGH.1.0
  4. ULTRA would be unstable by design. Non versioned. Sure, it can break the site after upgrade, but well, you opted into it, and better fix your site, or add some whitelisting if you want to be sure it works.

For example it would be nice to have Caddy verify that if CSP has nonce type set, all specific resources does have some nounce set (it doesn’t need to check if they are correct really). I know, it requires some form of HTML parsing, so maybe not really, but it could be a plugin in the future that is enabled by default at ultra level. Just an option and idea.

Another similar option, make sure the cross origin resources (i.e. jquery scripts) do have integrity tags (content hashes), and crossorigin=“anonymous” attributes set. Again, a bit tricky without plugin with some HTML parsing. Again, an idea for the future.

I know this is hard, and far reaching, but I think it might be worth it. Most people do not even know about these headers, and all the semantic behind them.


Low, Medium and High would be my preferred nomenclature

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.