Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Security] Avoid refreshing user whenTokenInterface::getUser() returns null#59560

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

alexandre-daubois
Copy link
Member

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
IssuesFix#59559
LicenseMIT

@MatTheCat
Copy link
Contributor

I don’t think this makes sense since only authenticated tokens (aka tokens with a user) are serialized into the session, meaningrefreshUser should always retrieve a user from the token.

chalasr reacted with thumbs up emoji

@alexandre-daubois
Copy link
MemberAuthor

I think this should be covered, the added test shows that the code can fail with a token without a user. Also the issue author gives a reproducer. I suggest adding this check, so even in the case of an unlikely event of this happening, the component code doesn't crash.

@chalasr
Copy link
Member

A token is always considered authenticated and as such should hold a user IMHO. So we may rather want to enforce this e.g. by throwing an exception in case ofnull user. Pinging@wouterj and@Spomky for thoughts

alexandre-daubois reacted with thumbs up emoji

@nicolas-grekas
Copy link
Member

/cc@jorrit WDYT?

@jorrit
Copy link
Contributor

I thought I was replying on the proposed code change.

Anyway, returning null is best for me as the code is not part of a path that I control. Otherwise, an exception handler in the stack untilrefreshUser needs to be added or used for this purpose.

This is the stack trace untilContextListener.refreshUser(). In Symfony 6.4, there seem to be no appropriate exception handlers in this stack.

image

If returning null is not acceptable, I could just try to return a user with a different identifier to get the behavior I want. I just need a way to deauthenticate a user automatically when its underlying token expires.

@chalasr
Copy link
Member

Listening onCheckPassportEvent to throw aBadCredentialsException when$event->getPassport->getAttribute(OidcToken::AUTH_DATA_ATTR) is expired should do the job.

@MatTheCat
Copy link
Contributor

Couldn’t this be implemented using the underlying library token constraints?https://github.com/Drenso/symfony-oidc?tab=readme-ov-file#additional-token-claim-validation

@chalasr
Copy link
Member

Looks like there are many alternatives to achieve what's needed. Considering this andPostAuthenticationToken expecting aUser instance as constructor argument, I'd say there's nothing to do.

@MatTheCat
Copy link
Contributor

MatTheCat commentedJan 22, 2025
edited
Loading

An exception could still be appropriate to inform the developer they made something unexpected?
Like anUnexpectedValueException

The "getUser" method of a token stored in session must not return "null".

?

xabbuh reacted with thumbs up emoji

@alexandre-daubois
Copy link
MemberAuthor

Looks like there are many alternatives to achieve what's needed

Should a defensive mechanism still be added? In the current state, the underlying code and logic can fail and lead to an unmanaged PHP error

@xabbuh
Copy link
Member

I agree that this would be better than running into a PHP error.

@chalasr
Copy link
Member

Fair, PR welcome 👍

@alexandre-daubois
Copy link
MemberAuthor

Nice, I'll take care of it 🙂

chalasr and xabbuh reacted with thumbs up emoji

nicolas-grekas added a commit that referenced this pull requestJan 28, 2025
… with a null user (alexandre-daubois)This PR was merged into the 6.4 branch.Discussion----------[Security] Throw an explicit error when refreshing a token with a null user| Q             | A| ------------- | ---| Branch?       | 6.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Issues        |Fix#59559| License       | MITFollwing#59560 (comment), to prevent the code to simply fail and return an explicit message to the user.Commits-------cd427c3 [Security] Throw an explicit error when authenticating a token with a null user
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

7 participants
@alexandre-daubois@MatTheCat@chalasr@nicolas-grekas@jorrit@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp