Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

aschempp
Copy link
Contributor

@aschempp aschempp commented Oct 2, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT

Unfortunately, the new User authorization checker added in #48142 (Symfony 7.3) does not allow to check for a guest (a token without a user). This PR should be seen as draft because the code is not backwards compatible. It feels wrong to add another isGrantedForGuest method – any idea about a BC way? The "usual" func_get_args wouldn't work here I think?

/cc @natewiebe13

@carsonbot

This comment has been minimized.

@aschempp aschempp marked this pull request as ready for review October 2, 2025 17:06
@aschempp aschempp requested a review from chalasr as a code owner October 2, 2025 17:06
@carsonbot carsonbot added this to the 7.4 milestone Oct 2, 2025
@carsonbot carsonbot changed the title Allow AuthorizationChecker::isGrantedForUser to check for guest permissions Allow AuthorizationChecker::isGrantedForUser to check for guest permissions Oct 2, 2025
@carsonbot carsonbot changed the title Allow AuthorizationChecker::isGrantedForUser to check for guest permissions [Security] Allow AuthorizationChecker::isGrantedForUser to check for guest permissions Oct 2, 2025
@nicolas-grekas
Copy link
Member

Indeed, I see so BC path to add the nullable type to the interface.
Maybe there's no need to change anything and you can pass a user with no roles instead?

@xabbuh
Copy link
Member

xabbuh commented Oct 3, 2025

We could introduce a class that decorates the existing one with a different signature and creates such an empty user when forwarding the call. Or maybe another helper in AbstractController doing this might also ease things?

@xabbuh
Copy link
Member

xabbuh commented Oct 3, 2025

Such a method could also be placed in the Security class in SecurityBundle.

@antonkomarev
Copy link

@aschempp there is one more possible option, to make Guest user a separate class, which implements Userinterface too. But it may require a lot of changes in legacy systems.

@chalasr
Copy link
Member

chalasr commented Oct 4, 2025

Given the purpose of this method and the fact that one aim of the now well-established authenticator system was to remove the concept of unauthenticated tokens (see e.g. #42050 and #42510), I don't think we should try to address this here, passing some kind of null user on the caller's side seems good enough.

@chalasr chalasr requested a review from wouterj October 4, 2025 11:58
@aschempp
Copy link
Contributor Author

aschempp commented Oct 8, 2025

passing some kind of null user on the caller's side seems good enough.

That would be perfectly fine with me. But shouldn't the security system then return such a null user in e.g. SecurityHelper::getUser() as well? Which certainly would be a BC break as well 😅

As an example of our current system (Contao CMS), we have permissions on objects that can be given to certain user groups, or to guests. Our voters then decides whether there is a user in the current system and which groups it belongs to, or if the object is allowed for guests. If there's a new NullUser concept, we'd need to adjust all voters to check for ->getUser() === null || $user instanceof NullUser which feels kinda wrong?

Btw. would you consider this a bug (to be fixed in 7.3 possibly) or a feature to check for guest users?

@aschempp
Copy link
Contributor Author

aschempp commented Oct 8, 2025

The most backward and forward compatible solution might be to create a new UserAndGuestAuthorizationCheckerInterface that accepts a null object. We could then deprecated the other interface …
Since most applications will probably use the core AuthorizationChecker, everyone could instantly use the new method instead of the deprecated old one.

Let me know if you like that idea, I can then update the PR (we can still decide on final naming later).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.