2022-03-14 19:13:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Config;
|
|
|
|
|
|
|
|
use CodeIgniter\Config\BaseConfig;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the default settings for the ContentSecurityPolicy, if you
|
|
|
|
* choose to use it. The values here will be read in and set as defaults
|
|
|
|
* for the site. If needed, they can be overridden on a page-by-page basis.
|
|
|
|
*
|
|
|
|
* Suggested reference for explanations:
|
|
|
|
*
|
|
|
|
* @see https://www.html5rocks.com/en/tutorials/security/content-security-policy/
|
|
|
|
*/
|
|
|
|
class ContentSecurityPolicy extends BaseConfig
|
|
|
|
{
|
2024-04-07 22:17:30 +02:00
|
|
|
// -------------------------------------------------------------------------
|
2022-03-14 19:13:10 +01:00
|
|
|
// Broadbrush CSP management
|
2024-04-07 22:17:30 +02:00
|
|
|
// -------------------------------------------------------------------------
|
2022-03-14 19:13:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default CSP report context
|
|
|
|
*/
|
2024-04-07 22:17:30 +02:00
|
|
|
public bool $reportOnly = false;
|
2022-03-14 19:13:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies a URL where a browser will send reports
|
|
|
|
* when a content security policy is violated.
|
|
|
|
*/
|
2024-04-07 22:17:30 +02:00
|
|
|
public ?string $reportURI = null;
|
2022-03-14 19:13:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Instructs user agents to rewrite URL schemes, changing
|
|
|
|
* HTTP to HTTPS. This directive is for websites with
|
|
|
|
* large numbers of old URLs that need to be rewritten.
|
|
|
|
*/
|
2024-04-07 22:17:30 +02:00
|
|
|
public bool $upgradeInsecureRequests = false;
|
2022-03-14 19:13:10 +01:00
|
|
|
|
2024-04-07 22:17:30 +02:00
|
|
|
// -------------------------------------------------------------------------
|
2022-03-14 19:13:10 +01:00
|
|
|
// Sources allowed
|
2024-04-07 22:17:30 +02:00
|
|
|
// NOTE: once you set a policy to 'none', it cannot be further restricted
|
|
|
|
// -------------------------------------------------------------------------
|
2022-03-14 19:13:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Will default to self if not overridden
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string|null
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $defaultSrc;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists allowed scripts' URLs.
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $scriptSrc = 'self';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists allowed stylesheets' URLs.
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $styleSrc = 'self';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines the origins from which images can be loaded.
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $imageSrc = 'self';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restricts the URLs that can appear in a page's `<base>` element.
|
|
|
|
*
|
|
|
|
* Will default to self if not overridden
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string|null
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $baseURI;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists the URLs for workers and embedded frame contents
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $childSrc = 'self';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Limits the origins that you can connect to (via XHR,
|
|
|
|
* WebSockets, and EventSource).
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $connectSrc = 'self';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies the origins that can serve web fonts.
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $fontSrc;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists valid endpoints for submission from `<form>` tags.
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $formAction = 'self';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies the sources that can embed the current page.
|
|
|
|
* This directive applies to `<frame>`, `<iframe>`, `<embed>`,
|
|
|
|
* and `<applet>` tags. This directive can't be used in
|
|
|
|
* `<meta>` tags and applies only to non-HTML resources.
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string|null
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $frameAncestors;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The frame-src directive restricts the URLs which may
|
|
|
|
* be loaded into nested browsing contexts.
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string|null
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $frameSrc;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restricts the origins allowed to deliver video and audio.
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string|null
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $mediaSrc;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows control over Flash and other plugins.
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $objectSrc = 'self';
|
|
|
|
|
|
|
|
/**
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string|null
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $manifestSrc;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Limits the kinds of plugins a page may invoke.
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string|null
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $pluginTypes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of actions allowed.
|
|
|
|
*
|
2024-04-07 22:17:30 +02:00
|
|
|
* @var list<string>|string|null
|
2022-03-14 19:13:10 +01:00
|
|
|
*/
|
|
|
|
public $sandbox;
|
2024-04-07 22:17:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Nonce tag for style
|
|
|
|
*/
|
|
|
|
public string $styleNonceTag = '{csp-style-nonce}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Nonce tag for script
|
|
|
|
*/
|
|
|
|
public string $scriptNonceTag = '{csp-script-nonce}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replace nonce tag automatically
|
|
|
|
*/
|
|
|
|
public bool $autoNonce = true;
|
2022-03-14 19:13:10 +01:00
|
|
|
}
|