saveinmed/backend/internal/http/middleware/security.go
Tiago Yamamoto fd237cd9c4 fix(backend): resolving hardcoded values and test failures
Updates .env.example with missing variables. Adds missing security headers in middleware. Fixes repository tests including timezone issues and sqlmock expectations.
2025-12-21 21:43:50 -03:00

18 lines
717 B
Go

package middleware
import "net/http"
func SecurityHeaders(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("X-Frame-Options", "DENY")
w.Header().Set("X-XSS-Protection", "1; mode=block")
w.Header().Set("Referrer-Policy", "strict-origin-when-cross-origin")
// Content-Security-Policy can be very strict, maybe good to start lenient or specific.
// For an API, it's less critical than a frontend serving HTML, but good practice.
w.Header().Set("Content-Security-Policy", "default-src 'none'")
w.Header().Set("Cache-Control", "no-store, max-age=0")
next.ServeHTTP(w, r)
})
}