Skip to content

Commit

Permalink
Improved workaround for Nextcloud bug #631 #633 so it works in embed …
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Nov 7, 2022
1 parent f41d40c commit a595c5d
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ public function index()
return $response;
}

$cspManager = \OC::$server->getContentSecurityPolicyNonceManager();
if (\method_exists($cspManager, 'browserSupportsCspV3') && !$cspManager->browserSupportsCspV3()) {
exit('SnappyMail does not work in this browser due to a <a href="https://github.com/the-djmaze/snappymail/issues/633">bug in Nextcloud</a>.
<br/>You must <a href="../../settings/admin/additional">turn on iframe mode</a>');
}

\OC::$server->getNavigationManager()->setActiveEntry('snappymail');

\OCP\Util::addStyle('snappymail', 'embed');
Expand All @@ -61,12 +55,19 @@ public function index()
$sAppCssMin = $oConfig->Get('labs', 'use_app_debug_css', false) ? '' : '.min';
$sLanguage = $oActions->GetLanguage(false);

$cspManager = \OC::$server->getContentSecurityPolicyNonceManager();
$sNonce = $cspManager->getNonce() ?: \SnappyMail\UUID::generate();
$csp = new ContentSecurityPolicy();
if (\method_exists($cspManager, 'browserSupportsCspV3') && !$cspManager->browserSupportsCspV3()) {
$csp->addAllowedScriptDomain("'nonce-{$sNonce}'");
}

$params = [
'Admin' => $bAdmin ? 1 : 0,
'LoadingDescriptionEsc' => \htmlspecialchars($oConfig->Get('webmail', 'loading_description', 'SnappyMail'), ENT_QUOTES|ENT_IGNORE, 'UTF-8'),
'BaseTemplates' => \RainLoop\Utils::ClearHtmlOutput($oServiceActions->compileTemplates($bAdmin)),
'BaseAppBootScript' => \file_get_contents(APP_VERSION_ROOT_PATH.'static/js'.($sAppJsMin ? '/min' : '').'/boot'.$sAppJsMin.'.js'),
'BaseAppBootScriptNonce' => $cspManager->getNonce(),
'BaseAppBootScriptNonce' => $sNonce,
'BaseLanguage' => $oActions->compileLanguage($sLanguage, $bAdmin),
'BaseAppBootCss' => \file_get_contents(APP_VERSION_ROOT_PATH.'static/css/boot'.$sAppCssMin.'.css'),
'BaseAppThemeCssLink' => $oActions->ThemeLink($bAdmin),
Expand All @@ -86,7 +87,7 @@ public function index()

$response = new TemplateResponse('snappymail', 'index_embed', $params);

$response->setContentSecurityPolicy(new ContentSecurityPolicy());
$response->setContentSecurityPolicy($csp);

return $response;
}
Expand Down

0 comments on commit a595c5d

Please sign in to comment.