// Package middleware provides HTTP middleware functions. package middleware import ( "log/slog" "net" "net/http" "time" basicauth "github.com/99designs/basicauth-go" "github.com/go-chi/chi/v5/middleware" "github.com/go-chi/cors" metrics "github.com/slok/go-http-metrics/metrics/prometheus" ghmm "github.com/slok/go-http-metrics/middleware" "github.com/slok/go-http-metrics/middleware/std" "go.uber.org/fx" "sneak.berlin/go/pixa/internal/config" "sneak.berlin/go/pixa/internal/logger" ) // CORSMaxAgeSeconds is the max age for CORS preflight cache (24 hours). const CORSMaxAgeSeconds = 86400 // HSTSValue is the Strict-Transport-Security header value: one year with // includeSubDomains. Emitted unconditionally even though pixa listens plain // HTTP behind a TLS-terminating proxy; browsers ignore an HSTS header received // over plaintext (RFC 6797 section 8.1), so it never lies about the connection, // and emitting it here avoids trusting a forwarded-proto header. const HSTSValue = "max-age=31536000; includeSubDomains" // ContentSecurityPolicyValue is the Content-Security-Policy header value. // default-src 'self' is the baseline and frame-ancestors 'none' is the primary // clickjacking control. 'unsafe-inline' is required in script-src and style-src // because the served templates carry inline onclick handlers (generator page) // and the bundled Tailwind asset injects a runtime