Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Security] Fix logout #24805

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
May 15, 2018
Merged

[Security] Fix logout #24805

merged 1 commit into from
May 15, 2018

Conversation

MatTheCat
Copy link
Contributor

@MatTheCat MatTheCat commented Nov 3, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #6751, #7104
License MIT

@chalasr
Copy link
Member

chalasr commented Nov 3, 2017

👎 because #7104 (comment), sorry


$listener->handle($event);

$hasResponse = $event->hasResponse();
Copy link
Member

Choose a reason for hiding this comment

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

this means that it won't stop at the first listener setting the response anymore, allowing others to set the response

Copy link
Contributor Author

@MatTheCat MatTheCat Nov 3, 2017

Choose a reason for hiding this comment

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

Nope only LogoutListener can override the response if it has been set (see https://github.com/symfony/symfony/pull/24805/files#diff-31ca8a8ce837591218082b00363149fcR65). And handle is called so #7104 (comment) doesn't apply.

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test case for this? with multiple listeners if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try but I don't know how to do it yet

@chalasr chalasr requested a review from stof November 3, 2017 13:00
@@ -359,6 +358,11 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
// Access listener
$listeners[] = new Reference('security.access_listener');

// Logout listener
if (isset($logoutListener)) {
Copy link
Member

Choose a reason for hiding this comment

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

comment should be removed (low value)
the "isset" shold be replaced by null !== $logoutListener (which implies setting the var to null when appropriate)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@MatTheCat
Copy link
Contributor Author

I guess TraceableFirewallListener will need to be updated when merging in 3.4/4.0

@MatTheCat
Copy link
Contributor Author

Is there something missing for this PR to be merged?

@@ -359,6 +360,10 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
// Access listener
$listeners[] = new Reference('security.access_listener');

if (null !== $logoutListenerId) {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we just move the whole block that starts with if (isset($firewall['logout'])) { here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope because factories rely on the definition being in the container so we must create it before but still register last.

@@ -285,16 +285,20 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
$listeners[] = new Reference($this->createContextListener($container, $contextKey));
}

// Determine default entry point
$configuredEntryPoint = isset($firewall['entry_point']) ? $firewall['entry_point'] : null;
Copy link
Member

Choose a reason for hiding this comment

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

should probably be moved back as this is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

break;
} elseif ($hasResponse) {
Copy link
Member

Choose a reason for hiding this comment

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

just if as the previous if stops the execution path with break already.

@@ -53,13 +54,21 @@ public function onKernelRequest(GetResponseEvent $event)
$exceptionListener->register($this->dispatcher);
}

$hasResponse = false;
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to create this variable. Just use $event->hasResponse() in the right place.

@stof
Copy link
Member

stof commented Nov 17, 2017

Note that this will defeat the lazy-loading added in 3.4, as the loop will always iterate until it reaches the logout listener, and it is at the end.

@MatTheCat
Copy link
Contributor Author

@chalasr @nicolas-grekas @stof @xabbuh I tried to exclude the logout listener from others to allow lazy-loading. I guess it introduced BC breaks so I would like you to review this.

@MatTheCat
Copy link
Contributor Author

MatTheCat commented Dec 3, 2017

I don't understand why tests fail on PHP > 7.0, seems like a routing issue... Tests pass on my computer with PHP 7.1.12

@MatTheCat
Copy link
Contributor Author

Should I duplicate this PR to get more visibility? The logout listener never did work so I thought this would have got more attention.

@chalasr
Copy link
Member

chalasr commented Dec 15, 2017

@MatTheCat No need for reopening a new one.
Sorry for not giving you more feedback yet, but be sure that this has my attention.
That's an important bug which exists for a long time, if we can fix it, we need to do it right.
I think it's close to be ok, you tried a lot of approaches and that's great. What prevents me to approve is the fact we need to change some public api, hence I want to review it more throughly, check it out and see if we can do that more transparently.
Note that as of 3.3 FirewallContext::getContext() is deprecated in favor of separated getListeners() and getExceptionListener(), which means we would need to add a new public method when merging this up to 3.3, hence I'm not comfortable with this as is. Please be a bit more a patient, I will give more inputs as soon as I have time.
Thanks for your understanding.

@MatTheCat
Copy link
Contributor Author

I rebased one last time. People impacted by this issue will have to disable logout in their configuration and call their handler in the controller of their logout route.


$this->assertNull($cookieJar->get('REMEMBERME'));
}
}

