Review main Merged

95781[FEATURE] Introduce security voters for authorization

Thomas Maroschik CR +2 V +2 Nightmare +2715 −93 updated 11/18/26, 18:51

Commit message

Authorization decisions are spread over the methods of
BackendUserAuthentication, such as isAdmin() and check(), and can only
be taken for a user object. Security voters are now the unified
concept for them: code asks the authorization checker whether the
principal is granted an attribute on a subject,
isGranted(Scope::ACCESS, $module), and voters decide.

The authorization checker of symfony/security-core is used for this.
Only symfony/security-core is added as dependency, which pulls in
symfony/password-hasher. Authentication stays on the PSR-7 pipeline
of EXT:core, so neither symfony/security-http nor the HttpFoundation
bridge is required.

Voters are registered with the new #[AsSecurityVoter] attribute.
Access is granted when at least one voter grants and no voter denies
it, so a voter can restrict any decision, also of TYPO3 Core or
another extension, but cannot overrule a denial. If all voters
abstain, access is denied. PrincipalVoter is the base class of voters
deciding for a principal; a request without principal is denied. The
read surface of the principal, the role, id and group ids of its
context and isBackendUser(), is public API now.

The backend and frontend user authentication middlewares put a
PrincipalToken of the established principal into the token storage
while the request is handled, so isGranted() decides for the
authenticated user; no token is set for an anonymous request.
Afterwards the token of an enclosing request is restored. Another
principal, such as the backend user of a frontend request, is checked
with isGrantedForUser(). The roles of a principal are the cases of
the new enum SecurityRole, cumulative, plus one role per group, such
as ROLE_BACKEND_GROUP_3. SecurityRole::USER is the base role of every
authenticated principal. There is no role for anonymous requests: the
AuthenticatedVoter of the security component decides on
IS_AUTHENTICATED and PUBLIC_ACCESS, which also covers the "hide at
login" and "show at any login" groups of frontend records.

The access to backend modules is the first decision taken with
voters. The ModuleVoter decides on the access values of TYPO3 Core:
"admin" and "systemMaintainer" on the role of the principal, "user"
on the module grants in the group data of the backend user object the
principal was built from, as check() does. Frontend principals are
denied every module. The ModuleWorkspaceVoter denies a module that is
not available in the current workspace of that backend user object.
The access value stays an open string: an extension may use a value
of its own and decide it with a voter. ModuleProvider::accessGranted()
asks the voters for every module and every backend user, as
isGranted() does; it ignores the workspace restriction only if
$respectWorkspaceRestrictions is false. LegacyUserPrincipalFactory,
the one factory building principals from user objects, now accepts
any backend user object, builds its principal once and anew only when
it changed, and registers the object for the principal, so that
decisions are taken on its group data.

Module access gates are deprecated. A gate is still asked through a
voter for an access value unknown to TYPO3 Core and for a Core access
value whose gate an extension replaced, which triggers a deprecation.

Compared to the module access gates:

* A user object without a user record is granted modules without
  access value only.
* BackendUserAuthentication::isSystemMaintainer() evaluates the switch
  user mode of the user object itself instead of $GLOBALS['BE_USER'].
* A grant of any alias of a module grants the module.
* ModuleProvider no longer takes the ModuleAccessGateRegistry, but
  the access decision manager and the principal factory.

Functional tests compare the decisions for every registered module
and a set of users with the legacy checks, and cover the switch user
mode, the development context, unset system maintainers, the workspace
restriction, frontend principals, gates of extensions and a replaced
Core gate. The public API is listed in the changelog; the bridges to
BackendUserAuthentication are internal.

Review

  • Code review CR +2 Done
    • Oli Bartsch +2
    • Benni Mack +1
  • Verified V +2 Done
    • Oli Bartsch +2
    • Benni Mack +1
    • core-ci +1 CI

Issues 4

Files 53

Show 33 more files

Review log 2745

