2021-10-17 16:48:53 +02:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
2022-09-28 09:01:17 +02:00
|
|
|
|
2024-01-16 20:56:43 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/api"
|
2022-10-09 17:16:49 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2024-01-07 12:25:56 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/header"
|
2021-10-17 16:48:53 +02:00
|
|
|
)
|
|
|
|
|
2024-01-16 20:04:36 +01:00
|
|
|
// Security is a middleware that adds security-related headers to the server's response.
|
2022-10-09 17:16:49 +02:00
|
|
|
var Security = func(conf *config.Config) gin.HandlerFunc {
|
2021-10-17 16:48:53 +02:00
|
|
|
return func(c *gin.Context) {
|
2024-01-16 20:04:36 +01:00
|
|
|
// Abort if the request should not be served through a CDN.
|
|
|
|
if header.AbortCdnRequest(c.Request) {
|
2024-01-16 20:56:43 +01:00
|
|
|
api.AbortNotFound(c)
|
2024-01-16 16:17:16 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-15 13:06:27 +01:00
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|