mirror of
https://github.com/Luzifer/ots.git
synced 2025-04-19 06:55:51 -04:00
Add security HTTP headers
Sadly, the Vue web interface needs unsafe-inline for both stylesheets and scripts, making the CSP header a bit useless.
This commit is contained in:
parent
9ad6d468fd
commit
652eea694e
17
main.go
17
main.go
@ -86,9 +86,20 @@ func assetDelivery(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", mime.TypeByExtension(ext))
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.Write(assetData)
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
|
||||
var cspHeader = strings.Join([]string{
|
||||
"default-src 'none'",
|
||||
"connect-src 'self'",
|
||||
"font-src 'self'",
|
||||
"img-src 'self'",
|
||||
"script-src 'self' 'unsafe-inline'",
|
||||
"style-src 'self' 'unsafe-inline'",
|
||||
}, ";")
|
||||
|
||||
func handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||
indexTpl, err := assets.ReadFile("frontend/index.html")
|
||||
if err != nil {
|
||||
@ -102,6 +113,12 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Referrer-Policy", "no-referrer")
|
||||
w.Header().Set("X-Frame-Options", "DENY")
|
||||
w.Header().Set("X-Xss-Protection", "1; mode=block")
|
||||
w.Header().Set("Content-Security-Policy", cspHeader)
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
|
||||
if err = tpl.Execute(w, struct {
|
||||
Vars map[string]string
|
||||
}{
|
||||
|
Loading…
x
Reference in New Issue
Block a user