ContentSecurityPolicy.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 strict-dynamic should be set */
  47. protected $strictDynamicAllowed = false;
  48. /** @var array Domains from which scripts can get loaded */
  49. protected $allowedScriptDomains = [
  50. '\'self\'',
  51. ];
  52. /**
  53. * @var bool Whether inline CSS is allowed
  54. * TODO: Disallow per default
  55. * @link https://github.com/owncloud/core/issues/13458
  56. */
  57. protected $inlineStyleAllowed = true;
  58. /** @var array Domains from which CSS can get loaded */
  59. protected $allowedStyleDomains = [
  60. '\'self\'',
  61. ];
  62. /** @var array Domains from which images can get loaded */
  63. protected $allowedImageDomains = [
  64. '\'self\'',
  65. 'data:',
  66. 'blob:',
  67. ];
  68. /** @var array Domains to which connections can be done */
  69. protected $allowedConnectDomains = [
  70. '\'self\'',
  71. ];
  72. /** @var array Domains from which media elements can be loaded */
  73. protected $allowedMediaDomains = [
  74. '\'self\'',
  75. ];
  76. /** @var array Domains from which object elements can be loaded */
  77. protected $allowedObjectDomains = [];
  78. /** @var array Domains from which iframes can be loaded */
  79. protected $allowedFrameDomains = [];
  80. /** @var array Domains from which fonts can be loaded */
  81. protected $allowedFontDomains = [
  82. '\'self\'',
  83. 'data:',
  84. ];
  85. /** @var array Domains from which web-workers and nested browsing content can load elements */
  86. protected $allowedChildSrcDomains = [];
  87. /** @var array Domains which can embed this Nextcloud instance */
  88. protected $allowedFrameAncestors = [
  89. '\'self\'',
  90. ];
  91. /** @var array Domains from which web-workers can be loaded */
  92. protected $allowedWorkerSrcDomains = [];
  93. /** @var array Domains which can be used as target for forms */
  94. protected $allowedFormActionDomains = [
  95. '\'self\'',
  96. ];
  97. /** @var array Locations to report violations to */
  98. protected $reportTo = [];
  99. }