Show 1220 earlier messages
  1. Thomas Maroschik uploaded patch set 1 09/12/26, 08:29

  2. core-ci voted on patch set 1 V +1 09/12/26, 08:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108387

  3. Thomas Maroschik updated the commit message in patch set 2 V +1 09/12/26, 09:04

  4. core-ci voted on patch set 2 V +1 09/12/26, 09:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108394

  5. Thomas Maroschik abandoned the change 10/22/26, 16:15

  6. Thomas Maroschik commented on patch set 2 10/22/26, 16:16

    Abandoned after talking with Benni, that a typo3 native auth is favored because of PSR/symfony request bridge problems.
  7. Benni Mack restored the change 10/25/26, 14:19

  8. Benni Mack uploaded patch set 3 V +1 10/25/26, 14:19

  9. core-ci voted on patch set 3 V +1 10/25/26, 14:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112511

  10. Oli Bartsch rebased onto patch set 4 V +1 10/25/26, 19:39

  11. core-ci voted on patch set 4 V +1 10/25/26, 20:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112541

  12. Benni Mack rebased onto patch set 5 V +1 10/26/26, 19:41

  13. core-ci voted on patch set 5 V +1 10/26/26, 20:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112608

  14. Benni Mack rebased onto patch set 6 V +1 11/03/26, 14:43

  15. core-ci voted on patch set 6 V +1 11/03/26, 15:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113164

  16. Benni Mack uploaded patch set 7 V +1 11/09/26, 10:12

  17. core-ci voted on patch set 7 V +1 11/09/26, 10:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113640

  18. Benni Mack uploaded patch set 8 V +1 11/10/26, 20:26

  19. core-ci voted on patch set 8 V +1 11/10/26, 20:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113947

  20. Benni Mack marked it ready for review 11/10/26, 22:10

  1. Benni Mack rebased onto patch set 9 V +1 11/13/26, 14:31

  2. core-ci voted on patch set 9 V +1 11/13/26, 16:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114339

  3. Benni Mack rebased onto patch set 10 V +1 11/13/26, 19:02

  4. core-ci voted on patch set 10 V +1 11/13/26, 20:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114375

  5. Benni Mack rebased onto patch set 11 V +1 11/13/26, 20:59

  6. core-ci voted on patch set 11 V +1 11/13/26, 22:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114397

  7. Benni Mack uploaded patch set 12 V +1 11/17/26, 15:48

  8. core-ci voted on patch set 12 V +1 11/17/26, 16:01 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114756

  9. Oli Bartsch uploaded patch set 13 V +1 11/17/26, 17:23

  10. core-ci voted on patch set 13 V +1 11/17/26, 17:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114768

  11. Oli Bartsch uploaded patch set 14 V +1 11/17/26, 17:58

  12. core-ci voted on patch set 14 V +1 11/17/26, 18:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114773

  13. Benni Mack uploaded patch set 15 V +1 11/17/26, 18:50

  14. core-ci voted on patch set 15 V -1 11/17/26, 19:02 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114779

  15. Benni Mack uploaded patch set 16 V -1 11/18/26, 08:04

  16. core-ci voted on patch set 16 V -1 11/18/26, 08:18 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114827

  17. Benni Mack uploaded patch set 17 V -1 11/18/26, 10:35

  18. core-ci voted on patch set 17 V +1 11/18/26, 10:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114846

  19. Oli Bartsch uploaded patch set 18 V +1 11/18/26, 15:22

  20. Oli Bartsch commented on patch set 18 11/18/26, 15:23

    The read part of Principal is now public API. The context's role, id and groupIds, and isBackendUser(). Creating a Principal stays internal, so the voteOnPrincipal() signature and the RST examples can stay as they are. The module workspace restriction is now decided by a new ModuleWorkspaceVoter, so isGranted(Scope::ACCESS, $module) and ModuleProvider::accessGranted() give the same answer. ModuleProvider now asks the access decision manager with a PrincipalToken, so its constructor takes AccessDecisionManagerInterface. Callers can still skip the workspace check with $respectWorkspaceRestrictions = false. ModuleVoter now denies frontend principals, the RST example is renamed to canAccessLayoutModule(). Still open: A public way to get a PrincipalUser for a backend user object.
  21. core-ci voted on patch set 18 V +1 11/18/26, 15:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114883

  22. Benni Mack voted on patch set 18 CR +1 V +1 11/18/26, 17:33

  23. Oli Bartsch voted on patch set 18 CR +1 V +1 11/18/26, 17:37

  24. Oli Bartsch voted on patch set 18 CR +2 V +2 11/18/26, 18:51

  25. Oli Bartsch merged patch set 19 11/18/26, 18:51