ContentSecurityPolicy.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author sualko <klaus@jsxc.org>
  9. * @author Thomas Citharel <nextcloud@tcit.fr>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCP\AppFramework\Http;
  27. /**
  28. * Class ContentSecurityPolicy is a simple helper which allows applications to
  29. * modify the Content-Security-Policy sent by Nextcloud. Per default only JavaScript,
  30. * stylesheets, images, fonts, media and connections from the same domain
  31. * ('self') are allowed.
  32. *
  33. * Even if a value gets modified above defaults will still get appended. Please
  34. * notice that Nextcloud ships already with sensible defaults and those policies
  35. * should require no modification at all for most use-cases.
  36. *
  37. * This class allows unsafe-inline of CSS.
  38. *
  39. * @since 8.1.0
  40. */
  41. class ContentSecurityPolicy extends EmptyContentSecurityPolicy {
  42. /** @var bool Whether inline JS snippets are allowed */
  43. protected $inlineScriptAllowed = false;
  44. /** @var bool Whether eval in JS scripts is allowed */
  45. protected $evalScriptAllowed = false;
  46. /** @var bool Whether WebAssembly compilation is allowed */
  47. protected ?bool $evalWasmAllowed = false;
  48. /** @var bool Whether strict-dynamic should be set */
  49. protected $strictDynamicAllowed = false;
  50. /** @var bool Whether strict-dynamic should be set for 'script-src-elem' */
  51. protected $strictDynamicAllowedOnScripts = true;
  52. /** @var array Domains from which scripts can get loaded */
  53. protected $allowedScriptDomains = [
  54. '\'self\'',
  55. ];
  56. /**
  57. * @var bool Whether inline CSS is allowed
  58. * TODO: Disallow per default
  59. * @link https://github.com/owncloud/core/issues/13458
  60. */
  61. protected $inlineStyleAllowed = true;
  62. /** @var array Domains from which CSS can get loaded */
  63. protected $allowedStyleDomains = [
  64. '\'self\'',
  65. ];
  66. /** @var array Domains from which images can get loaded */
  67. protected $allowedImageDomains = [
  68. '\'self\'',
  69. 'data:',
  70. 'blob:',
  71. ];
  72. /** @var array Domains to which connections can be done */
  73. protected $allowedConnectDomains = [
  74. '\'self\'',
  75. ];
  76. /** @var array Domains from which media elements can be loaded */
  77. protected $allowedMediaDomains = [
  78. '\'self\'',
  79. ];
  80. /** @var array Domains from which object elements can be loaded */
  81. protected $allowedObjectDomains = [];
  82. /** @var array Domains from which iframes can be loaded */
  83. protected $allowedFrameDomains = [];
  84. /** @var array Domains from which fonts can be loaded */
  85. protected $allowedFontDomains = [
  86. '\'self\'',
  87. 'data:',
  88. ];
  89. /** @var array Domains from which web-workers and nested browsing content can load elements */
  90. protected $allowedChildSrcDomains = [];
  91. /** @var array Domains which can embed this Nextcloud instance */
  92. protected $allowedFrameAncestors = [
  93. '\'self\'',
  94. ];
  95. /** @var array Domains from which web-workers can be loaded */
  96. protected $allowedWorkerSrcDomains = [];
  97. /** @var array Domains which can be used as target for forms */
  98. protected $allowedFormActionDomains = [
  99. '\'self\'',
  100. ];
  101. /** @var array Locations to report violations to */
  102. protected $reportTo = [];
  103. }