ContentSecurityPolicy.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. * Specifies a reporting endpoint to which violation reports ought to be sent.
  29. */
  30. public ?string $reportTo = null;
  31. /**
  32. * Instructs user agents to rewrite URL schemes, changing
  33. * HTTP to HTTPS. This directive is for websites with
  34. * large numbers of old URLs that need to be rewritten.
  35. */
  36. public bool $upgradeInsecureRequests = false;
  37. // -------------------------------------------------------------------------
  38. // CSP DIRECTIVES SETTINGS
  39. // NOTE: once you set a policy to 'none', it cannot be further restricted
  40. // -------------------------------------------------------------------------
  41. /**
  42. * Will default to `'self'` if not overridden
  43. *
  44. * @var list<string>|string|null
  45. */
  46. public $defaultSrc;
  47. /**
  48. * Lists allowed scripts' URLs.
  49. *
  50. * @var list<string>|string
  51. */
  52. public $scriptSrc = 'self';
  53. /**
  54. * Specifies valid sources for JavaScript <script> elements.
  55. *
  56. * @var list<string>|string
  57. */
  58. public array|string $scriptSrcElem = 'self';
  59. /**
  60. * Specifies valid sources for JavaScript inline event
  61. * handlers and JavaScript URLs.
  62. *
  63. * @var list<string>|string
  64. */
  65. public array|string $scriptSrcAttr = 'self';
  66. /**
  67. * Lists allowed stylesheets' URLs.
  68. *
  69. * @var list<string>|string
  70. */
  71. public $styleSrc = 'self';
  72. /**
  73. * Specifies valid sources for stylesheets <link> elements.
  74. *
  75. * @var list<string>|string
  76. */
  77. public array|string $styleSrcElem = 'self';
  78. /**
  79. * Specifies valid sources for stylesheets inline
  80. * style attributes and `<style>` elements.
  81. *
  82. * @var list<string>|string
  83. */
  84. public array|string $styleSrcAttr = 'self';
  85. /**
  86. * Defines the origins from which images can be loaded.
  87. *
  88. * @var list<string>|string
  89. */
  90. public $imageSrc = 'self';
  91. /**
  92. * Restricts the URLs that can appear in a page's `<base>` element.
  93. *
  94. * Will default to self if not overridden
  95. *
  96. * @var list<string>|string|null
  97. */
  98. public $baseURI;
  99. /**
  100. * Lists the URLs for workers and embedded frame contents
  101. *
  102. * @var list<string>|string
  103. */
  104. public $childSrc = 'self';
  105. /**
  106. * Limits the origins that you can connect to (via XHR,
  107. * WebSockets, and EventSource).
  108. *
  109. * @var list<string>|string
  110. */
  111. public $connectSrc = 'self';
  112. /**
  113. * Specifies the origins that can serve web fonts.
  114. *
  115. * @var list<string>|string
  116. */
  117. public $fontSrc;
  118. /**
  119. * Lists valid endpoints for submission from `<form>` tags.
  120. *
  121. * @var list<string>|string
  122. */
  123. public $formAction = 'self';
  124. /**
  125. * Specifies the sources that can embed the current page.
  126. * This directive applies to `<frame>`, `<iframe>`, `<embed>`,
  127. * and `<applet>` tags. This directive can't be used in
  128. * `<meta>` tags and applies only to non-HTML resources.
  129. *
  130. * @var list<string>|string|null
  131. */
  132. public $frameAncestors;
  133. /**
  134. * The frame-src directive restricts the URLs which may
  135. * be loaded into nested browsing contexts.
  136. *
  137. * @var list<string>|string|null
  138. */
  139. public $frameSrc;
  140. /**
  141. * Restricts the origins allowed to deliver video and audio.
  142. *
  143. * @var list<string>|string|null
  144. */
  145. public $mediaSrc;
  146. /**
  147. * Allows control over Flash and other plugins.
  148. *
  149. * @var list<string>|string
  150. */
  151. public $objectSrc = 'self';
  152. /**
  153. * @var list<string>|string|null
  154. */
  155. public $manifestSrc;
  156. /**
  157. * @var list<string>|string
  158. */
  159. public array|string $workerSrc = [];
  160. /**
  161. * Limits the kinds of plugins a page may invoke.
  162. *
  163. * @var list<string>|string|null
  164. */
  165. public $pluginTypes;
  166. /**
  167. * List of actions allowed.
  168. *
  169. * @var list<string>|string|null
  170. */
  171. public $sandbox;
  172. /**
  173. * Nonce placeholder for style tags.
  174. */
  175. public string $styleNonceTag = '{csp-style-nonce}';
  176. /**
  177. * Nonce placeholder for script tags.
  178. */
  179. public string $scriptNonceTag = '{csp-script-nonce}';
  180. /**
  181. * Replace nonce tag automatically?
  182. */
  183. public bool $autoNonce = true;
  184. }