2015-02-09 18:30:01 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-10-05 21:54:56 +03:00
|
|
|
* @author sualko <klaus@jsxc.org>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
2015-02-09 18:30:01 +03:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2015-02-09 18:30:01 +03:00
|
|
|
namespace OCP\AppFramework\Http;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ContentSecurityPolicy is a simple helper which allows applications to
|
2018-06-12 23:34:58 +03:00
|
|
|
* modify the Content-Security-Policy sent by Nextcloud. Per default only JavaScript,
|
2015-02-09 18:30:01 +03: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 23:34:58 +03:00
|
|
|
* notice that Nextcloud ships already with sensible defaults and those policies
|
2015-02-09 18:30:01 +03:00
|
|
|
* should require no modification at all for most use-cases.
|
|
|
|
*
|
2018-06-12 23:34:58 +03:00
|
|
|
* This class allows unsafe-eval of javascript and unsafe-inline of CSS.
|
|
|
|
*
|
2015-02-09 18:30:01 +03:00
|
|
|
* @package OCP\AppFramework\Http
|
2015-04-16 18:00:08 +03:00
|
|
|
* @since 8.1.0
|
2015-02-09 18:30:01 +03:00
|
|
|
*/
|
2016-01-28 16:33:02 +03:00
|
|
|
class ContentSecurityPolicy extends EmptyContentSecurityPolicy {
|
2015-02-09 18:30:01 +03:00
|
|
|
/** @var bool Whether inline JS snippets are allowed */
|
2016-01-28 16:33:02 +03:00
|
|
|
protected $inlineScriptAllowed = false;
|
2018-09-03 16:28:37 +03:00
|
|
|
/** @var bool Whether eval in JS scripts is allowed */
|
|
|
|
protected $evalScriptAllowed = false;
|
2015-02-09 18:30:01 +03:00
|
|
|
/** @var array Domains from which scripts can get loaded */
|
2016-01-28 16:33:02 +03:00
|
|
|
protected $allowedScriptDomains = [
|
2015-02-09 18:30:01 +03:00
|
|
|
'\'self\'',
|
|
|
|
];
|
|
|
|
/**
|
|
|
|
* @var bool Whether inline CSS is allowed
|
|
|
|
* TODO: Disallow per default
|
|
|
|
* @link https://github.com/owncloud/core/issues/13458
|
|
|
|
*/
|
2016-01-28 16:33:02 +03:00
|
|
|
protected $inlineStyleAllowed = true;
|
2015-02-09 18:30:01 +03:00
|
|
|
/** @var array Domains from which CSS can get loaded */
|
2016-01-28 16:33:02 +03:00
|
|
|
protected $allowedStyleDomains = [
|
2015-02-09 18:30:01 +03:00
|
|
|
'\'self\'',
|
|
|
|
];
|
|
|
|
/** @var array Domains from which images can get loaded */
|
2016-01-28 16:33:02 +03:00
|
|
|
protected $allowedImageDomains = [
|
2015-02-09 18:30:01 +03:00
|
|
|
'\'self\'',
|
2015-08-05 12:41:25 +03:00
|
|
|
'data:',
|
2015-09-29 15:18:12 +03:00
|
|
|
'blob:',
|
2015-02-09 18:30:01 +03:00
|
|
|
];
|
|
|
|
/** @var array Domains to which connections can be done */
|
2016-01-28 16:33:02 +03:00
|
|
|
protected $allowedConnectDomains = [
|
2015-02-09 18:30:01 +03:00
|
|
|
'\'self\'',
|
|
|
|
];
|
|
|
|
/** @var array Domains from which media elements can be loaded */
|
2016-01-28 16:33:02 +03:00
|
|
|
protected $allowedMediaDomains = [
|
2015-02-09 18:30:01 +03:00
|
|
|
'\'self\'',
|
|
|
|
];
|
|
|
|
/** @var array Domains from which object elements can be loaded */
|
2016-01-28 16:33:02 +03:00
|
|
|
protected $allowedObjectDomains = [];
|
2015-02-09 18:30:01 +03:00
|
|
|
/** @var array Domains from which iframes can be loaded */
|
2016-01-28 16:33:02 +03:00
|
|
|
protected $allowedFrameDomains = [];
|
2015-02-09 18:30:01 +03:00
|
|
|
/** @var array Domains from which fonts can be loaded */
|
2016-01-28 16:33:02 +03:00
|
|
|
protected $allowedFontDomains = [
|
2015-02-09 18:30:01 +03:00
|
|
|
'\'self\'',
|
2019-01-07 15:13:34 +03:00
|
|
|
'data:',
|
2015-02-09 18:30:01 +03:00
|
|
|
];
|
2015-02-26 14:54:15 +03:00
|
|
|
/** @var array Domains from which web-workers and nested browsing content can load elements */
|
2016-01-28 16:33:02 +03:00
|
|
|
protected $allowedChildSrcDomains = [];
|
2017-06-19 14:55:46 +03:00
|
|
|
|
2017-07-27 18:25:09 +03:00
|
|
|
/** @var array Domains which can embed this Nextcloud instance */
|
2019-01-08 11:33:34 +03:00
|
|
|
protected $allowedFrameAncestors = [
|
|
|
|
'\'self\'',
|
|
|
|
];
|
2018-09-03 17:47:52 +03:00
|
|
|
|
|
|
|
/** @var array Domains from which web-workers can be loaded */
|
|
|
|
protected $allowedWorkerSrcDomains = [];
|
2018-10-16 15:04:22 +03:00
|
|
|
|
2019-07-31 00:13:46 +03:00
|
|
|
/** @var array Domains which can be used as target for forms */
|
|
|
|
protected $allowedFormActionDomains = [
|
|
|
|
'\'self\'',
|
|
|
|
];
|
|
|
|
|
2018-10-16 15:04:22 +03:00
|
|
|
/** @var array Locations to report violations to */
|
|
|
|
protected $reportTo = [];
|
2015-02-09 18:30:01 +03:00
|
|
|
}
|