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.

60 lines
3.7 KiB

4 years ago
  1. {{/*
  2. Copyright (C) 2019 Josh Habdas <jhabdas@protonmail.com>
  3. This file is part of After Dark.
  4. After Dark is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. After Dark is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */ -}}
  15. {{ $is_disabled := .Param "disable_csp" }}
  16. {{ $site_directives := .Site.Params.security.csp.directives }}
  17. {{ if and $site_directives (ne $is_disabled true) }}
  18. {{ if ge (len $site_directives) 1 }}
  19. <meta
  20. http-equiv="Content-Security-Policy"
  21. content="default-src{{ if $site_directives.defaultsrc }}
  22. {{- range $site_directives.defaultsrc }} {{ . | safeHTML }}{{ end -}}
  23. {{- range .Params.security.csp.directives.defaultsrc }} {{ . | safeHTML }}{{ end -}}
  24. {{ else }} 'none'{{ end }};connect-src{{ if $site_directives.connectsrc }}
  25. {{- range $site_directives.connectsrc }} {{ . | safeHTML }}{{ end -}}
  26. {{- range .Params.security.csp.directives.connectsrc }} {{ . | safeHTML }}{{ end -}}
  27. {{ else }} 'self'{{ end }};worker-src{{ if $site_directives.workersrc }}
  28. {{- range $site_directives.workersrc }} {{ . | safeHTML }}{{ end -}}
  29. {{- range .Params.security.csp.directives.workersrc }} {{ . | safeHTML }}{{ end -}}
  30. {{ else }} 'self'{{ end }};font-src{{ if $site_directives.fontsrc }}
  31. {{- range $site_directives.fontsrc }} {{ . | safeHTML }}{{ end -}}
  32. {{- range .Params.security.csp.directives.fontsrc }} {{ . | safeHTML }}{{ end -}}
  33. {{ else }} 'self'{{ end }};media-src{{ if $site_directives.mediasrc }}
  34. {{- range $site_directives.mediasrc }} {{ . | safeHTML }}{{ end -}}
  35. {{- range .Params.security.csp.directives.mediasrc }} {{ . | safeHTML }}{{ end -}}
  36. {{ else }} 'self'{{ end }};img-src{{ if $site_directives.imgsrc }}
  37. {{- range $site_directives.imgsrc }} {{ . | safeHTML }}{{ end -}}
  38. {{- range .Params.security.csp.directives.imgsrc }} {{ . | safeHTML }}{{ end -}}
  39. {{ else }} 'self' data:{{ end }};script-src{{ if $site_directives.scriptsrc }}
  40. {{- range $site_directives.scriptsrc }} {{ . | safeHTML }}{{ end -}}
  41. {{- range .Params.security.csp.directives.scriptsrc }} {{ . | safeHTML }} {{ end -}}
  42. {{ else }} 'none'{{ end }};style-src{{ if $site_directives.stylesrc }}
  43. {{- range $site_directives.stylesrc }} {{ . | safeHTML }}{{ end -}}
  44. {{- range .Params.security.csp.directives.stylesrc }} {{ . | safeHTML }} {{ end -}}
  45. {{ else }} 'self' 'unsafe-inline'{{ end }};frame-src{{ if $site_directives.framesrc }}
  46. {{- range $site_directives.framesrc }} {{ . | safeHTML }}{{ end -}}
  47. {{- range .Params.security.csp.directives.framesrc }} {{ . | safeHTML }} {{ end -}}
  48. {{ else }} 'self'{{ end }};object-src{{ if $site_directives.objectsrc }}
  49. {{- range $site_directives.objectsrc }} {{ . | safeHTML }}{{ end -}}
  50. {{- range .Params.security.csp.directives.objectsrc }} {{ . | safeHTML }} {{ end -}}
  51. {{ else }} 'none'{{ end }};">
  52. {{ end }}
  53. {{ else if not $is_disabled }}
  54. <meta http-equiv="Content-Security-Policy" content="default-src 'self' https: 'unsafe-inline' 'unsafe-eval'; worker-src 'self' blob:; connect-src 'self' wss: data:; font-src 'self' https: data:; img-src 'self' https: data:; object-src 'none'">
  55. {{ end }}