2015-02-09 10:30:01 -05:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2015-02-09 10:30:01 -05:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-02-09 10:30:01 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCP\AppFramework\Http;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class ContentSecurityPolicy is a simple helper which allows applications to
|
2018-06-12 16:34:58 -04:00
|
|
|
* modify the Content-Security-Policy sent by Nextcloud. Per default only JavaScript,
|
2015-02-09 10:30:01 -05:00
|
|
|
* stylesheets, images, fonts, media and connections from the same domain
|
|
|
|
|
* ('self') are allowed.
|
|
|
|
|
*
|
|
|
|
|
* Even if a value gets modified above defaults will still get appended. Please
|
2018-06-12 16:34:58 -04:00
|
|
|
* notice that Nextcloud ships already with sensible defaults and those policies
|
2015-02-09 10:30:01 -05:00
|
|
|
* should require no modification at all for most use-cases.
|
|
|
|
|
*
|
2020-12-12 15:11:42 -05:00
|
|
|
* This class allows unsafe-inline of CSS.
|
2018-06-12 16:34:58 -04:00
|
|
|
*
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 8.1.0
|
2015-02-09 10:30:01 -05:00
|
|
|
*/
|
2016-01-28 08:33:02 -05:00
|
|
|
class ContentSecurityPolicy extends EmptyContentSecurityPolicy {
|
2015-02-09 10:30:01 -05:00
|
|
|
/** @var bool Whether inline JS snippets are allowed */
|
2016-01-28 08:33:02 -05:00
|
|
|
protected $inlineScriptAllowed = false;
|
2018-09-03 09:28:37 -04:00
|
|
|
/** @var bool Whether eval in JS scripts is allowed */
|
|
|
|
|
protected $evalScriptAllowed = false;
|
2023-05-04 10:54:23 -04:00
|
|
|
/** @var bool Whether WebAssembly compilation is allowed */
|
|
|
|
|
protected ?bool $evalWasmAllowed = false;
|
2022-03-09 08:25:36 -05:00
|
|
|
/** @var bool Whether strict-dynamic should be set */
|
2022-04-01 07:56:15 -04:00
|
|
|
protected $strictDynamicAllowed = false;
|
2023-11-17 04:56:02 -05:00
|
|
|
/** @var bool Whether strict-dynamic should be set for 'script-src-elem' */
|
2023-11-17 05:07:35 -05:00
|
|
|
protected $strictDynamicAllowedOnScripts = true;
|
2015-02-09 10:30:01 -05:00
|
|
|
/** @var array Domains from which scripts can get loaded */
|
2016-01-28 08:33:02 -05:00
|
|
|
protected $allowedScriptDomains = [
|
2015-02-09 10:30:01 -05:00
|
|
|
'\'self\'',
|
|
|
|
|
];
|
|
|
|
|
/**
|
|
|
|
|
* @var bool Whether inline CSS is allowed
|
|
|
|
|
* TODO: Disallow per default
|
|
|
|
|
* @link https://github.com/owncloud/core/issues/13458
|
|
|
|
|
*/
|
2016-01-28 08:33:02 -05:00
|
|
|
protected $inlineStyleAllowed = true;
|
2015-02-09 10:30:01 -05:00
|
|
|
/** @var array Domains from which CSS can get loaded */
|
2016-01-28 08:33:02 -05:00
|
|
|
protected $allowedStyleDomains = [
|
2015-02-09 10:30:01 -05:00
|
|
|
'\'self\'',
|
|
|
|
|
];
|
|
|
|
|
/** @var array Domains from which images can get loaded */
|
2016-01-28 08:33:02 -05:00
|
|
|
protected $allowedImageDomains = [
|
2015-02-09 10:30:01 -05:00
|
|
|
'\'self\'',
|
2015-08-05 05:41:25 -04:00
|
|
|
'data:',
|
2015-09-29 08:18:12 -04:00
|
|
|
'blob:',
|
2015-02-09 10:30:01 -05:00
|
|
|
];
|
|
|
|
|
/** @var array Domains to which connections can be done */
|
2016-01-28 08:33:02 -05:00
|
|
|
protected $allowedConnectDomains = [
|
2015-02-09 10:30:01 -05:00
|
|
|
'\'self\'',
|
|
|
|
|
];
|
|
|
|
|
/** @var array Domains from which media elements can be loaded */
|
2016-01-28 08:33:02 -05:00
|
|
|
protected $allowedMediaDomains = [
|
2015-02-09 10:30:01 -05:00
|
|
|
'\'self\'',
|
|
|
|
|
];
|
|
|
|
|
/** @var array Domains from which object elements can be loaded */
|
2016-01-28 08:33:02 -05:00
|
|
|
protected $allowedObjectDomains = [];
|
2015-02-09 10:30:01 -05:00
|
|
|
/** @var array Domains from which iframes can be loaded */
|
2016-01-28 08:33:02 -05:00
|
|
|
protected $allowedFrameDomains = [];
|
2015-02-09 10:30:01 -05:00
|
|
|
/** @var array Domains from which fonts can be loaded */
|
2016-01-28 08:33:02 -05:00
|
|
|
protected $allowedFontDomains = [
|
2015-02-09 10:30:01 -05:00
|
|
|
'\'self\'',
|
2019-01-07 07:13:34 -05:00
|
|
|
'data:',
|
2015-02-09 10:30:01 -05:00
|
|
|
];
|
2015-02-26 06:54:15 -05:00
|
|
|
/** @var array Domains from which web-workers and nested browsing content can load elements */
|
2016-01-28 08:33:02 -05:00
|
|
|
protected $allowedChildSrcDomains = [];
|
2017-06-19 07:55:46 -04:00
|
|
|
|
2017-07-27 11:25:09 -04:00
|
|
|
/** @var array Domains which can embed this Nextcloud instance */
|
2019-01-08 03:33:34 -05:00
|
|
|
protected $allowedFrameAncestors = [
|
|
|
|
|
'\'self\'',
|
|
|
|
|
];
|
2018-09-03 10:47:52 -04:00
|
|
|
|
|
|
|
|
/** @var array Domains from which web-workers can be loaded */
|
|
|
|
|
protected $allowedWorkerSrcDomains = [];
|
2018-10-16 08:04:22 -04:00
|
|
|
|
2019-07-30 17:13:46 -04:00
|
|
|
/** @var array Domains which can be used as target for forms */
|
|
|
|
|
protected $allowedFormActionDomains = [
|
|
|
|
|
'\'self\'',
|
|
|
|
|
];
|
|
|
|
|
|
2018-10-16 08:04:22 -04:00
|
|
|
/** @var array Locations to report violations to */
|
|
|
|
|
protected $reportTo = [];
|
2015-02-09 10:30:01 -05:00
|
|
|
}
|