Skip to content

Commit

Permalink
fix: Avoid throwing during app setup when federation classes could no…
Browse files Browse the repository at this point in the history
…t be queried

Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Oct 23, 2023
1 parent 4f7346e commit 652c096
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use OCP\AppFramework\QueryException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IPreview;
use Psr\Log\LoggerInterface;

class Application extends App {
public const APP_ID = 'officeonline';
Expand Down Expand Up @@ -135,20 +136,25 @@ public function updateCSP() {
$path = '';
try {
$path = $container->getServer()->getRequest()->getPathInfo();
} catch (\Exception $e) {
}
if (strpos($path, '/apps/files') === 0 && $container->getServer()->getAppManager()->isEnabledForUser('federation')) {
/** @var TrustedServers $trustedServers */
$trustedServers = $container->query(TrustedServers::class);
/** @var FederationService $federationService */
$federationService = $container->query(FederationService::class);
$remoteAccess = $container->getServer()->getRequest()->getParam('officeonline_remote_access');

if ($remoteAccess && $trustedServers->isTrustedServer($remoteAccess)) {
$remoteCollabora = $federationService->getRemoteCollaboraURL($remoteAccess);
$policy->addAllowedFrameDomain($remoteAccess);
$policy->addAllowedFrameDomain($remoteCollabora);

if (strpos($path, '/apps/files') === 0 && $container->getServer()->getAppManager()->isEnabledForUser('federation')) {
/** @var TrustedServers $trustedServers */
$trustedServers = $container->query(TrustedServers::class);
/** @var FederationService $federationService */
$federationService = $container->query(FederationService::class);
$remoteAccess = $container->getServer()->getRequest()->getParam('officeonline_remote_access');

if ($remoteAccess && $trustedServers->isTrustedServer($remoteAccess)) {
$remoteCollabora = $federationService->getRemoteCollaboraURL($remoteAccess);
$policy->addAllowedFrameDomain($remoteAccess);
$policy->addAllowedFrameDomain($remoteCollabora);
}
}
} catch (\Throwable $e) {
\OCP\Server::get(LoggerInterface::class)->warning('Failed to gather federation hosts for CSP', [
'exception' => $e,
'app' => 'officeonline'
]);
}

$cspManager->addDefaultPolicy($policy);
Expand Down

0 comments on commit 652c096

Please sign in to comment.