A Zodiac extension for adding secure HTTP headers to your application.
com.github.brettatoms/zodiac-headers {:mvn/version "0.1.0"}
(ns myapp
(:require [zodiac.core :as z]
[zodiac.ext.headers :as headers]))
(def routes
["/" {:get (fn [_] {:status 200 :body "Hello!"})}])
;; Uses the 'web' preset by default
(z/start {:routes routes
:extensions [(headers/init)]})
Five presets are provided based on OWASP recommendations:
web (default)Standard web application headers:
(headers/init {:headers headers/web})
X-Content-Type-Options: nosniffX-Frame-Options: DENYReferrer-Policy: strict-origin-when-cross-originContent-Security-Policy: default-src 'self'Permissions-Policy: geolocation=(), camera=(), microphone=()Cross-Origin-Opener-Policy: same-originsecure-webWeb headers + HSTS for HTTPS:
(headers/init {:headers headers/secure-web})
Adds: Strict-Transport-Security: max-age=63072000; includeSubDomains
apiMinimal headers for JSON APIs:
(headers/init {:headers headers/api})
X-Content-Type-Options: nosniffReferrer-Policy: strict-origin-when-cross-originsecure-apiAPI headers + HSTS:
(headers/init {:headers headers/secure-api})
strictMaximum security headers:
(headers/init {:headers headers/strict})
Includes all security headers plus header removal (Server, X-Powered-By).
Presets are just maps. Use standard Clojure functions to customize:
(headers/init {:headers (assoc headers/web
:strict-transport-security "max-age=31536000")})
(headers/init {:headers (dissoc headers/web :x-frame-options)})
(headers/init {:headers (assoc headers/web
:x-frame-options "SAMEORIGIN")})
(headers/init {:headers (merge headers/api
{:content-security-policy "default-src 'none'"})})
(headers/init {:headers {:x-content-type-options "nosniff"
:referrer-policy "no-referrer"}})
Use :remove as the value to strip headers from responses:
(headers/init {:headers {:x-content-type-options "nosniff"
:server :remove
:x-powered-by :remove}})
default-src 'self' is a starting point. Most apps need customization.secure-web or secure-api if your site is fully HTTPS. HSTS can break local development.DENY by default. Use SAMEORIGIN if you need to embed your app in iframes on the same domain.MIT License - see LICENSE
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |