photoprism/internal/server/security.go

29 lines
904 B
Go
Raw Normal View History

2021-10-17 16:48:53 +02:00
package server
import (
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/api"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/pkg/header"
2021-10-17 16:48:53 +02:00
)
// Security is a middleware that adds security-related headers to the server's response.
var Security = func(conf *config.Config) gin.HandlerFunc {
2021-10-17 16:48:53 +02:00
return func(c *gin.Context) {
// Abort if the request should not be served through a CDN.
if header.AbortCdnRequest(c.Request) {
api.AbortNotFound(c)
return
}
// Set Content Security Policy.
// See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
c.Header(header.ContentSecurityPolicy, header.DefaultContentSecurityPolicy)
// Set Frame Options.
// See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
c.Header(header.FrameOptions, header.DefaultFrameOptions)
2021-10-17 16:48:53 +02:00
}
}