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

[SecurityBundle] fix(security): user login programmatically with dedicated user checker on a firewall#54287

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

Closed

Conversation

@94noni
Copy link
Contributor

@94noni94noni commentedMar 14, 2024
edited
Loading

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
IssuesFix internal security user checker code call
LicenseMIT

Original PR at#41274 as of Symfony v6.2 => so lets target v6.4 here

When defining anuser checker on a firewall
This user checker logic forcheckPreAuth is not called at all when using theSymfony/Bundle/SecurityBundle/Security::login feature
=> this can lead to unwanted security issue


In the reproducer, check thehttps://github.com/94noni/userchecker/blob/master/src/Security/UserChecker.php (logged in user must be enabled)
The controllerhttps://github.com/94noni/userchecker/blob/master/src/Controller/AnonymousController.php get the user by its id and log
=> the user checker is not called and the user is logged in even if not enabled

@OskarStark
Copy link
Contributor

Sounds like a bugfix to me

@94noni94noni changed the titlefix(security): user login programmatically with dedicated user checker on a firewall[SecurityBundle] fix(security): user login programmatically with dedicated user checker on a firewallMar 15, 2024
@94noni94noniforce-pushed thesecurity-login-prog-user-checker branch froma93196b tobe547b5CompareMarch 15, 2024 13:39
@94noni
Copy link
ContributorAuthor

Sounds like a bugfix to me

yes

