Skip to content

Commit

Permalink
feat: Add headers for wasm support if CO has hasWASMSupport enabled
Browse files Browse the repository at this point in the history
which was added in: CollaboraOnline/online#7784

Signed-off-by: Caolán McNamara <[email protected]>
  • Loading branch information
caolanm authored and juliusknorr committed Dec 7, 2023
1 parent e9f8d1f commit 571472e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/Listener/AddContentSecurityPolicyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace OCA\Richdocuments\Listener;

use OCA\Richdocuments\AppConfig;
use OCA\Richdocuments\Service\CapabilitiesService;
use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand All @@ -36,6 +37,7 @@ class AddContentSecurityPolicyListener implements IEventListener {
public function __construct(
private IRequest $request,
private AppConfig $config,
private CapabilitiesService $capabilitiesService,
) {
}

Expand All @@ -51,7 +53,10 @@ public function handle(Event $event): void {
$policy = new EmptyContentSecurityPolicy();
$policy->addAllowedFrameDomain("'self'");
$policy->addAllowedFrameDomain("nc:");
$policy->allowEvalWasm(true);

if ($this->capabilitiesService->hasWASMSupport()) {
$policy->allowEvalWasm(true);
}

foreach ($this->config->getDomainList() as $url) {
$policy->addAllowedFrameDomain($url);
Expand Down
15 changes: 11 additions & 4 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@

namespace OCA\Richdocuments\Listener;

use OCA\Richdocuments\Service\CapabilitiesService;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/** @template-implements IEventListener<BeforeTemplateRenderedEvent|Event> */
class BeforeTemplateRenderedListener implements IEventListener {
private CapabilitiesService $capabilitiesService;

public function __construct(CapabilitiesService $capabilitiesService) {
$this->capabilitiesService = $capabilitiesService;
}

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

// FIXME: Might be too wide, we should only do this when needed

//$event->getResponse()->addHeader('Cross-Origin-Opener-Policy', 'unsafe-none');
//$event->getResponse()->addHeader('Cross-Origin-Embedder-Policy', 'require-corp');
if ($this->capabilitiesService->hasWASMSupport()) {
$event->getResponse()->addHeader('Cross-Origin-Opener-Policy', 'same-origin');
$event->getResponse()->addHeader('Cross-Origin-Embedder-Policy', 'require-corp');
}
}
}
4 changes: 4 additions & 0 deletions lib/Service/CapabilitiesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public function hasZoteroSupport(): bool {
return $this->getCapabilities()['hasZoteroSupport'] ?? false;
}

public function hasWASMSupport(): bool {
return $this->getCapabilities()['hasWASMSupport'] ?? false;
}

public function getProductName(): string {
$theme = $this->config->getAppValue(Application::APPNAME, 'theme', 'nextcloud');

Expand Down

0 comments on commit 571472e

Please sign in to comment.