ContentSecurityPolicy.php 2.9 KB

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