-
Notifications
You must be signed in to change notification settings - Fork 455
[FEATURE] Introduce Sudo-Mode Events #5893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
55 changes: 55 additions & 0 deletions
55
Documentation/ApiOverview/Events/Events/Backend/SudoModeRequiredEvent.rst
This file contains hidden or 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,55 @@ | ||
| .. include:: /Includes.rst.txt | ||
| .. index:: Events; SudoModeRequiredEvent | ||
| .. _SudoModeRequiredEvent: | ||
|
|
||
| ===================== | ||
| SudoModeRequiredEvent | ||
| ===================== | ||
|
|
||
| .. versionadded:: 12.4.32 / 13.4.13 | ||
| This event was introduced by security advisory `TYPO3-CORE-SA-2025-013 <https://typo3.org/security/advisory/typo3-core-sa-2025-013>`_ | ||
| to address challenges with single sign-on (SSO) providers. | ||
|
|
||
| The PSR-14 event | ||
| :php:`\TYPO3\CMS\Backend\Backend\Event\SudoModeRequiredEvent` is triggered before | ||
| showing the `sudo-mode verification dialog <https://docs.typo3.org/permalink/t3coreapi:backend-user-api-sudo>`_ | ||
| when managing backend user accounts. | ||
|
|
||
| This step-up authentication, introduced as part of the fix for | ||
| `TYPO3-CORE-SA-2025-013 <https://typo3.org/security/advisory/typo3-core-sa-2025-013>`_, | ||
| helps prevent unauthorized password changes. However, | ||
| it may pose challenges when using remote single sign-on (SSO) systems, which | ||
| typically do not support a separate step-up verification process. | ||
|
|
||
| This event allows developers to skip / bypass the step-up | ||
| authentication process and uses custom logic, such as identifying users | ||
| authenticated through an :abbr:`SSO (single sign-on)` system. | ||
|
|
||
| .. seealso:: | ||
|
|
||
| * The `SudoModeVerifyEvent <https://docs.typo3.org/permalink/t3coreapi:sudomodeverifyevent>`_ | ||
| is triggered before verification of a submitted password. | ||
|
|
||
| .. _SudoModeRequiredEvent-example: | ||
|
|
||
|
|
||
| Example: Use an event listener to skip step-up authentication for SSO users | ||
| =========================================================================== | ||
|
|
||
| The following example demonstrates how to use an event listener to skip step-up | ||
| authentication for `be_users` records that have an active `is_sso` flag: | ||
|
|
||
| .. literalinclude:: _SudoModeRequiredEvent/_Services.yaml | ||
| :caption: EXT:my_extension/Configuration/Services.yaml | ||
|
|
||
| .. literalinclude:: _SudoModeRequiredEvent/_SkipSudoModeDialog.php | ||
| :caption: EXT:my_extension/Classes/EventListener/SkipSudoModeDialog.php | ||
|
|
||
| See also: `StaticPasswordVerification example <https://docs.typo3.org/permalink/t3coreapi:sudomodeverifyevent-example>`_ | ||
|
|
||
| .. _SudoModeRequiredEvent-api: | ||
|
|
||
| API | ||
| === | ||
|
|
||
| .. include:: /CodeSnippets/Events/Backend/SudoModeRequiredEvent.rst.txt |
60 changes: 60 additions & 0 deletions
60
Documentation/ApiOverview/Events/Events/Backend/SudoModeVerifyEvent.rst
This file contains hidden or 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,60 @@ | ||
| .. include:: /Includes.rst.txt | ||
| .. index:: Events; SudoModeVerifyEvent | ||
| .. _SudoModeVerifyEvent: | ||
|
|
||
| =================== | ||
| SudoModeVerifyEvent | ||
| =================== | ||
|
|
||
| .. versionadded:: 12.4.32 / 13.4.13 | ||
| This event was introduced by the fix for security advisory `TYPO3-CORE-SA-2025-013 <https://typo3.org/security/advisory/typo3-core-sa-2025-013>`_ | ||
| to address challenges with single sign-on (SSO) providers. | ||
|
|
||
| The PSR-14 event | ||
| :php:`\TYPO3\CMS\Backend\Backend\Event\SudoModeVerifyEvent` is triggered before | ||
| a password submitted in `sudo-mode verification dialog | ||
| <https://docs.typo3.org/permalink/t3coreapi:backend-user-api-sudo>`_ is verified | ||
| for backend user accounts. | ||
|
|
||
| This step-up authentication mechanism, introduced as part of the fix for | ||
| `TYPO3-CORE-SA-2025-013 <https://typo3.org/security/advisory/typo3-core-sa-2025-013>`_, | ||
| may pose challenges when using remote single sign-on | ||
| (SSO) systems because they do not support a dedicated verification step. | ||
|
|
||
| This event allows developers to change the verification logic of step-up | ||
| authentication, by conditionally allowing or denying verification based | ||
| on custom logic — for example, by identifying users authenticated via an | ||
| :abbr:`SSO (single sign-on)` system. | ||
|
|
||
| .. seealso:: | ||
|
|
||
| * `SudoModeRequiredEvent <https://docs.typo3.org/permalink/t3coreapi:sudomoderequiredevent>`_ | ||
| is triggered before showing the sudo-mode verification dialog. | ||
|
|
||
| .. _SudoModeVerifyEvent-example: | ||
|
|
||
| Example: Use an event listener to modify the verification of password in sudo mode | ||
| ================================================================================== | ||
|
|
||
| The following demonstrates using the event to statically check the password for | ||
| an expected hash. | ||
|
|
||
| .. warning:: | ||
| This example has been simplified for clarity. Always use secure password | ||
| handling with salted hashing in production. **Never** hard-code a password hash as | ||
| shown below. | ||
|
|
||
| .. literalinclude:: _SudoModeRequiredEvent/_Services.yaml | ||
| :caption: EXT:my_extension/Configuration/Services.yaml | ||
|
|
||
| .. literalinclude:: _SudoModeVerifyEvent/_StaticPasswordVerification.php | ||
| :caption: EXT:my_extension/Classes/EventListener/StaticPasswordVerification.php | ||
|
|
||
| See also: `SkipSudoModeDialog example <https://docs.typo3.org/permalink/t3coreapi:sudomoderequiredevent-example>`_. | ||
|
|
||
| .. _SudoModeVerifyEvent-api: | ||
|
|
||
| API | ||
| === | ||
|
|
||
| .. include:: /CodeSnippets/Events/Backend/SudoModeVerifyEvent.rst.txt |
14 changes: 14 additions & 0 deletions
14
Documentation/ApiOverview/Events/Events/Backend/_SudoModeRequiredEvent/_Services.yaml
This file contains hidden or 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,14 @@ | ||
| services: | ||
| _defaults: | ||
| autowire: true | ||
| autoconfigure: true | ||
| public: false | ||
|
|
||
| Vendor\MyExtension\EventListener\SkipSudoModeDialog: | ||
| tags: | ||
| - name: event.listener | ||
| identifier: 'ext-myextension/skip-sudo-mode-dialog' | ||
| Vendor\MyExtension\EventListener\StaticPasswordVerification: | ||
| tags: | ||
| - name: event.listener | ||
| identifier: 'ext-myextension/static-password-verification' |
64 changes: 64 additions & 0 deletions
64
...entation/ApiOverview/Events/Events/Backend/_SudoModeRequiredEvent/_SkipSudoModeDialog.php
This file contains hidden or 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,64 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Vendor\MyExtension\EventListener; | ||
|
|
||
| use TYPO3\CMS\Backend\Hooks\DataHandlerAuthenticationContext; | ||
| use TYPO3\CMS\Backend\Security\SudoMode\Access\AccessSubjectInterface; | ||
| use TYPO3\CMS\Backend\Security\SudoMode\Access\TableAccessSubject; | ||
| use TYPO3\CMS\Backend\Security\SudoMode\Event\SudoModeRequiredEvent; | ||
| use TYPO3\CMS\Backend\Utility\BackendUtility; | ||
| use TYPO3\CMS\Core\Utility\MathUtility; | ||
|
|
||
| final class SkipSudoModeDialog | ||
| { | ||
| public function __invoke(SudoModeRequiredEvent $event): void | ||
| { | ||
| // Ensure the event context matches DataHandler operations | ||
| if ($event->getClaim()->origin !== DataHandlerAuthenticationContext::class) { | ||
| return; | ||
| } | ||
|
|
||
| // Filter for TableAccessSubject types only | ||
| $tableAccessSubjects = array_filter( | ||
| $event->getClaim()->subjects, | ||
| static fn(AccessSubjectInterface $subject): bool => $subject instanceof TableAccessSubject, | ||
| ); | ||
|
|
||
| // Abort if there are unhandled subject types | ||
| if ($event->getClaim()->subjects !== $tableAccessSubjects) { | ||
| return; | ||
| } | ||
|
|
||
| /** @var list<TableAccessSubject> $tableAccessSubjects */ | ||
| foreach ($tableAccessSubjects as $subject) { | ||
| // Expecting format: tableName.fieldName.id | ||
| if (substr_count($subject->getSubject(), '.') !== 2) { | ||
| return; | ||
| } | ||
|
|
||
| [$tableName, $fieldName, $id] = explode('.', $subject->getSubject()); | ||
|
|
||
| // Only handle be_users table | ||
| if ($tableName !== 'be_users') { | ||
| return; | ||
| } | ||
|
|
||
| // Skip if ID is not a valid integer (e.g., 'NEW' records) | ||
| if (!MathUtility::canBeInterpretedAsInteger($id)) { | ||
| continue; | ||
| } | ||
|
|
||
| $record = BackendUtility::getRecord($tableName, $id); | ||
|
|
||
| // Abort if any record does not use SSO | ||
| if (empty($record['is_sso'])) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // All conditions met — disable verification | ||
| $event->setVerificationRequired(false); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
...on/ApiOverview/Events/Events/Backend/_SudoModeVerifyEvent/_StaticPasswordVerification.php
This file contains hidden or 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); | ||
|
|
||
| namespace Example\Demo\EventListener; | ||
|
|
||
| use TYPO3\CMS\Backend\Security\SudoMode\Event\SudoModeVerifyEvent; | ||
|
|
||
| final class StaticPasswordVerification | ||
| { | ||
| public function __invoke(SudoModeVerifyEvent $event): void | ||
| { | ||
| $calculatedHash = hash('sha256', $event->getPassword()); | ||
| // static hash of `dontdothis` - just used as proof-of-concept | ||
| // side-note: in production, make use of strong salted password | ||
| $expectedHash = '3382f2e21a5471b52a85bc32ab59ab2c467f6e3cb112aef295323874f423994c'; | ||
|
|
||
| if (hash_equals($expectedHash, $calculatedHash)) { | ||
| $event->setVerified(true); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
14 changes: 14 additions & 0 deletions
14
Documentation/CodeSnippets/Events/Backend/SudoModeRequiredEvent.rst.txt
This file contains hidden or 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,14 @@ | ||
| .. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets | ||
| .. php:namespace:: TYPO3\CMS\Backend\Security\SudoMode\Event | ||
|
|
||
| .. php:class:: SudoModeRequiredEvent | ||
|
|
||
| .. php:method:: getClaim() | ||
| :returns: `\TYPO3\CMS\Backend\Security\SudoMode\Access\AccessClaim` | ||
|
|
||
| .. php:method:: isVerificationRequired() | ||
| :returns: `bool` | ||
|
|
||
| .. php:method:: setVerificationRequired(bool $verificationRequired) | ||
|
|
||
| :param $verificationRequired: the verificationRequired | ||
20 changes: 20 additions & 0 deletions
20
Documentation/CodeSnippets/Events/Backend/SudoModeVerifyEvent.rst.txt
This file contains hidden or 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,20 @@ | ||
| .. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets | ||
| .. php:namespace:: TYPO3\CMS\Backend\Security\SudoMode\Event | ||
|
|
||
| .. php:class:: SudoModeVerifyEvent | ||
|
|
||
| .. php:method:: getClaim() | ||
| :returns: `\TYPO3\CMS\Backend\Security\SudoMode\Access\AccessClaim` | ||
|
|
||
| .. php:method:: getPassword() | ||
| :returns: `string` | ||
|
|
||
| .. php:method:: isUseInstallToolPassword() | ||
| :returns: `bool` | ||
|
|
||
| .. php:method:: isVerified() | ||
| :returns: `bool` | ||
|
|
||
| .. php:method:: setVerified(bool $verified) | ||
|
|
||
| :param $verified: the verified | ||
ohader marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.