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")
|
2023-07-22 21:43:54 +05:00
|
|
|
c.Writer.Header().Set("Content-Security-Policy", "script-src 'self'; ")
|
2023-07-22 20:49:13 +05:00
|
|
|
}
|