Skip to content
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

[Security] Fix event propagation for globally registered security events #39621

Merged
merged 1 commit into from
Dec 23, 2020

Conversation

scheb
Copy link
Contributor

@scheb scheb commented Dec 23, 2020

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

When new authenticator security is enabled, the AuthenticatorManager is using its own firewall-specific event dispatcher. To allow security events being listened to on the global level, RegisterGlobalSecurityEventListenersPass is there to automatically add globally registered event listeners to the firewall-specific event dispatchers.

RegisterGlobalSecurityEventListenersPass contains a list of events that are propagated, but unfortunately this list is incomplete as there are other events in AuthenticatorManager that would need too be propagated. So I added the missing (older) security events. These older events may also be registered by their name, rather than the FQN of the class, so I've also added those.

As this is targeting 5.1, I'll file another PR for the AuthenticationTokenCreatedEvent that was introduced in 5.2, as soon as this change was merged into 5.x.

On a note, I feel this "whitelist" approach to propagate security events to the global dispatcher isn't that great, because it's prone to error. Additional security events may be added in the future and adding these to RegisterGlobalSecurityEventListenersPass can easily be missed. When I added AuthenticationTokenCreatedEvent in PR #37359 I wasn't aware of this propagation mechanic existed and also no one reviewing the PR noticed it.

Additional changes:

  • Typo fix :)
  • The array_uintersect in RegisterGlobalSecurityEventListenersPassTest wasn't implemented correctly *

* That function's behavior is really odd and easy to be used in the wrong way. The callback function isn't intended to return true/false for matching items, but return -1/0/1 like sorting functions. The tests seemingly only worked by chance as returning true/false is doing pretty much the opposite of what the callback function is supposed to do.

@carsonbot carsonbot added this to the 5.1 milestone Dec 23, 2020
@scheb scheb changed the title [Security] Fix event propagation to global dispatcher for old security events [Security] Fix event propagation for globally registered security events Dec 23, 2020
Copy link
Member

@wouterj wouterj 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 agree with whitelist being suboptimal, but I can't come up with a better way unfortunately. It would be great if we somehow could add a test that verifies that all events in AuthenticatorManager are included in the compiler pass.

@nicolas-grekas
Copy link
Member

Thank you @scheb.

@nicolas-grekas
Copy link
Member

PR welcome on 5.2!

wouterj added a commit that referenced this pull request Dec 27, 2020
…opagated (scheb)

This PR was merged into the 5.1 branch.

Discussion
----------

[Security] Add test to ensure all security events are propagated

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| License       | MIT

Follow-up to #39621. As requested by @wouterj I'm adding a dedicated test case to ensure the security events are propagated from global to firewall-level event dispatcher.

I'll file another PR to add `AuthenticationTokenCreatedEvent` as soon as this has been merged and copied to the 5.2 branch, that I need to target for the `AuthenticationTokenCreatedEvent` change.

Happy holidays!

Commits
-------

e78adf7 Add test case to ensure all security events are propagated
@scheb scheb deleted the security-event-propagation branch December 28, 2020 11:40
fabpot added a commit that referenced this pull request Dec 29, 2020
…eatedEvent when globally registered (scheb)

This PR was merged into the 5.2 branch.

Discussion
----------

[Security] Fix event propagation for AuthenticationTokenCreatedEvent when globally registered

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| License       | MIT

As promised, here's the follow-up to #39621, fixing `AuthenticationTokenCreatedEvent` to be propated from the global event dispatcher to firewall-specific event dispatchers.

The event was added in Symfony 5.2, therefore the separate PR targeting the 5.2 branch.

Commits
-------

68aaf4f Add AuthenticationTokenCreatedEvent to be propagated
This was referenced Jan 27, 2021
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.

4 participants