// SPDX-License-Identifier: AGPL-3.0-or-later package middleware import "net/http" // SecurityHeaders adds security-related HTTP headers to every response. func SecurityHeaders(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { h := w.Header() h.Set("X-Content-Type-Options", "nosniff") h.Set("X-Frame-Options", "DENY") h.Set("Referrer-Policy", "strict-origin-when-cross-origin") h.Set("Permissions-Policy", "camera=(), microphone=(), geolocation=()") // CSP allows inline styles from Pico CSS and scripts from self only. // The 'unsafe-inline' for style-src is needed for Pico CSS. h.Set("Content-Security-Policy", "default-src 'self'; "+ "style-src 'self' 'unsafe-inline'; "+ "img-src 'self' data:; "+ "frame-ancestors 'none'") next.ServeHTTP(w, r) }) }