csp.go 1.3 KB

123456789101112131415161718192021
  1. package template
  2. import (
  3. "fmt"
  4. "net/http"
  5. "codeberg.org/vnpower/pixivfe/v2/session"
  6. )
  7. func SetHTMLPrivacyHeaders(w http.ResponseWriter, r *http.Request) {
  8. header := w.Header()
  9. header.Add("Referrer-Policy", "same-origin") // needed for settings redirect
  10. header.Add("X-Frame-Options", "DENY")
  11. // use this if need iframe: `X-Frame-Options: SAMEORIGIN`
  12. header.Add("X-Content-Type-Options", "nosniff")
  13. header.Add("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload")
  14. header.Add("Content-Security-Policy", fmt.Sprintf("base-uri 'self'; default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' %s; media-src 'self' %s; connect-src 'self'; form-action 'self'; frame-ancestors 'none';", session.GetImageProxyOrigin(r), session.GetImageProxyOrigin(r)))
  15. // use this if need iframe: `frame-ancestors 'self'`
  16. header.Add("Permissions-Policy", "accelerometer=(), ambient-light-sensor=(), battery=(), camera=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=()")
  17. }