From d24069e3d062e66176a69d19adf9aad86e6f2445 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 4 Mar 2020 11:03:07 -0500 Subject: [PATCH] Look for global array so we don't load all Servers multiple times. Add all servers to allowed script-src in CSPHeaders --- web/includes/functions.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/includes/functions.php b/web/includes/functions.php index aec5d12b9..e1b1e058f 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -36,14 +36,18 @@ function noCacheHeaders() { } function CSPHeaders($view, $nonce) { - $additionalScriptSrc = ''; + global $Servers; + if ( ! $Servers ) + $Servers = ZM\Server::find(); + + $additionalScriptSrc = implode(' ', array_map(function($S){return $S->Url();}, $Servers)); switch ($view) { case 'login': { if (defined('ZM_OPT_USE_GOOG_RECAPTCHA') && defined('ZM_OPT_GOOG_RECAPTCHA_SITEKEY') && defined('ZM_OPT_GOOG_RECAPTCHA_SECRETKEY') && ZM_OPT_USE_GOOG_RECAPTCHA && ZM_OPT_GOOG_RECAPTCHA_SITEKEY && ZM_OPT_GOOG_RECAPTCHA_SECRETKEY) { - $additionalScriptSrc = "https://www.google.com"; + $additionalScriptSrc = ' https://www.google.com'; } // fall through } @@ -92,7 +96,9 @@ function CORSHeaders() { # The following is left for future reference/use. $valid = false; - $Servers = ZM\Server::find(); + global $Servers; + if ( ! $Servers ) + $Servers = ZM\Server::find(); if ( sizeof($Servers) < 1 ) { # Only need CORSHeaders in the event that there are multiple servers in use. # ICON: Might not be true. multi-port?