- audio reader: scrub/volume/speed/genre-tick bindings converted to component methods (onScrubInput, setVolumeFromEvent, applyDefaultSpeedFromSelect, volumeLabel, railTickStyle, isSkipActive/isSpeedActive) — these used Number/Math/String globals that the CSP evaluator cannot resolve - fmtTime restored to the audioReader component: the unexport pass had ripped it from the Alpine.data object (time displays were dead) - book detail: cover-upload click and banner edit validation moved to component methods (triggerCoverUpload, bannerEditHasText) - admin/docs/index components: init() hooks for their x-init chains - CSP header: 'unsafe-eval' dropped — the CSP build needs no eval - e2e spec: replace test.info().annotate (unavailable in this Playwright version) with console logging
28 lines
1.2 KiB
Go
28 lines
1.2 KiB
Go
package middleware
|
|
|
|
import (
|
|
"github.com/labstack/echo/v5"
|
|
)
|
|
|
|
// SecurityHeadersMiddleware adds security headers to all responses
|
|
func SecurityHeadersMiddleware() echo.MiddlewareFunc {
|
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
|
return func(c *echo.Context) error {
|
|
// Add security headers
|
|
c.Response().Header().Set("X-Content-Type-Options", "nosniff")
|
|
c.Response().Header().Set("X-Frame-Options", "DENY")
|
|
c.Response().Header().Set("X-XSS-Protection", "1; mode=block")
|
|
c.Response().Header().Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload")
|
|
// script-src notes: 'unsafe-inline' is required by the pre-paint
|
|
// theme flash guard (inline <script>). Alpine runs via its
|
|
// CSP-safe build (@alpinejs/csp), which needs no eval — do NOT
|
|
// add 'unsafe-eval' here without removing that build.
|
|
c.Response().Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:")
|
|
c.Response().Header().Set("Referrer-Policy", "strict-origin-when-cross-origin")
|
|
c.Response().Header().Set("Permissions-Policy", "geolocation=(), microphone=(), camera=()")
|
|
|
|
return next(c)
|
|
}
|
|
}
|
|
}
|