Skip to content

Commit

Permalink
add csp listener to run csp->addAllowedWorkerSrcDomain('blob:')
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Oct 14, 2024
1 parent 429f565 commit 29b6d87
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCA\Cospend\Capabilities;
use OCA\Cospend\Dashboard\CospendWidget;
use OCA\Cospend\Federation\CloudFederationProviderCospend;
use OCA\Cospend\Listener\CSPListener;
use OCA\Cospend\Middleware\FederationMiddleware;
use OCA\Cospend\Middleware\PublicAuthMiddleware;
use OCA\Cospend\Middleware\UserPermissionMiddleware;
Expand All @@ -28,6 +29,7 @@
use OCP\Federation\ICloudFederationProvider;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\IConfig;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
use OCP\Server;
use OCP\Util;

Expand Down Expand Up @@ -117,6 +119,7 @@ public function register(IRegistrationContext $context): void {
$context->registerMiddleware(FederationMiddleware::class);

$context->registerCapability(Capabilities::class);
$context->registerEventListener(AddContentSecurityPolicyEvent::class, CSPListener::class);
}

public function boot(IBootContext $context): void {
Expand Down
30 changes: 30 additions & 0 deletions lib/Listener/CSPListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace OCA\Cospend\Listener;

use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;

/**
* @template-implements IEventListener<AddContentSecurityPolicyEvent>
*/
class CSPListener implements IEventListener {

public function __construct(
) {
}

public function handle(Event $event): void {
if (!($event instanceof AddContentSecurityPolicyEvent)) {
return;
}

$csp = new ContentSecurityPolicy();
$csp->addAllowedWorkerSrcDomain('blob:');
$event->addPolicy($csp);
}
}

0 comments on commit 29b6d87

Please sign in to comment.