This comment was marked as resolved.

@chalasr
Copy link
Member

chalasr commented Dec 27, 2017

Given that this implies public API changes in patch releases, I think that the previous version would be better (passing a fake token to logout handlers if no one exists in the token storage).
@stof @xabbuh what do you think?

@chalasr
Copy link
Member

chalasr commented May 15, 2018

Does that mean mean I have to increment symfony/security version?

yea, SecurityBundle's symfony/security requirement should be "~2.7.47|~2.8.40" (#24805 (review))

@@ -21,16 +21,19 @@
interface FirewallMapInterface
{
/**
* Returns the authentication listeners, and the exception listener to use
* for the given request.
* Returns the authentication listeners, the exception listener and the logout
Copy link
Member

Choose a reason for hiding this comment

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

just chatted a bit with @nicolas-grekas, let's revert the interface changes now (changelog update not needed anymore), we need to change this on 4.1 with proper deprecation.

Copy link
Member

Choose a reason for hiding this comment

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

agreed: should be reverted and reintroduced in 4.1 with a deprecation notice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay done

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.

👍

@stof
Copy link
Member

stof commented May 15, 2018

After merging this (and once it is propagated until master), we should get another PR against master to deprecate the case of returning only 2 elements in the firewall map. This can be checked in the Firewall class.

@nicolas-grekas
Copy link
Member

Thank you @MatTheCat.

@nicolas-grekas nicolas-grekas merged commit 9e88eb5 into symfony:2.7 May 15, 2018
nicolas-grekas added a commit that referenced this pull request May 15, 2018
This PR was squashed before being merged into the 2.7 branch (closes #24805).

Discussion
----------

[Security] Fix logout

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | #6751, #7104
| License       | MIT

Commits
-------

9e88eb5 [Security] Fix logout
@chalasr
Copy link
Member

chalasr commented May 15, 2018

I'll take care of the master PR.

$listener->handle($event);

if ($event->hasResponse()) {
break;
}
}

if (null !== $logoutListener) {
$logoutListener->handle($event);
Copy link
Contributor

Choose a reason for hiding this comment

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

😍

@MatTheCat
Copy link
Contributor Author

Yay thanks!


public function __construct(array $listeners, ExceptionListener $exceptionListener = null)
public function __construct(array $listeners, ExceptionListener $exceptionListener = null, LogoutListener $logoutListener = null)
Copy link
Member

Choose a reason for hiding this comment

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

fun fact: on 3.4 & up, this class already has a 3rd argument: FirewallConfig $config
To prevent any funnier things, I suggest adding this argument in 2.7 (but ignoring its value).
WDYT? Any better idea?

Copy link
Contributor Author

@MatTheCat MatTheCat May 15, 2018

Choose a reason for hiding this comment

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

Can we do this on concerned branches only?

Copy link
Member

Choose a reason for hiding this comment

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

we could change for a setter on 2.7, not sure it's better. Here is what you propose #27280

Copy link
Member

Choose a reason for hiding this comment

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

I finally managed to merge, see 86a9c73#diff-cf0390616c24425d612bcf9ee1555111
@chalasr when doing your PR against master, please also deprecate passing a FirewallConfig as 3rd arg there.

@MatTheCat MatTheCat deleted the ticket_7104 branch May 15, 2018 21:57
@fabpot fabpot mentioned this pull request May 21, 2018
nicolas-grekas added a commit that referenced this pull request May 25, 2018
… deprecations (chalasr)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Security][SecurityBundle] FirewallMap/FirewallContext deprecations

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes/no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Next to #24805.

Commits
-------

a71ba78 [Security][SecurityBundle] FirewallMap/FirewallContext deprecations
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.

9 participants