- Add comprehensive root README with badges, architecture diagram, and setup guide - Update backend README with security middlewares and endpoint documentation - Update frontend README with design system and page structure - Update seeder-api README with generated data and credentials - Add internal module READMEs (middleware, handlers, components) - Document Clean Architecture layers and request flow - Add environment variables reference table
32 lines
1.1 KiB
Go
32 lines
1.1 KiB
Go
package middleware
|
|
|
|
import "net/http"
|
|
|
|
// SecurityHeadersMiddleware adds essential security headers to all responses
|
|
// Based on OWASP guidelines
|
|
func SecurityHeadersMiddleware(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Prevent clickjacking
|
|
w.Header().Set("X-Frame-Options", "DENY")
|
|
|
|
// Prevent MIME sniffing
|
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
|
|
|
// Enable XSS filter
|
|
w.Header().Set("X-XSS-Protection", "1; mode=block")
|
|
|
|
// Only send referrer for same-origin
|
|
w.Header().Set("Referrer-Policy", "strict-origin-when-cross-origin")
|
|
|
|
// Permissions policy (disable potentially dangerous features)
|
|
w.Header().Set("Permissions-Policy", "geolocation=(), microphone=(), camera=()")
|
|
|
|
// Content Security Policy - adjust as needed for your frontend
|
|
w.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'")
|
|
|
|
// HSTS - uncomment in production with HTTPS
|
|
// w.Header().Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains")
|
|
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|