summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2019-05-24 21:42:37 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2019-07-08 20:35:15 +0200
commit5ac857bcdcd204d6dbfd86f8a09d241661cdd2c5 (patch)
tree4a02f63a1f9a2ced4e3565e97ad628c612aef5c9 /lib/private
parenteb092bbdc74fd10253e7a75850d5725df27daa25 (diff)
downloadnextcloud-server-5ac857bcdcd204d6dbfd86f8a09d241661cdd2c5.tar.gz
nextcloud-server-5ac857bcdcd204d6dbfd86f8a09d241661cdd2c5.zip
Add an event to edit the CSP
This introduces and event that can be listend to when we actually use the CSP. This means that apps no longer have to always inject their CSP but only do so when it is required. Yay for being lazy. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Security/CSP/ContentSecurityPolicyManager.php12
-rw-r--r--lib/private/Server.php6
2 files changed, 14 insertions, 4 deletions
diff --git a/lib/private/Security/CSP/ContentSecurityPolicyManager.php b/lib/private/Security/CSP/ContentSecurityPolicyManager.php
index 27a0524d3f3..332d9ebca8e 100644
--- a/lib/private/Security/CSP/ContentSecurityPolicyManager.php
+++ b/lib/private/Security/CSP/ContentSecurityPolicyManager.php
@@ -25,12 +25,21 @@ namespace OC\Security\CSP;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Security\CSP\AddContentSecurityPolicyEvent;
use OCP\Security\IContentSecurityPolicyManager;
class ContentSecurityPolicyManager implements IContentSecurityPolicyManager {
/** @var ContentSecurityPolicy[] */
private $policies = [];
+ /** @var IEventDispatcher */
+ private $dispatcher;
+
+ public function __construct(IEventDispatcher $dispatcher) {
+ $this->dispatcher = $dispatcher;
+ }
+
/** {@inheritdoc} */
public function addDefaultPolicy(EmptyContentSecurityPolicy $policy) {
$this->policies[] = $policy;
@@ -43,6 +52,9 @@ class ContentSecurityPolicyManager implements IContentSecurityPolicyManager {
* @return ContentSecurityPolicy
*/
public function getDefaultPolicy(): ContentSecurityPolicy {
+ $event = new AddContentSecurityPolicyEvent($this);
+ $this->dispatcher->dispatch(AddContentSecurityPolicyEvent::class, $event);
+
$defaultPolicy = new \OC\Security\CSP\ContentSecurityPolicy();
foreach($this->policies as $policy) {
$defaultPolicy = $this->mergePolicies($defaultPolicy, $policy);
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 6a2d8106fb6..e10967debb4 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -1029,10 +1029,8 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService(SessionStorage::class, function (Server $c) {
return new SessionStorage($c->getSession());
});
- $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
- return new ContentSecurityPolicyManager();
- });
- $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
+ $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, \OC\Security\CSP\ContentSecurityPolicyManager::class);
+ $this->registerAlias('ContentSecurityPolicyManager', \OC\Security\CSP\ContentSecurityPolicyManager::class);
$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
return new ContentSecurityPolicyNonceManager(