Skip to content

Security Headers ​

HTTP security headers instruct modern web browsers to activate built-in defenses against clickjacking, MIME sniffing, cross-site scripting, and man-in-the-middle attacks.

HeaderRecommended ValueProtection
Strict-Transport-Securitymax-age=31536000; includeSubDomains; preloadEnforces HTTPS exclusively for 1 year
X-Content-Type-OptionsnosniffDisables MIME type sniffing
X-Frame-OptionsDENYPrevents framing and clickjacking
Referrer-Policystrict-origin-when-cross-originProtects sensitive URL paths from referrers
Content-Security-Policydefault-src 'self'Restricts sources of executable scripts/styles

Server Implementation ​

zig
fn securityHeadersMiddleware(ctx: *httpx.Context) !void {
    ctx.header("Strict-Transport-Security", "max-age=63072000; includeSubDomains; preload");
    ctx.header("X-Content-Type-Options", "nosniff");
    ctx.header("X-Frame-Options", "DENY");
    ctx.header("Referrer-Policy", "strict-origin-when-cross-origin");
    ctx.header("Permissions-Policy", "camera=(), microphone=(), geolocation=()");
    try ctx.next();
}

Released under the MIT License.