-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SECURITY] Prohibit TypoScript in form yaml files
Only evaluate TypoScript-like instructions like ``` submitButtonLabel = TEXT submitButtonLabel.value = Bar ``` defined within `plugin.tx_form.settings.formDefinitionOverrides` and `plugin.tx_form.settings.yamlSettingsOverrides` and **not** within form definition yaml files or the form setup yaml files. This is achieved by not searching the entire form definition or form setup for TypoScript instructions, but only the actual TypoScript. Resolves: #98403 Releases: main, 11.5, 10.4 Change-Id: I7b066f109d6061715c2240b01ed15185c58fa9f5 Security-Bulletin: TYPO3-CORE-SA-2022-015 Security-References: CVE-2022-23503 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77086 Tested-by: Oliver Hader <oliver.hader@typo3.org> Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
- Loading branch information
1 parent
4ad5092
commit edf344b
Showing
4 changed files
with
255 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
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
145 changes: 145 additions & 0 deletions
145
typo3/sysext/form/Tests/Unit/Mvc/Configuration/ConfigurationManagerTest.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,145 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* 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! | ||
*/ | ||
|
||
namespace TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration; | ||
|
||
use TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager; | ||
use TYPO3\CMS\Extbase\Object\ObjectManager; | ||
use TYPO3\CMS\Extbase\Service\EnvironmentService; | ||
use TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager; | ||
use TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManagerInterface; | ||
use TYPO3\CMS\Form\Mvc\Configuration\TypoScriptService; | ||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; | ||
|
||
class ConfigurationManagerTest extends UnitTestCase | ||
{ | ||
/** | ||
* @var bool | ||
*/ | ||
protected $resetSingletonInstances = true; | ||
|
||
public function tearDown(): void | ||
{ | ||
unset($GLOBALS['TYPO3_REQUEST']); | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getConfigurationDoesNotEvaluateTypoScriptLookalikeInstructionsFromYamlSettingsInFrontendContext(): void | ||
{ | ||
$yamlSettings = [ | ||
'prototypes' => [ | ||
'standard' => [ | ||
'formElementsDefinition' => [ | ||
'Form' => [ | ||
'renderingOptions' => [ | ||
'submitButtonLabel' => 'Foo', | ||
'templateVariant' => 'version1', | ||
'addQueryString' => [ | ||
'value' => 'Baz', | ||
'_typoScriptNodeValue' => 'TEXT', | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
]; | ||
|
||
$formTypoScript = [ | ||
'settings' => [ | ||
'yamlSettingsOverrides' => [ | ||
'prototypes' => [ | ||
'standard' => [ | ||
'formElementsDefinition' => [ | ||
'Form' => [ | ||
'renderingOptions' => [ | ||
'submitButtonLabel' => [ | ||
'value' => 'Bar', | ||
'_typoScriptNodeValue' => 'TEXT', | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
]; | ||
|
||
$evaluatedFormTypoScript = [ | ||
'prototypes' => [ | ||
'standard' => [ | ||
'formElementsDefinition' => [ | ||
'Form' => [ | ||
'renderingOptions' => [ | ||
'submitButtonLabel' => 'Bar', | ||
], | ||
], | ||
], | ||
], | ||
], | ||
]; | ||
|
||
$expected = [ | ||
'prototypes' => [ | ||
'standard' => [ | ||
'formElementsDefinition' => [ | ||
'Form' => [ | ||
'renderingOptions' => [ | ||
'submitButtonLabel' => 'Bar', | ||
'templateVariant' => 'version1', | ||
'addQueryString' => [ | ||
'value' => 'Baz', | ||
'_typoScriptNodeValue' => 'TEXT', | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
]; | ||
|
||
$configurationManagerMock = $this->getAccessibleMock(ConfigurationManager::class, [ | ||
'getTypoScriptSettings', | ||
'getYamlSettingsFromCache', | ||
], [], '', false); | ||
$configurationManagerMock->method('getYamlSettingsFromCache')->with(self::anything())->willReturn($yamlSettings); | ||
|
||
$environmentServiceProphecy = $this->prophesize(EnvironmentService::class); | ||
$environmentServiceProphecy->isEnvironmentInFrontendMode()->willReturn(true); | ||
|
||
$typoScriptServiceProphecy = $this->prophesize(TypoScriptService::class); | ||
$typoScriptServiceProphecy->resolvePossibleTypoScriptConfiguration($formTypoScript['settings']['yamlSettingsOverrides'])->willReturn($evaluatedFormTypoScript); | ||
|
||
$concreteConfigurationManagerProphecy = $this->prophesize(FrontendConfigurationManager::class); | ||
$concreteConfigurationManagerProphecy->getConfiguration('form', null)->willReturn($formTypoScript); | ||
|
||
$objectManager = $this->prophesize(ObjectManager::class); | ||
$objectManager->get(TypoScriptService::class)->willReturn($typoScriptServiceProphecy->reveal()); | ||
|
||
$configurationManagerMock->_set('objectManager', $objectManager->reveal()); | ||
$configurationManagerMock->_set('concreteConfigurationManager', $concreteConfigurationManagerProphecy->reveal()); | ||
$configurationManagerMock->_set('environmentService', $environmentServiceProphecy->reveal()); | ||
|
||
$configurationManagerMock->method('getTypoScriptSettings')->with(self::anything())->willReturn([]); | ||
|
||
self::assertSame($expected, $configurationManagerMock->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_YAML_SETTINGS, 'form')); | ||
} | ||
} |