package middleware import ( "net/http" ) // SecurityHeaders middleware adds standard security headers to HTTP responses. // This provides defense-in-depth against various web attacks. func SecurityHeaders(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Prevent MIME type sniffing w.Header().Set("X-Content-Type-Options", "nosniff") // Prevent clickjacking w.Header().Set("X-Frame-Options", "DENY") // XSS protection (legacy, but still useful for older browsers) w.Header().Set("X-XSS-Protection", "1; mode=block") // Control referrer information w.Header().Set("Referrer-Policy", "strict-origin-when-cross-origin") // Restrict browser features w.Header().Set("Permissions-Policy", "geolocation=(), microphone=(), camera=()") next.ServeHTTP(w, r) }) }