diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-05-24 21:42:37 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-07-08 20:35:15 +0200 |
commit | 5ac857bcdcd204d6dbfd86f8a09d241661cdd2c5 (patch) | |
tree | 4a02f63a1f9a2ced4e3565e97ad628c612aef5c9 /lib/private/Security/CSP/ContentSecurityPolicyManager.php | |
parent | eb092bbdc74fd10253e7a75850d5725df27daa25 (diff) | |
download | nextcloud-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/Security/CSP/ContentSecurityPolicyManager.php')
-rw-r--r-- | lib/private/Security/CSP/ContentSecurityPolicyManager.php | 12 |
1 files changed, 12 insertions, 0 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); |