mirror of
https://github.com/ordinary-dev/phoenix
synced 2024-09-20 03:40:29 +05:00
19 lines
587 B
Go
19 lines
587 B
Go
|
package middleware
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
// Adds several headers to the response to improve security.
|
||
|
// For example, headers prevent embedding a site and passing information about the referrer.
|
||
|
func SecurityHeadersMiddleware(next http.Handler) http.Handler {
|
||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
w.Header().Set("X-Frame-Options", "SAMEORIGIN")
|
||
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||
|
w.Header().Set("Referrer-Policy", "same-origin")
|
||
|
w.Header().Set("Content-Security-Policy", "script-src 'self'; ")
|
||
|
|
||
|
next.ServeHTTP(w, r)
|
||
|
})
|
||
|
}
|