8000 [security] Fetching current stored context when not explicitly specified by jaytaph · Pull Request #13342 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[security] Fetching current stored context when not explicitly specified #13342

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

Closed
wants to merge 3 commits into from
Closed

[security] Fetching current stored context when not explicitly specified #13342

wants to merge 3 commits into from

Conversation

jaytaph
Copy link
Contributor
@jaytaph jaytaph commented Jan 9, 2015
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #12160
License MIT
Doc PR N/A

This patch will use the current stored context found in a token (provided, there is one), if none has been specified.

According to a quick scan of the code, this will be the only place where getProviderKey() is used outside a specific class (the authentication providers will check token type before calling getProviderKey(), but maybe it's be a good idea to implement a "providerKeyTokenInterface" or something. It's a nicer solution imho than the current method_exists()

*/
public function __construct(ContainerInterface $container, UrlGeneratorInterface $router)
public function __construct(RequestStack $requestStack, UrlGeneratorInterface $router, TokenStorageInterface $tokenStorage)
Copy link
Contributor

Choose a reason for hiding this comment

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

BC break

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was an optional fix. I can change this back without any problems.

@jaytaph
Copy link
Contributor Author
jaytaph commented Jan 9, 2015

@stof I've implemented your comments, and reverted the BC break.

@Tobion
Copy link
Contributor
Tobion commented Jan 9, 2015

It's still a BC break because of the extra required argument.

@jaytaph
Copy link
Contributor Author
jaytaph commented Jan 9, 2015

@Tobion I see. I thought you were only talking about the container/requeststack change.

Since we already injected the container, we could (ab)use this to fetch the token-storage from that. I agree this would not be a nice thing to (this is why i removed to container in favor of the request-stack in the first place), but it would not break the signature of the constructor.

Would that be a viable option (if not, i'll just add this feature as BC break)?

@@ -68,7 +72,7 @@ public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter
*
* @return string The logout path
*/
public function getLogoutPath($key)
public function getLogoutPath($key = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

phpdoc needs update with string|null and description what it means

Copy link
Member

Choose a reason for hiding this comment

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

and this change must be documented in the UPGRADE file

Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Member

Choose a reason for hiding this comment

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

People extending the class will have to update their method signatures. That's why the BC promise requires this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xabbuh The getLogoutPath() and getLogoutUrl() from the helper can indeed used with a default argument and do not have to change.

Only the getLogoutPath() and getLogoutUrl() from the LogoutUrlExtension must have a default value, which according to the BC promise is allowed. The only question I have, in which UPGRADE file must I add this information?

@Tobion
Copy link
Contributor
Tobion commented Jan 9, 2015

You can write the constructor so that you remove the typehint and allow both the container or the request stack to be passed. So both versions work. And then you can mention in the phpdoc that passing the container is deprecated. And the TokenStorage as third parameter can be made optional ($storage = null) and say document that it will be required in symfony 3.0. If not given, fetch it from the container.

@jaytaph
Copy link
Contributor Author
jaytaph commented Jan 9, 2015

@Tobion Thanks, that makes sense.. I'll try and fix that (and also the missing docblocks)..

@jaytaph jaytaph changed the title Fetching current stored context when not explicitly specified [security] Fetching current stored context when not explicitly specified Jan 9, 2015
@jaytaph
Copy link
Contributor Author
jaytaph commented Jan 9, 2015

@Tobion I've fixed the BC break (+squashed the commits). Does it look all right now or are there still issues?

*/
public function __construct(ContainerInterface $container, UrlGeneratorInterface $router)
public function __construct($container, UrlGeneratorInterface $router, TokenStorageInterface $tokenStorage = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

please rename $container to $requestStack to be future ready

@jaytaph
Copy link
Contributor Author
jaytaph commented Jan 9, 2015

@Tobion Updated. The BadMethodCallException was there for consistency with ActionsExtension.php.

@Tobion
Copy link
Contributor
Tobion commented Jan 10, 2015

👍

$key = $token->getProviderKey();
}
}

if (!array_key_exists($key, $this->listeners)) {
throw new \InvalidArgumentException(sprintf('No LogoutListener found for firewall key "%s".', $key));
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to throw a specific exception when key is null? Probably in the condition above when we are not able to find the corresponding key? Something like "Unable to find the current firewall LogoutListener, please specify the provider key."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabpot the feature ia about handling the current context. By specifying null, it will use the current provider key so we can reuse a twig template with logout_url and/or not dependable anymore of the firewall name. If a default key cannot be found, the invalidargumentexception on the lines below will be triggered as a fallback anyway.

Copy link
Member

Choose a reason for hiding this comment

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

I do understand the change, but if the getProviderKey() method does not exist, the $key will still be null here, in which case, the error message is not the right one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'll see if I can find an exception that can be added.

@xabbuh
Copy link
Member
xabbuh commented Jan 10, 2015

What about triggering a deprecation notice when a ContainerInterface is passed to the constructor?

@jaytaph
Copy link
Contributor Author

@xabbuh i'll add one today

@jaytaph
Copy link
Contributor Author
jaytaph commented Jan 10, 2015

@fabpot @Tobion Updated. I've added the deprecation notice, and exception. I'm using the same \InvalidArgumentException, since both exceptions require the same user action (changing the provided key). I did not think this would require implementing a new exception.

*/
private function generateLogoutUrl($key, $referenceType)
{
// Fetch the current provider key from token, if possible
if (null === $key && $this->tokenStorage) {
Copy link
Member

Choose a reason for hiding this comment

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

I would be more explicit when checking the tokenStorage: null !== $this->tokenStorage

@fabpot
Copy link
Member
fabpot commented Jan 16, 2015

@jaytaph This PR looks like a mess, something wrong happened. Can you create a new one?

@jaytaph
Copy link
Contributor Author
jaytaph commented Jan 16, 2015

@fabpot Rebase gone wild, it seems. I've rebased it correctly and it should be ready.

$this->container = $container;
if ($requestStack instanceof ContainerInterface) {
$this->requestStack = $requestStack->get('request_stack');
trigger_error('The '.__CLASS__.' constructor will require a RequestStack instead of a containerInterface instance in 3.0.', E_USER_DEPRECATED);
Copy link
Contributor

Choose a reason for hiding this comment

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

/containerInterface/ContainerInterface/

@jaytaph
Copy link
Contributor Author
jaytaph commented Jan 17, 2015

@hhamon Fixed

@stof
Copy link
Member
stof commented Jan 18, 2015

👍

@fabpot
Copy link
Member
fabpot commented Jan 18, 2015

Thank you @jaytaph.

@fabpot fabpot closed this in 388ae55 Jan 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0