Skip to content

Return null when csrfToken is not valid #8062

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 1 commit into from
Closed

Return null when csrfToken is not valid #8062

wants to merge 1 commit into from

Conversation

rubenrubiob
Copy link
Contributor

I am not 100% sure of this change, but throwing an InvalidCsrfTokenException when the csrfToken is not valid makes the framework redirect to the url returned by getLoginUrl method, and from there, it keeps redirecting in a loop until the browser kills the redirections.

According to the documentation for getCredentials method, it should return null when there is some parameter missing, so I guess null is the correct value to return when the csrfToken validation fails.

I am not 100% sure of this change, but throwing an `InvalidCsrfTokenException` when the csrfToken is not valid makes the framework redirect to the url returned by `getLoginUrl` method, and from there, it keeps redirecting in a loop until the browser kills the redirections.

According to the documentation for `getCredentials` method, it should return `null` when there is some parameter missing, so I guess `null` is the correct value to return when the csrfToken validation fails.
@@ -505,7 +505,7 @@ and add the following logic::
$csrfToken = $request->request->get('_csrf_token');

if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken('authenticate', $csrfToken))) {
throw new InvalidCsrfTokenException('Invalid CSRF token.');
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @rubenrubiob, as said in #7996, such change is wrong as it would allow another guard to try to authenticate this request. To stop the process here an exception needs to be thrown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, @HeahDude ,

Okay, I see it now. Nevertheless, if you throw an exception the application stays in a redirect loop until the browser kills it. Anyway, I will look further onto it in September, to try to solve the problem directly.

Thank you!

Regards.

@HeahDude HeahDude added this to the 2.8 milestone Jul 29, 2017
@javiereguiluz
Copy link
Member

Closing because this change doesn't look entirely correct ... although some change may bee needed to avoid the loop mentioned by @rubenrubiob. Thanks.

@rubenrubiob rubenrubiob deleted the patch-2 branch January 5, 2018 22:19
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