Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid throwing during app setup when federation classes could not be queried #488

Merged
merged 1 commit into from Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 19 additions & 13 deletions lib/AppInfo/Application.php
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