21 lines
611 B
Go
21 lines
611 B
Go
package security
|
|
|
|
import "net/http"
|
|
|
|
func MaxBody(n int64, next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
r.Body = http.MaxBytesReader(w, r.Body, n)
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
func SecurityHeaders(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
|
w.Header().Set("X-Frame-Options", "DENY")
|
|
w.Header().Set("Referrer-Policy", "no-referrer")
|
|
w.Header().Set("Content-Security-Policy", "default-src 'self'")
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|