From a3d2b560d092098641ac943015de5ae6275878fe Mon Sep 17 00:00:00 2001 From: djmaze Date: Wed, 28 Jul 2021 14:32:41 +0200 Subject: [PATCH] Make ', $sResult, $script); + $sScriptHash = 'sha256-'.\base64_encode(\hash('sha256', $script[1], true)); + $this->setCSP(null, $sScriptHash); +*/ } else if (!\headers_sent()) { @@ -191,6 +195,23 @@ class Service return true; } + private function setCSP(string $sScriptNonce = null) : void + { + $sContentSecurityPolicy = \trim($this->oActions->Config()->Get('security', 'content_security_policy', '')) ?: APP_DEFAULT_CSP; + if ($this->oActions->Config()->Get('security', 'use_local_proxy_for_external_images', '')) { + $sContentSecurityPolicy = \preg_replace('/(img-src[^;]+)\\shttps:(\\s|;|$)/D', '$1$2', $sContentSecurityPolicy); + $sContentSecurityPolicy = \preg_replace('/(img-src[^;]+)\\shttp:(\\s|;|$)/D', '$1$2', $sContentSecurityPolicy); + } + // Internet Explorer does not support 'nonce' + if (!\strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/')) { + if ($sScriptNonce) { + $sContentSecurityPolicy = \preg_replace("/(script-src[^;]+)'unsafe-inline'/", "\$1'nonce-{$sScriptNonce}'", $sContentSecurityPolicy); + } + $sContentSecurityPolicy = \preg_replace("/(script-src[^;]+)'unsafe-inline'/", '', $sContentSecurityPolicy); + } + \header('Content-Security-Policy: '.$sContentSecurityPolicy, true); + } + private function staticPath(string $sPath) : string { return $this->oActions->StaticPath($sPath); diff --git a/snappymail/v/0.0.0/app/templates/Index.html b/snappymail/v/0.0.0/app/templates/Index.html index 171350f16..8dd65439d 100644 --- a/snappymail/v/0.0.0/app/templates/Index.html +++ b/snappymail/v/0.0.0/app/templates/Index.html @@ -15,7 +15,6 @@ - {{BaseAppFaviconPngLinkTag}} {{BaseAppFaviconTouchLinkTag}} @@ -38,7 +37,7 @@ {{BaseTemplates}} - +