Skip to content

Commit

Permalink
N°4129 - Security hardening
Browse files Browse the repository at this point in the history
  • Loading branch information
Molkobain committed Aug 18, 2021
1 parent 834ac00 commit 92a9a8c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/config.class.inc.php
Expand Up @@ -1161,6 +1161,14 @@ class Config
'source_of_value' => '',
'show_in_conf_sample' => false,
),
'security.disable_inline_documents_sandbox' => array(
'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,
),
);

public function IsProperty($sPropCode)
Expand Down
Expand Up @@ -1295,6 +1295,11 @@ public function DocumentAction(Request $oRequest, Application $oApp, $sOperation
$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);
}

Expand Down
7 changes: 6 additions & 1 deletion pages/ajax.render.php
Expand Up @@ -902,7 +902,12 @@ function LogErrorMessage($sMsgPrefix, $aContextInfo) {
$sField = utils::ReadParam('field', '');
if (!empty($sClass) && ($sClass != 'InlineImage') && !empty($id) && !empty($sField))
{
$oPage->add_header('X-Frame-Options:'); // resets header, see N°3416
// Resets header, see N°3416
$oPage->add_header('X-Frame-Options:');
// 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');
}
break;
Expand Down

0 comments on commit 92a9a8c

Please sign in to comment.