ContentSecurityPolicy.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCP\AppFramework\Http;
  8. /**
  9. * Class ContentSecurityPolicy is a simple helper which allows applications to
  10. * modify the Content-Security-Policy sent by Nextcloud. Per default only JavaScript,
  11. * stylesheets, images, fonts, media and connections from the same domain
  12. * ('self') are allowed.
  13. *
  14. * Even if a value gets modified above defaults will still get appended. Please
  15. * notice that Nextcloud ships already with sensible defaults and those policies
  16. * should require no modification at all for most use-cases.
  17. *
  18. * This class allows unsafe-inline of CSS.
  19. *
  20. * @since 8.1.0
  21. */
  22. class ContentSecurityPolicy extends EmptyContentSecurityPolicy {
  23. /** @var bool Whether inline JS snippets are allowed */
  24. protected $inlineScriptAllowed = false;
  25. /** @var bool Whether eval in JS scripts is allowed */
  26. protected $evalScriptAllowed = false;
  27. /** @var bool Whether WebAssembly compilation is allowed */
  28. protected ?bool $evalWasmAllowed = false;
  29. /** @var bool Whether strict-dynamic should be set */
  30. protected $strictDynamicAllowed = false;
  31. /** @var bool Whether strict-dynamic should be set for 'script-src-elem' */
  32. protected $strictDynamicAllowedOnScripts = true;
  33. /** @var array Domains from which scripts can get loaded */
  34. protected $allowedScriptDomains = [
  35. '\'self\'',
  36. ];
  37. /**
  38. * @var bool Whether inline CSS is allowed
  39. * TODO: Disallow per default
  40. * @link https://github.com/owncloud/core/issues/13458
  41. */
  42. protected $inlineStyleAllowed = true;
  43. /** @var array Domains from which CSS can get loaded */
  44. protected $allowedStyleDomains = [
  45. '\'self\'',
  46. ];
  47. /** @var array Domains from which images can get loaded */
  48. protected $allowedImageDomains = [
  49. '\'self\'',
  50. 'data:',
  51. 'blob:',
  52. ];
  53. /** @var array Domains to which connections can be done */
  54. protected $allowedConnectDomains = [
  55. '\'self\'',
  56. ];
  57. /** @var array Domains from which media elements can be loaded */
  58. protected $allowedMediaDomains = [
  59. '\'self\'',
  60. ];
  61. /** @var array Domains from which object elements can be loaded */
  62. protected $allowedObjectDomains = [];
  63. /** @var array Domains from which iframes can be loaded */
  64. protected $allowedFrameDomains = [];
  65. /** @var array Domains from which fonts can be loaded */
  66. protected $allowedFontDomains = [
  67. '\'self\'',
  68. 'data:',
  69. ];
  70. /** @var array Domains from which web-workers and nested browsing content can load elements */
  71. protected $allowedChildSrcDomains = [];
  72. /** @var array Domains which can embed this Nextcloud instance */
  73. protected $allowedFrameAncestors = [
  74. '\'self\'',
  75. ];
  76. /** @var array Domains from which web-workers can be loaded */
  77. protected $allowedWorkerSrcDomains = [];
  78. /** @var array Domains which can be used as target for forms */
  79. protected $allowedFormActionDomains = [
  80. '\'self\'',
  81. ];
  82. /** @var array Locations to report violations to */
  83. protected $reportTo = [];
  84. }