@94noni94noniforce-pushed thesecurity-login-prog-user-checker branch 2 times, most recently from961db7e to2527d07CompareMarch 15, 2024 13:53
@94noni94noni changed the base branch from7.1 to6.4March 15, 2024 13:53
@94noni94noniforce-pushed thesecurity-login-prog-user-checker branch 2 times, most recently fromd5db9d8 toe4ea9f8CompareMarch 15, 2024 14:11
{
if (!array_filter($configs)) {
trigger_deprecation('symfony/security-bundle','6.3','Enabling bundle "%s" and not configuring it is deprecated.', SecurityBundle::class);

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

fabbot cs fixer issue

->addArgument(newTaggedIteratorArgument('security.user_checker.'.$id));

// Register Firewall-specific user checker for 'security.helper' login()
$securityUserCheckerLocator =$container->getDefinition('security.user_checker_locator');
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

i "copied" such things for another locator
please tell me if its the right thing to do


$this->container->get('security.user_checker')->checkPreAuth($user);
if ($this->container->get('security.user_checker_locator')->has('security.user_checker.'.$firewallName)) {
$this->container->get('security.user_checker_locator')->get('security.user_checker.'.$firewallName)->checkPreAuth($user);
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

this is the PR fix: calling the proper firewall user checker if any

$securityUserCheckerLocator =$container->getDefinition('security.user_checker_locator');
$securityUserCheckerLocator
->replaceArgument(0,array_merge($securityUserCheckerLocator->getArgument(0), [
'security.user_checker.'.$id =>newServiceClosureArgument(newReference('security.user_checker.'.$id)),
Copy link
Member

Choose a reason for hiding this comment

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

You should reuse the chain defined just before

security.user_checker.chain.'.$id

Copy link
ContributorAuthor

@94noni94noniMar 16, 2024
edited
Loading

Choose a reason for hiding this comment

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

Thx for your comment
I fear not getting it, you mean i should add it in the locator or i should not use locator at all but inject this chained instead and use it in the security helper?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure a locator is needed. There are already "ChainChecker" registered per firewall, that have all the checkers you reference there.

The problem is -imho- that no Event is triggered during this execution (there is one for the standard behaviour (seeUserCheckerListener) login or SwitchUser) So the checkPreAuth is called only with the "main" UserChecker and not the one registered, as you already pointed.

I'm thinking instead of adding services there, it would maybe be prefereable to add a new Event ("manualLogin" -- with a better name haha) and plug the checkers in the same way they are called in the authentication events.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@smnandre thx for detailing this, I got it more
I know@chalasr and@wouterj are a lot of security subject so I would like to have more hints

my PR just want to fix the bug/security issue

Copy link
Member

@chalasrchalasrMar 31, 2024
edited
Loading

Choose a reason for hiding this comment

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

Thanks for the ping.

I'm thinking instead of adding services there, it would maybe be prefereable to add a new Event

Indeed, relying onUserCheckerListener sounds better. Maybe make it listen to aCheckUserEvent in addition toCheckPassportEvent? As this is a bugfix, that new event class should be internal at first. On 7.x we'll be able to make it public, dispatch it in the regular authentication flow and deprecate listening onCheckPassportEvent inUserCheckerListener.

94noni reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I will try to find some time this week to address both of your reviews
Thx

@symfonysymfony deleted a comment fromcarsonbotMar 16, 2024
@94noni94noniforce-pushed thesecurity-login-prog-user-checker branch 2 times, most recently from9d29a40 to29a65f9CompareApril 2, 2024 12:10
@94noni
Copy link
ContributorAuthor

@smnandre@chalasr I've push something related toour discussion

please come back to me if it is what you had in mind, so I can continue if its the legit path
thx a lot

@94noni94noniforce-pushed thesecurity-login-prog-user-checker branch from29a65f9 to6d1cf68CompareApril 2, 2024 12:24
@94noni
Copy link
ContributorAuthor

friendly ping 👋🏻
just before investing more time on CIs resolution
thx!

@xabbuhxabbuh modified the milestones:7.1,6.4May 15, 2024
@94noni
Copy link
ContributorAuthor

up please ? I really think this is important
thank you

@smnandre
Copy link
Member

up please ? I really think this is important thank you

Sorry, had a lot going on those last weeks .. seems good to me, but my opinion will have no importance here.

I think you should maybe add some tests for this new feature, and check the previous ones still pass :)


$authenticator =$this->getAuthenticator($authenticatorName,$firewallName);

$this->container->get('security.user_checker')->checkPreAuth($user);
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure that this will solve#57706,security.user_checker is still bound toInMemoryUserChecker as default.

We probably need create service that will be aware about all user_checker's per firewall and based on firewall name, all required service.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

thanks for commenting
to be franc I've tested several things, see all PR force push
so for now I am quite waiting core devs hints

i do also have created a workaround on my project until core is fixed so for now it really dont bother much in a security POV on my side

@xabbuh
Copy link
Member

@94noni I suggest trying another approach that doesn't require a new event. Can you try if#57748 fixes the issue you experience?

@94noni
Copy link
ContributorAuthor

Is it like my first approach on this PR (prior to reviews/force push) with a locator@xabbuh ?
In all ways, i will try this ok, but not at the moment as not having any computer
Thanks

@xabbuh
Copy link
Member

Is it like my first approach on this PR (prior to reviews/force push) with a locator@xabbuh ?

It really looks like that. Can you push your initial approach as I think you should then get the credit for the bugfix.

@94noni
Copy link
ContributorAuthor

Its not about the credit but more confirming my first understanding of this core code :)
As much as the root issue is fixed i will be happy
But really i would not be able to test on a machine before end of month so perhaps better merge your PR so it can be released asap :)

xabbuh and chalasr reacted with thumbs up emoji

@xabbuh
Copy link
Member

closing in favor of#57748 then 👍

@xabbuhxabbuh closed thisJul 19, 2024
@chalasr
Copy link
Member

Is it like my first approach on this PR (prior to reviews/force push) with a locator@xabbuh ?

@94noni Indeed. Looking again at the code, your original approach was correct.

TheChainUserchecker is what confused us, but actually there is no need to care about it given it's a userland class, not a core service. When it's used, it ends up being set as the firewall'suser_checker so it would ultimately be part of the service locator you first proposed.

My apologies for the confusion and thanks a lot for your work here.

94noni reacted with thumbs up emoji

@94noni94noni deleted the security-login-prog-user-checker branchAugust 7, 2024 10:10
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

2 more reviewers

@oleg-andreyevoleg-andreyevoleg-andreyev left review comments

@smnandresmnandresmnandre left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.4

Development

Successfully merging this pull request may close these issues.

8 participants

@94noni@OskarStark@smnandre@xabbuh@chalasr@oleg-andreyev@GromNaN@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp