Skip to content

[Security][Guard] GuardAuthenticationProvider::authenticate cannot return null #27016

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
Apr 25, 2018

Conversation

biomedia-thomas
Copy link
Contributor

@biomedia-thomas biomedia-thomas commented Apr 23, 2018

Q A
Branch? 2.8
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #26942
License MIT

Authenticate method in GuardAuthenticationProvider returned null when the token does not originate from any of the guard authenticators. This check was not done in the supports method. According to the interface authenticate cannot return null. This patch copies theguard authenticator checks to the supports method.

@linaori
Copy link
Contributor

linaori commented Apr 23, 2018

I can confirm that this fix is working

return $this->authenticateViaGuard($guardAuthenticator, $token);
}
if (null === $guardAuthenticator) {
throw new AuthenticationException('Cannot find guard authenticator this token originated from.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be an idea to add some token info? Perhaps the GuardProviderKey

@biomedia-thomas
Copy link
Contributor Author

I've added the key to the exception and also added some tests.

@chalasr chalasr modified the milestones: 3.4, 2.8 Apr 23, 2018
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.

Thanks, looks great!

As it's a bug, I think it can be merged in 2.8. However, the core team can change this for you while merging.

There is a small BC break in here, in case someone overwrote supports() to make guard authenticator support non-GuardTokenInterface tokens. But that's just weird and an edge case, so I think we can ignore it.

// no matching authenticator found - but there will be multiple GuardAuthenticationProvider
// instances that will be checked if you have multiple firewalls.

return null;
Copy link
Member

Choose a reason for hiding this comment

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

does Symfony use explicit null returns at the end of function bodies? (I'm not sure, so don't immediately change this)

Copy link
Member

@chalasr chalasr Apr 23, 2018

Choose a reason for hiding this comment

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

yes it does :) this method could have a ?AuthenticatorInterface return type starting from 4.0, explicit null would be mandatory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those two are mutually exclusive, a nullable return type cannot have an implicit return value of null. Should I fix something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, read your comment wrong, thought it read 'implicit null' for some reason. Shall I add the return type?

Copy link
Member

Choose a reason for hiding this comment

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

@biomedia-thomas nope. If this patch gets merged, it must be on 2.8 (the lowest maintained branch where it applies) where return types cannot be added due to support of old PHP versions. We'll take care of adding it when merging it up to master

@chalasr chalasr requested a review from weaverryan April 23, 2018 23:56
@nicolas-grekas nicolas-grekas changed the title [Security] [Guard] Fix for issue #26942. GuardAuthenticationProvider::authenticate cannot return null [Security] [Guard] GuardAuthenticationProvider::authenticate cannot return null Apr 25, 2018
@nicolas-grekas nicolas-grekas changed the title [Security] [Guard] GuardAuthenticationProvider::authenticate cannot return null [Security][Guard] GuardAuthenticationProvider::authenticate cannot return null Apr 25, 2018
@nicolas-grekas nicolas-grekas changed the base branch from 4.0 to 2.8 April 25, 2018 12:29
@nicolas-grekas nicolas-grekas force-pushed the ticket_26942 branch 2 times, most recently from dd9769c to 575fe1a Compare April 25, 2018 12:33
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

(rebased on 2.8)

'Token with provider key "%s" did not originate from any of the guard authenticators of provider "%s".',
$token->getGuardProviderKey(),
$this->providerKey
));
Copy link
Member

Choose a reason for hiding this comment

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

should be on one line.

Copy link
Member

Choose a reason for hiding this comment

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

on one line it is now

@nicolas-grekas
Copy link
Member

Thank you @biomedia-thomas.

@nicolas-grekas nicolas-grekas merged commit 9dff22c into symfony:2.8 Apr 25, 2018
nicolas-grekas added a commit that referenced this pull request Apr 25, 2018
…e cannot return null (biomedia-thomas)

This PR was merged into the 2.8 branch.

Discussion
----------

[Security][Guard] GuardAuthenticationProvider::authenticate cannot return null

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #26942
| License       | MIT

Authenticate method in GuardAuthenticationProvider returned null when the token does not originate from any of the guard authenticators. This check was not done in the supports method. According to the interface authenticate cannot return null. This patch copies theguard authenticator checks to the supports method.

Commits
-------

9dff22c [Security] guardAuthenticationProvider::authenticate cannot return null according to interface specification
@chalasr
Copy link
Member

chalasr commented Apr 25, 2018

Congratz for your first contrib to Symfony @biomedia-thomas, thanks

This was referenced Apr 30, 2018
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.

7 participants