Skip to content

Security Headers Middleware #47

Description

@fiandev

Description:
Create a built-in middleware that automatically sets essential HTTP security headers on every response. This is a critical security feature that modern frameworks should provide out-of-the-box.

Proposed Headers:

  • Content-Security-Policy - Prevents XSS attacks
  • X-Frame-Options - Prevents clickjacking
  • X-Content-Type-Options - Prevents MIME-sniffing
  • X-XSS-Protection - XSS filter (legacy but still useful)
  • Strict-Transport-Security (HSTS) - Enforces HTTPS
  • Referrer-Policy - Controls referrer information

Proposed API:

import AppRoutes from './modules/app/AppRoutes';
import { defineBootstrap } from 'gaman';

defineBootstrap(async (app) => {
  app.mount(appRoutes, {
    security: {
      contentSecurityPolicy: "default-src 'self'",
      xFrameOptions: 'DENY',
      hsts: true, // max-age in seconds
    }
  });
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions