Skip to content

Navigation Menu

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

[Security] Deprecate AnonymousToken, non-UserInterface users, and token credentials #42423

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 1 commit into from
Aug 13, 2021

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Aug 8, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? no
Deprecations? yes
Tickets Ref #41613, #34909
License MIT
Doc PR -

This is a continuation of @xabbuh's experiment in #34909 and @chalasr's work in #42050. This hopefully is the last cleanup of TokenInterface:

  • As tokens now always represent an authenticated user (and no longer e.g. the "username" input of the form), we can finally remove the weird string|\Stringable union from Token::getUser() and other helper methods and require a user to be an instance of UserInterface.
  • For the same reason, we can also deprecate token credentials. I didn't deprecate Token::eraseCredentials() as this is still used to remove credentials from UserInterface.
  • Meanwhile, this also deprecated the AnonymousToken, which we forgot in 5.3. This token is not used anymore in the new system (anonymous does no longer exists). This was also the only token in core that didn't fulfill the UserInterface requirement for authenticated tokens.

@wouterj wouterj requested a review from chalasr as a code owner August 8, 2021 10:54
@wouterj wouterj changed the title [Security] Deprecate AnonymousToken and non-UserInterface users [Security] [WIP] Deprecate AnonymousToken and non-UserInterface users Aug 8, 2021
@wouterj wouterj changed the title [Security] [WIP] Deprecate AnonymousToken and non-UserInterface users [Security] [WIP] Deprecate AnonymousToken, non-UserInterface users, and token credentials Aug 8, 2021
@wouterj wouterj force-pushed the pull-41613/token-user branch from be5dd61 to f1b28f4 Compare August 8, 2021 15:30
@wouterj wouterj requested a review from lyrixx as a code owner August 8, 2021 15:30
@wouterj wouterj changed the title [Security] [WIP] Deprecate AnonymousToken, non-UserInterface users, and token credentials [Security] Deprecate AnonymousToken, non-UserInterface users, and token credentials Aug 8, 2021
@wouterj wouterj force-pushed the pull-41613/token-user branch from f1b28f4 to 8cced53 Compare August 8, 2021 15:37
@wouterj
Copy link
Member Author

wouterj commented Aug 8, 2021

Psalm disliking the old signatures in the legacy integrations/tests is to be expected, this PR is ready imho

@wouterj wouterj force-pushed the pull-41613/token-user branch from 8cced53 to b451883 Compare August 8, 2021 16:40
@wouterj wouterj force-pushed the pull-41613/token-user branch from b451883 to 8554c93 Compare August 8, 2021 17:51
Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just minor comments.
The CHANGELOG and UPGRADE files need to be updated also

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

I just have a few questions/comments.

Can you also confirm that all the psalm errors on unmodified files are false positives?

$originalToken = new UsernamePasswordToken(new InMemoryUser('original_user', 'password', ['ROLE_SUPER_ADMIN']), 'provider', ['ROLE_SUPER_ADMIN']);
$switchUserToken = new SwitchUserToken(new InMemoryUser('user', 'passsword', ['ROLE_USER']), 'provider', ['ROLE_USER'], $originalToken);
} else {
$originalToken = new UsernamePasswordToken(new User('original_user', 'password', ['ROLE_SUPER_ADMIN']), null, 'provider', ['ROLE_SUPER_ADMIN']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make a comment here so it is more easily found when we remove code in Symfony 6.0.

(or you maybe have added this code to your list of future PRs)

@@ -49,6 +49,7 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
$user = $token->getUser();

// in case it's not an object we cannot do anything with it; E.g. "anon."
// @deprecated since 5.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// @deprecated since 5.4
// @deprecated since 5.4, $user will always be an UserInterface in 6.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// @deprecated since 5.4
// @deprecated since 5.4 , $user will always be a UserInterface in 6.0

:)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. You are correct.

@fabpot fabpot force-pushed the pull-41613/token-user branch from ba70257 to 44b843a Compare August 13, 2021 16:23
@fabpot
Copy link
Member

fabpot commented Aug 13, 2021

Thank you @wouterj.

@fabpot fabpot merged commit 76a7fe7 into symfony:5.4 Aug 13, 2021
@wouterj wouterj deleted the pull-41613/token-user branch August 13, 2021 18:37
fabpot added a commit that referenced this pull request Aug 14, 2021
This PR was merged into the 5.4 branch.

Discussion
----------

[Security] Deprecate remaining anonymous checks

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | yes
| Tickets       | Ref #41613
| License       | MIT
| Doc PR        | tbd

Deprecates the remaining checks for anonymous found in #41613.  It's WIP because the tests are failing until #42423 is merged and this PR is rebased (didn't update one test to avoid merge conflicts).

Besides this, it also introduced `IS_AUTHENTICATED` and `AuthenticationTrustResolver::isAutenticated()`. Previously, `IS_AUTHENTICATED_ANONYMOUSLY` was considered to be the "bottom type" for authenticated requests. As this is no longer true, `IS_AUTHENTICATED_REMEMBERME` is now the new "bottom type". I suggest we use an explicit bottom type (the ones introduced) instead to avoid another such update if we change something with remember me. It's also more clear on the exact intent of the check.

Commits
-------

e3aca7f [Security] Deprecate remaining anonymous checks
This was referenced Nov 5, 2021
*/
public function __construct($user, $credentials, string $firewallName, array $roles = [])
public function __construct($user, /*string*/ $firewallName, /*array*/ $roles = [])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi guys, I'm not sure how to use UsernamePasswordToken without $credentials as this change is not explained in documentation: https://symfony.com/doc/current/components/security/authentication.html

Copy link
Member Author

@wouterj wouterj Dec 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably get faster answers if you use one of the support channels: https://symfony.com/support (e.g. GitHub discussions) Not a lot of people are watching already merged PRs.

The security component is refactored during Symfony 5. Tokens now only represent authenticated tokens/sessions, so they no longer have credentials. The "pre authentication tokens" are now called passports.

We haven't updated the components docs yet, but the framework docs are upgraded to the new system. Hopefully, you'll be able to figure stuff out using e.g. https://symfony.com/doc/current/security/custom_authenticator.html

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.