-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SECURITY] Disallow introducing Yaml placeholders in user interface
Introducing Yaml placeholders in backend user interface can lead to information disclosure and denial-of-service senarios. This change disallows adding new placeholders and throws an exception - existing placeholders are kept. Resolves: #89401 Releases: main, 11.5, 10.4 Change-Id: I69e24de07b5327507e1bf8de990f84402078f7d4 Security-Bulletin: TYPO3-CORE-SA-2022-016 Security-References: CVE-2022-23504 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77103 Reviewed-by: Oliver Hader <oliver.hader@typo3.org> Tested-by: Oliver Hader <oliver.hader@typo3.org>
- Loading branch information
Showing
8 changed files
with
208 additions
and
5 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
22 changes: 22 additions & 0 deletions
22
typo3/sysext/core/Classes/Configuration/Loader/Exception/YamlPlaceholderException.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,22 @@ | ||
<?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\Core\Configuration\Loader\Exception; | ||
|
||
class YamlPlaceholderException extends \RuntimeException | ||
{ | ||
} |
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
102 changes: 102 additions & 0 deletions
102
typo3/sysext/core/Classes/Configuration/Loader/YamlPlaceholderGuard.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,102 @@ | ||
<?php | ||
|
||
/* | ||
* 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\Core\Configuration\Loader; | ||
|
||
use TYPO3\CMS\Core\Configuration\Loader\Exception\YamlPlaceholderException; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Core\Utility\String\StringFragmentPattern; | ||
use TYPO3\CMS\Core\Utility\String\StringFragmentSplitter; | ||
|
||
/** | ||
* A guard for protecting YAML placeholders - keeps existing, but escalates on adding new placeholders | ||
*/ | ||
class YamlPlaceholderGuard | ||
{ | ||
protected StringFragmentSplitter $fragmentSplitter; | ||
|
||
public function __construct(protected array $existingConfiguration) | ||
{ | ||
$fragmentPattern = GeneralUtility::makeInstance( | ||
StringFragmentPattern::class, | ||
StringFragmentSplitter::TYPE_EXPRESSION, | ||
YamlFileLoader::PATTERN_PARTS | ||
); | ||
$this->fragmentSplitter = GeneralUtility::makeInstance( | ||
StringFragmentSplitter::class, | ||
$fragmentPattern | ||
); | ||
} | ||
|
||
/** | ||
* Modifies existing configuration. | ||
*/ | ||
public function process(array $modified): array | ||
{ | ||
return $this->protectPlaceholders($this->existingConfiguration, $modified); | ||
} | ||
|
||
/** | ||
* Detects placeholders that have been introduced and handles* them. | ||
* (*) currently throws an exception, but could be purged or escaped as well | ||
* | ||
* @param array<string, mixed> $current | ||
* @param array<string, mixed> $modified | ||
* @param list<string> $steps configuration keys traversed so far | ||
* @return array<string, mixed> sanitized configuration (currently not used, exception thrown before) | ||
* @throws YamlPlaceholderException | ||
*/ | ||
protected function protectPlaceholders(array $current, array $modified, array $steps = []): array | ||
{ | ||
foreach ($modified as $key => $value) { | ||
$currentSteps = array_merge($steps, [$key]); | ||
if (is_array($value)) { | ||
$modified[$key] = $this->protectPlaceholders( | ||
$current[$key] ?? [], | ||
$value, | ||
$currentSteps | ||
); | ||
} elseif (is_string($value)) { | ||
$splitFlags = StringFragmentSplitter::FLAG_UNMATCHED_AS_NULL; | ||
$newFragments = $this->fragmentSplitter->split($value, $splitFlags); | ||
if (is_string($current[$key] ?? null)) { | ||
$currentFragments = $this->fragmentSplitter->split($current[$key] ?? '', $splitFlags); | ||
} else { | ||
$currentFragments = null; | ||
} | ||
// in case there are new fragments (at least one matching the pattern) | ||
if ($newFragments !== null) { | ||
// compares differences in `expression` fragments only | ||
$differences = $currentFragments === null | ||
? $newFragments->withOnlyType(StringFragmentSplitter::TYPE_EXPRESSION) | ||
: $newFragments->withOnlyType(StringFragmentSplitter::TYPE_EXPRESSION) | ||
->diff($currentFragments->withOnlyType(StringFragmentSplitter::TYPE_EXPRESSION)); | ||
if (count($differences) > 0) { | ||
throw new YamlPlaceholderException( | ||
sprintf( | ||
'Introducing placeholder%s %s for %s is not allowed', | ||
count($differences) !== 1 ? 's' : '', | ||
implode(', ', $differences->getFragments()), | ||
implode('.', $currentSteps) | ||
), | ||
1651690534 | ||
); | ||
} | ||
} | ||
} | ||
} | ||
return $modified; | ||
} | ||
} |
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
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