Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SECURITY] Deny pages' TSconfig and tsconfig_includes for non-admins
Fields `TSconfig` and `tsconfig_includes` of table `pages` can be misused by restricted users to contain malicious instructions and lead to cross-site scripting as well as arbitrary code execution. Since user input cannot be sanitized properly, the field is now available for admin users only. In addition directory traversal in TSconfig static includes has been mitigated. Resolves: #88565 Releases: master, 9.5, 8.7 Security-Commit: b4ab9cd1f0539b3af675b94aa01d26e5c4b3a1d9 Security-Bulletin: TYPO3-CORE-SA-2019-019 Change-Id: I712364fde6a76ad761a0b738756cb151dc5c22e1 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61145 Tested-by: Oliver Hader <oliver.hader@typo3.org> Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
- Loading branch information
Showing
10 changed files
with
229 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
namespace TYPO3\CMS\Core\Hooks; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use TYPO3\CMS\Core\DataHandling\DataHandler; | ||
|
||
/** | ||
* Guard to only allow modifications of pages.TSconfig for admin users. | ||
*/ | ||
class PagesTsConfigGuard | ||
{ | ||
/** | ||
* @param array $incomingFieldArray | ||
* @param string $table | ||
* @param string $id | ||
* @param DataHandler $dataHandler | ||
*/ | ||
public function processDatamap_preProcessFieldArray( | ||
array &$incomingFieldArray, | ||
string $table, | ||
string $id, | ||
DataHandler $dataHandler | ||
): void { | ||
if ($table === 'pages' && !$dataHandler->admin) { | ||
unset($incomingFieldArray['TSconfig']); | ||
unset($incomingFieldArray['tsconfig_includes']); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...s/Functional/DataHandling/Regular/Hooks/DataSet/pagesTsConfigIsConsideredForAdminUser.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"pages",,,,, | ||
,"uid","pid","title","TSconfig","tsconfig_includes" | ||
,1,0,"FunctionalTest","","" | ||
,88,1,"DataHandlerTest","","" | ||
,89,88,"Relations","","" | ||
,90,88,"Target","","" | ||
,91,1,"New page","custom.setting = 1","EXT:package/file.tsconfig" |
7 changes: 7 additions & 0 deletions
7
...s/Functional/DataHandling/Regular/Hooks/DataSet/pagesTsConfigIsIgnoredForNonAdminUser.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"pages",,,,, | ||
,"uid","pid","title","TSconfig","tsconfig_includes" | ||
,1,0,"FunctionalTest","","" | ||
,88,1,"DataHandlerTest","","" | ||
,89,88,"Relations","","" | ||
,90,88,"Target","","" | ||
,91,1,"New page","","" |
132 changes: 132 additions & 0 deletions
132
typo3/sysext/core/Tests/Functional/DataHandling/Regular/Hooks/PagesTsConfigGuardTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; | ||
use TYPO3\CMS\Core\Core\Bootstrap; | ||
use TYPO3\CMS\Core\Database\ConnectionPool; | ||
use TYPO3\CMS\Core\DataHandling\DataHandler; | ||
use TYPO3\CMS\Core\Type\Bitmask\Permission; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Core\Utility\StringUtility; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
class PagesTsConfigGuardTest extends FunctionalTestCase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $scenarioDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/Regular/DataSet/'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $assertionDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/Regular/Hooks/DataSet/'; | ||
|
||
/** | ||
* The fixture which is used when initializing a backend user | ||
* | ||
* @var string | ||
*/ | ||
protected $backendUserFixture = 'typo3/sysext/core/Tests/Functional/Fixtures/be_users.xml'; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
Bootstrap::initializeLanguageObject(); | ||
$this->importScenarioDataSet('LiveDefaultPages'); | ||
$this->importDataSet(dirname($this->backendUserFixture) . '/be_groups.xml'); | ||
// define page create permissions for backend user group 9 on page 1 | ||
GeneralUtility::makeInstance(ConnectionPool::class) | ||
->getConnectionForTable('pages') | ||
->update( | ||
'pages', | ||
['perms_groupid' => 9, 'perms_group' => Permission::ALL], | ||
['uid' => 1] | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function pagesTsConfigIsConsideredForAdminUser() | ||
{ | ||
$backendUser = $this->setUpBackendUserFromFixture(1); | ||
$identifier = StringUtility::getUniqueId('NEW'); | ||
|
||
$dataMap = [ | ||
'pages' => [ | ||
$identifier => [ | ||
'pid' => 1, | ||
'title' => 'New page', | ||
'TSconfig' => 'custom.setting = 1', | ||
'tsconfig_includes' => 'EXT:package/file.tsconfig', | ||
], | ||
], | ||
]; | ||
|
||
$this->assertProcessedDataMap($dataMap, $backendUser); | ||
$this->assertAssertionDataSet('pagesTsConfigIsConsideredForAdminUser'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function pagesTsConfigIsIgnoredForNonAdminUser() | ||
{ | ||
$backendUser = $this->setUpBackendUserFromFixture(9); | ||
$identifier = StringUtility::getUniqueId('NEW'); | ||
|
||
$dataMap = [ | ||
'pages' => [ | ||
$identifier => [ | ||
'pid' => 1, | ||
'title' => 'New page', | ||
'TSconfig' => 'custom.setting = 1', | ||
'tsconfig_includes' => 'EXT:package/file.tsconfig', | ||
], | ||
], | ||
]; | ||
|
||
$this->assertProcessedDataMap($dataMap, $backendUser); | ||
$this->assertAssertionDataSet('pagesTsConfigIsIgnoredForNonAdminUser'); | ||
} | ||
|
||
/** | ||
* @param string $dataSetName | ||
*/ | ||
private function importScenarioDataSet($dataSetName): void | ||
{ | ||
$fileName = rtrim($this->scenarioDataSetDirectory, '/') . '/' . $dataSetName . '.csv'; | ||
$fileName = GeneralUtility::getFileAbsFileName($fileName); | ||
$this->importCSVDataSet($fileName); | ||
} | ||
|
||
private function assertAssertionDataSet($dataSetName): void | ||
{ | ||
$fileName = rtrim($this->assertionDataSetDirectory, '/') . '/' . $dataSetName . '.csv'; | ||
$fileName = GeneralUtility::getFileAbsFileName($fileName); | ||
$this->assertCSVDataSet($fileName); | ||
} | ||
|
||
private function assertProcessedDataMap(array $dataMap, BackendUserAuthentication $backendUser) | ||
{ | ||
$dataHandler = GeneralUtility::makeInstance(DataHandler::class); | ||
$dataHandler->start($dataMap, [], $backendUser); | ||
$dataHandler->process_datamap(); | ||
static::assertEmpty($dataHandler->errorLog); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<dataset> | ||
<be_groups> | ||
<uid>9</uid> | ||
<pid>0</pid> | ||
<title>editors</title> | ||
<deleted>0</deleted> | ||
<db_mountpoints>1</db_mountpoints> | ||
<tables_select>pages,tt_content</tables_select> | ||
<tables_modify>pages,tt_content</tables_modify> | ||
<non_exclude_fields>pages:title,pages:TSconfig,tt_content:header,tt_content:CType,tt_content:bodytext</non_exclude_fields> | ||
</be_groups> | ||
</dataset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters