phoenix/views/security.go

15 lines
505 B
Go
Raw Normal View History

2023-07-22 20:49:13 +05:00
package views
import (
"github.com/gin-gonic/gin"
)
// Adds several headers to the response to improve security.
// For example, headers prevent embedding a site and passing information about the referrer.
func SecurityHeadersMiddleware(c *gin.Context) {
c.Writer.Header().Set("X-Frame-Options", "SAMEORIGIN")
c.Writer.Header().Set("X-Content-Type-Options", "nosniff")
c.Writer.Header().Set("Referrer-Policy", "same-origin")
c.Writer.Header().Set("Content-Security-Policy", "default-src 'self'")
}