diff --git a/core/config.class.inc.php b/core/config.class.inc.php index 0cfbe6b4c..c806c05b5 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -1415,6 +1415,14 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ], + 'security.disable_inline_documents_sandbox' => [ + 'type' => 'bool', + 'description' => 'If true then the sandbox for documents displayed in a browser tab will be disabled; enabling scripts and other interactive content. Note that setting this to true will open the application to potential XSS attacks!', + 'default' => false, + 'value' => false, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ], 'behind_reverse_proxy' => [ 'type' => 'bool', 'description' => 'If true, then proxies custom header (X-Forwarded-*) are taken into account. Use only if the webserver is not publicly accessible (reachable only by the reverse proxy)', diff --git a/datamodels/2.x/itop-portal-base/portal/src/Controller/ObjectController.php b/datamodels/2.x/itop-portal-base/portal/src/Controller/ObjectController.php index daa4535e1..2d218da4c 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Controller/ObjectController.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Controller/ObjectController.php @@ -1097,6 +1097,11 @@ class ObjectController extends BrickController $aHeaders['Content-Type'] = $oDocument->GetMimeType(); $aHeaders['Content-Disposition'] = (($sOperation === 'display') ? 'inline' : 'attachment').';filename="'.$oDocument->GetFileName().'"'; + // N°4129 - Prevent XSS attacks & other script executions + if (utils::GetConfig()->Get('security.disable_inline_documents_sandbox') === false) { + $aHeaders['Content-Security-Policy'] = 'sandbox'; + } + return new Response($oDocument->GetData(), Response::HTTP_OK, $aHeaders); } diff --git a/pages/ajax.render.php b/pages/ajax.render.php index 92c1911bd..ffcda957e 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -831,6 +831,11 @@ try $iCacheSec = (int)utils::ReadParam('cache', 0); $oPage->set_cache($iCacheSec); + // N°4129 - Prevent XSS attacks & other script executions + if (utils::GetConfig()->Get('security.disable_inline_documents_sandbox') === false) { + $oPage->add_header('Content-Security-Policy: sandbox;'); + } + ormDocument::DownloadDocument($oPage, $sClass, $id, $sField, 'inline'); $oKPI->ComputeAndReport('Data fetch and format'); } diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index 4b8015450..3efd1cef8 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -103,7 +103,7 @@ class SetupUtils // -- First recent version that is not yet validated by Combodo (warning) const PHP_NOT_VALIDATED_VERSION = '8.0.0'; - const MIN_MEMORY_LIMIT = 33554432; // 32 * 1024 * 1024 - we can use expressions in const since PHP 5.6 but we are in the setup ! + const MIN_MEMORY_LIMIT = '32M'; const SUHOSIN_GET_MAX_VALUE_LENGTH = 2048; /** @@ -305,23 +305,19 @@ class SetupUtils // Check some more ini settings here, needed for file upload $sMemoryLimit = trim(ini_get('memory_limit')); - if (empty($sMemoryLimit)) - { + if (empty($sMemoryLimit)) { // On some PHP installations, memory_limit does not exist as a PHP setting! // (encountered on a 5.2.0 under Windows) // In that case, ini_set will not work, let's keep track of this and proceed anyway $aResult[] = new CheckResult(CheckResult::WARNING, "No memory limit has been defined in this instance of PHP"); - } - else - { + } else { // Check that the limit will allow us to load the data // - $iMemoryLimit = utils::ConvertToBytes($sMemoryLimit); - if (!utils::IsMemoryLimitOk($iMemoryLimit, self::MIN_MEMORY_LIMIT)) { - $aResult[] = new CheckResult(CheckResult::ERROR, - "memory_limit ($iMemoryLimit) is too small, the minimum value to run the application is ".self::MIN_MEMORY_LIMIT."."); - } - else { + $iCurrentMemoryLimit = utils::ConvertToBytes($sMemoryLimit); + $iMinMemoryLimit = utils::ConvertToBytes(self::MIN_MEMORY_LIMIT); + if (!utils::IsMemoryLimitOk($iCurrentMemoryLimit, $iMinMemoryLimit)) { + $aResult[] = new CheckResult(CheckResult::ERROR, "memory_limit ($sMemoryLimit) is too small, the minimum value to run the application is ".self::MIN_MEMORY_LIMIT."."); + } else { $aResult[] = new CheckResult(CheckResult::TRACE, "Info - memory_limit is $iMemoryLimit, ok."); } }