2015-02-09 15:30:01 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 15:07:57 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2015-10-05 18:54:56 +00:00
|
|
|
* @author sualko <klaus@jsxc.org>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Thomas Citharel <tcit@tcit.fr>
|
2015-03-26 10:44:34 +00: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,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2015-02-09 15:30:01 +00:00
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2015-02-09 15:30:01 +00:00
|
|
|
namespace OCP\AppFramework\Http;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ContentSecurityPolicy is a simple helper which allows applications to
|
2018-06-12 20:34:58 +00:00
|
|
|
* modify the Content-Security-Policy sent by Nextcloud. Per default only JavaScript,
|
2015-02-09 15:30:01 +00: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 20:34:58 +00:00
|
|
|
* notice that Nextcloud ships already with sensible defaults and those policies
|
2015-02-09 15:30:01 +00:00
|
|
|
* should require no modification at all for most use-cases.
|
|
|
|
*
|
2018-06-12 20:34:58 +00:00
|
|
|
* This class allows unsafe-eval of javascript and unsafe-inline of CSS.
|
|
|
|
*
|
2015-02-09 15:30:01 +00:00
|
|
|
* @package OCP\AppFramework\Http
|
2015-04-16 15:00:08 +00:00
|
|
|
* @since 8.1.0
|
2015-02-09 15:30:01 +00:00
|
|
|
*/
|
2016-01-28 13:33:02 +00:00
|
|
|
class ContentSecurityPolicy extends EmptyContentSecurityPolicy {
|
2015-02-09 15:30:01 +00:00
|
|
|
/** @var bool Whether inline JS snippets are allowed */
|
2016-01-28 13:33:02 +00:00
|
|
|
protected $inlineScriptAllowed = false;
|
2018-09-03 13:28:37 +00:00
|
|
|
/** @var bool Whether eval in JS scripts is allowed */
|
|
|
|
protected $evalScriptAllowed = false;
|
2015-02-09 15:30:01 +00:00
|
|
|
/** @var array Domains from which scripts can get loaded */
|
2016-01-28 13:33:02 +00:00
|
|
|
protected $allowedScriptDomains = [
|
2015-02-09 15:30:01 +00:00
|
|
|
'\'self\'',
|
|
|
|
];
|
|
|
|
/**
|
|
|
|
* @var bool Whether inline CSS is allowed
|
|
|
|
* TODO: Disallow per default
|
|
|
|
* @link https://github.com/owncloud/core/issues/13458
|
|
|
|
*/
|
2016-01-28 13:33:02 +00:00
|
|
|
protected $inlineStyleAllowed = true;
|
2015-02-09 15:30:01 +00:00
|
|
|
/** @var array Domains from which CSS can get loaded */
|
2016-01-28 13:33:02 +00:00
|
|
|
protected $allowedStyleDomains = [
|
2015-02-09 15:30:01 +00:00
|
|
|
'\'self\'',
|
|
|
|
];
|
|
|
|
/** @var array Domains from which images can get loaded */
|
2016-01-28 13:33:02 +00:00
|
|
|
protected $allowedImageDomains = [
|
2015-02-09 15:30:01 +00:00
|
|
|
'\'self\'',
|
2015-08-05 09:41:25 +00:00
|
|
|
'data:',
|
2015-09-29 12:18:12 +00:00
|
|
|
'blob:',
|
2015-02-09 15:30:01 +00:00
|
|
|
];
|
|
|
|
/** @var array Domains to which connections can be done */
|
2016-01-28 13:33:02 +00:00
|
|
|
protected $allowedConnectDomains = [
|
2015-02-09 15:30:01 +00:00
|
|
|
'\'self\'',
|
|
|
|
];
|
|
|
|
/** @var array Domains from which media elements can be loaded */
|
2016-01-28 13:33:02 +00:00
|
|
|
protected $allowedMediaDomains = [
|
2015-02-09 15:30:01 +00:00
|
|
|
'\'self\'',
|
|
|
|
];
|
|
|
|
/** @var array Domains from which object elements can be loaded */
|
2016-01-28 13:33:02 +00:00
|
|
|
protected $allowedObjectDomains = [];
|
2015-02-09 15:30:01 +00:00
|
|
|
/** @var array Domains from which iframes can be loaded */
|
2016-01-28 13:33:02 +00:00
|
|
|
protected $allowedFrameDomains = [];
|
2015-02-09 15:30:01 +00:00
|
|
|
/** @var array Domains from which fonts can be loaded */
|
2016-01-28 13:33:02 +00:00
|
|
|
protected $allowedFontDomains = [
|
2015-02-09 15:30:01 +00:00
|
|
|
'\'self\'',
|
2019-01-07 12:13:34 +00:00
|
|
|
'data:',
|
2015-02-09 15:30:01 +00:00
|
|
|
];
|
2015-02-26 11:54:15 +00:00
|
|
|
/** @var array Domains from which web-workers and nested browsing content can load elements */
|
2016-01-28 13:33:02 +00:00
|
|
|
protected $allowedChildSrcDomains = [];
|
2017-06-19 11:55:46 +00:00
|
|
|
|
2017-07-27 15:25:09 +00:00
|
|
|
/** @var array Domains which can embed this Nextcloud instance */
|
2019-01-08 08:33:34 +00:00
|
|
|
protected $allowedFrameAncestors = [
|
|
|
|
'\'self\'',
|
|
|
|
];
|
2018-09-03 14:47:52 +00:00
|
|
|
|
|
|
|
/** @var array Domains from which web-workers can be loaded */
|
|
|
|
protected $allowedWorkerSrcDomains = [];
|
2018-10-16 12:04:22 +00:00
|
|
|
|
|
|
|
/** @var array Locations to report violations to */
|
|
|
|
protected $reportTo = [];
|
2015-02-09 15:30:01 +00:00
|
|
|
}
|