Skip to content

Commit

Permalink
Merge pull request #139 from smarinier/fix/138/missing_worker_policy
Browse files Browse the repository at this point in the history
fix: #138 Missing worker policy when launching assistant
  • Loading branch information
julien-nc authored Oct 2, 2024
2 parents 6b63db2 + c52a752 commit 405dd93
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use OCA\Assistant\Capabilities;
use OCA\Assistant\Listener\BeforeTemplateRenderedListener;
use OCA\Assistant\Listener\CSPListener;
use OCA\Assistant\Listener\FreePrompt\FreePromptReferenceListener;
use OCA\Assistant\Listener\SpeechToText\SpeechToTextReferenceListener;
use OCA\Assistant\Listener\TaskFailedListener;
Expand All @@ -20,6 +21,7 @@
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
use OCP\TaskProcessing\Events\TaskFailedEvent;
use OCP\TaskProcessing\Events\TaskSuccessfulEvent;

Expand Down Expand Up @@ -55,6 +57,8 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(TaskFailedEvent::class, TaskFailedListener::class);

$context->registerNotifierService(Notifier::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\Assistant\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 405dd93

Please sign in to comment.