Contains the Concourse pipeline definition for building a line-server container
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
843 B

  1. package main
  2. import (
  3. "net/http"
  4. )
  5. const (
  6. cspHeader = "Content-Security-Policy"
  7. frameOptionsHeader = "X-Frame-Options"
  8. contentTypeOptionsHeader = "X-Content-Type-Options"
  9. )
  10. type csp struct {
  11. h http.Handler
  12. opts CSPOptions
  13. }
  14. type CSPOptions struct {
  15. policy string
  16. frame string
  17. }
  18. func (c csp) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  19. // only add a CSP if one is not already set
  20. if existing := w.Header().Get(cspHeader); existing == "" {
  21. w.Header().Add(cspHeader, c.opts.policy)
  22. }
  23. w.Header().Set(frameOptionsHeader, c.opts.frame)
  24. w.Header().Set(contentTypeOptionsHeader, "nosniff")
  25. c.h.ServeHTTP(w, r)
  26. }
  27. func ContentSecurityPolicy(o CSPOptions) func(http.Handler) http.Handler {
  28. fn := func(h http.Handler) http.Handler {
  29. return csp{h, o}
  30. }
  31. return fn
  32. }
  33. // vim:set ts=8 sw=8 noet: