ContentSecurityPolicy.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 sualko <klaus@jsxc.org>
  8. * @author Thomas Citharel <tcit@tcit.fr>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCP\AppFramework\Http;
  26. /**
  27. * Class ContentSecurityPolicy is a simple helper which allows applications to
  28. * modify the Content-Security-Policy sent by Nextcloud. Per default only JavaScript,
  29. * stylesheets, images, fonts, media and connections from the same domain
  30. * ('self') are allowed.
  31. *
  32. * Even if a value gets modified above defaults will still get appended. Please
  33. * notice that Nextcloud ships already with sensible defaults and those policies
  34. * should require no modification at all for most use-cases.
  35. *
  36. * This class allows unsafe-eval of javascript and unsafe-inline of CSS.
  37. *
  38. * @package OCP\AppFramework\Http
  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 array Domains from which scripts can get loaded */
  47. protected $allowedScriptDomains = [
  48. '\'self\'',
  49. ];
  50. /**
  51. * @var bool Whether inline CSS is allowed
  52. * TODO: Disallow per default
  53. * @link https://github.com/owncloud/core/issues/13458
  54. */
  55. protected $inlineStyleAllowed = true;
  56. /** @var array Domains from which CSS can get loaded */
  57. protected $allowedStyleDomains = [
  58. '\'self\'',
  59. ];
  60. /** @var array Domains from which images can get loaded */
  61. protected $allowedImageDomains = [
  62. '\'self\'',
  63. 'data:',
  64. 'blob:',
  65. ];
  66. /** @var array Domains to which connections can be done */
  67. protected $allowedConnectDomains = [
  68. '\'self\'',
  69. ];
  70. /** @var array Domains from which media elements can be loaded */
  71. protected $allowedMediaDomains = [
  72. '\'self\'',
  73. ];
  74. /** @var array Domains from which object elements can be loaded */
  75. protected $allowedObjectDomains = [];
  76. /** @var array Domains from which iframes can be loaded */
  77. protected $allowedFrameDomains = [];
  78. /** @var array Domains from which fonts can be loaded */
  79. protected $allowedFontDomains = [
  80. '\'self\'',
  81. 'data:',
  82. ];
  83. /** @var array Domains from which web-workers and nested browsing content can load elements */
  84. protected $allowedChildSrcDomains = [];
  85. /** @var array Domains which can embed this Nextcloud instance */
  86. protected $allowedFrameAncestors = [];
  87. /** @var array Domains from which web-workers can be loaded */
  88. protected $allowedWorkerSrcDomains = [];
  89. /** @var array Locations to report violations to */
  90. protected $reportTo = [];
  91. }