ContentSecurityPolicy.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace Config;
  3. use CodeIgniter\Config\BaseConfig;
  4. /**
  5. * Stores the default settings for the ContentSecurityPolicy, if you
  6. * choose to use it. The values here will be read in and set as defaults
  7. * for the site. If needed, they can be overridden on a page-by-page basis.
  8. *
  9. * Suggested reference for explanations:
  10. *
  11. * @see https://www.html5rocks.com/en/tutorials/security/content-security-policy/
  12. */
  13. class ContentSecurityPolicy extends BaseConfig
  14. {
  15. // -------------------------------------------------------------------------
  16. // Broadbrush CSP management
  17. // -------------------------------------------------------------------------
  18. /**
  19. * Default CSP report context
  20. */
  21. public bool $reportOnly = false;
  22. /**
  23. * Specifies a URL where a browser will send reports
  24. * when a content security policy is violated.
  25. */
  26. public ?string $reportURI = null;
  27. /**
  28. * Instructs user agents to rewrite URL schemes, changing
  29. * HTTP to HTTPS. This directive is for websites with
  30. * large numbers of old URLs that need to be rewritten.
  31. */
  32. public bool $upgradeInsecureRequests = false;
  33. // -------------------------------------------------------------------------
  34. // Sources allowed
  35. // NOTE: once you set a policy to 'none', it cannot be further restricted
  36. // -------------------------------------------------------------------------
  37. /**
  38. * Will default to self if not overridden
  39. *
  40. * @var list<string>|string|null
  41. */
  42. public $defaultSrc;
  43. /**
  44. * Lists allowed scripts' URLs.
  45. *
  46. * @var list<string>|string
  47. */
  48. public $scriptSrc = 'self';
  49. /**
  50. * Lists allowed stylesheets' URLs.
  51. *
  52. * @var list<string>|string
  53. */
  54. public $styleSrc = 'self';
  55. /**
  56. * Defines the origins from which images can be loaded.
  57. *
  58. * @var list<string>|string
  59. */
  60. public $imageSrc = 'self';
  61. /**
  62. * Restricts the URLs that can appear in a page's `<base>` element.
  63. *
  64. * Will default to self if not overridden
  65. *
  66. * @var list<string>|string|null
  67. */
  68. public $baseURI;
  69. /**
  70. * Lists the URLs for workers and embedded frame contents
  71. *
  72. * @var list<string>|string
  73. */
  74. public $childSrc = 'self';
  75. /**
  76. * Limits the origins that you can connect to (via XHR,
  77. * WebSockets, and EventSource).
  78. *
  79. * @var list<string>|string
  80. */
  81. public $connectSrc = 'self';
  82. /**
  83. * Specifies the origins that can serve web fonts.
  84. *
  85. * @var list<string>|string
  86. */
  87. public $fontSrc;
  88. /**
  89. * Lists valid endpoints for submission from `<form>` tags.
  90. *
  91. * @var list<string>|string
  92. */
  93. public $formAction = 'self';
  94. /**
  95. * Specifies the sources that can embed the current page.
  96. * This directive applies to `<frame>`, `<iframe>`, `<embed>`,
  97. * and `<applet>` tags. This directive can't be used in
  98. * `<meta>` tags and applies only to non-HTML resources.
  99. *
  100. * @var list<string>|string|null
  101. */
  102. public $frameAncestors;
  103. /**
  104. * The frame-src directive restricts the URLs which may
  105. * be loaded into nested browsing contexts.
  106. *
  107. * @var list<string>|string|null
  108. */
  109. public $frameSrc;
  110. /**
  111. * Restricts the origins allowed to deliver video and audio.
  112. *
  113. * @var list<string>|string|null
  114. */
  115. public $mediaSrc;
  116. /**
  117. * Allows control over Flash and other plugins.
  118. *
  119. * @var list<string>|string
  120. */
  121. public $objectSrc = 'self';
  122. /**
  123. * @var list<string>|string|null
  124. */
  125. public $manifestSrc;
  126. /**
  127. * Limits the kinds of plugins a page may invoke.
  128. *
  129. * @var list<string>|string|null
  130. */
  131. public $pluginTypes;
  132. /**
  133. * List of actions allowed.
  134. *
  135. * @var list<string>|string|null
  136. */
  137. public $sandbox;
  138. /**
  139. * Nonce tag for style
  140. */
  141. public string $styleNonceTag = '{csp-style-nonce}';
  142. /**
  143. * Nonce tag for script
  144. */
  145. public string $scriptNonceTag = '{csp-script-nonce}';
  146. /**
  147. * Replace nonce tag automatically
  148. */
  149. public bool $autoNonce = true;
  150. }