|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the TYPO3 CMS project. |
| 7 | + * |
| 8 | + * It is free software; you can redistribute it and/or modify it under |
| 9 | + * the terms of the GNU General Public License, either version 2 |
| 10 | + * of the License, or any later version. |
| 11 | + * |
| 12 | + * For the full copyright and license information, please read the |
| 13 | + * LICENSE.txt file that was distributed with this source code. |
| 14 | + * |
| 15 | + * The TYPO3 project - inspiring people to share! |
| 16 | + */ |
| 17 | + |
| 18 | +namespace TYPO3\CMS\Core\Hooks; |
| 19 | + |
| 20 | +use TYPO3\CMS\Core\DataHandling\DataHandler; |
| 21 | +use TYPO3\CMS\Core\SysLog\Action\Database as SystemLogDatabaseAction; |
| 22 | +use TYPO3\CMS\Core\SysLog\Error as SystemLogErrorClassification; |
| 23 | + |
| 24 | +/** |
| 25 | + * DataHandler hook to ensure that only system maintainers can change details of system maintainers. |
| 26 | + * |
| 27 | + * @internal This class is a hook implementation and is not part of the TYPO3 Core API. |
| 28 | + */ |
| 29 | +final class SystemMaintainerAllowanceCheck |
| 30 | +{ |
| 31 | + public function processDatamap_postProcessFieldArray(string $status, string $table, int|string $id, array &$fieldArray, DataHandler $dataHandler): void |
| 32 | + { |
| 33 | + if ($table !== 'be_users' || $status !== 'update' || empty($fieldArray)) { |
| 34 | + return; |
| 35 | + } |
| 36 | + // Do not allow a non system maintainer admin to change details of system maintainers. |
| 37 | + $systemMaintainers = array_map(intval(...), $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemMaintainers'] ?? []); |
| 38 | + // False if current user is not in system maintainer list or if switch to user mode is active |
| 39 | + $isCurrentUserSystemMaintainer = $dataHandler->BE_USER->isSystemMaintainer(); |
| 40 | + $isTargetUserInSystemMaintainerList = in_array((int)$id, $systemMaintainers, true); |
| 41 | + if (!$isCurrentUserSystemMaintainer && $isTargetUserInSystemMaintainerList) { |
| 42 | + $fieldArray = []; |
| 43 | + $dataHandler->log( |
| 44 | + $table, |
| 45 | + (int)$id, |
| 46 | + SystemLogDatabaseAction::UPDATE, |
| 47 | + null, |
| 48 | + SystemLogErrorClassification::SECURITY_NOTICE, |
| 49 | + 'Only system maintainers can change details of other system maintainers. The values have not been updated.' |
| 50 | + ); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments