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

CSRF Protection: inconsistency between frameworks #9737

Closed
tortuetorche opened this issue Jul 24, 2015 · 2 comments
Closed

CSRF Protection: inconsistency between frameworks #9737

tortuetorche opened this issue Jul 24, 2015 · 2 comments

Comments

@tortuetorche
Copy link
Contributor

The CSRF Protection of Laravel appears to be inspired by the Ruby on Rails one.

But this code doesn't reflect the CSRF protection behaviour of Ruby on Rails.

We should compare $request->session()->token() with $request->input('_token') and if it doesn't match, we should compare the $request->session()->token() with $request->header('X-CSRF-TOKEN').

For a real world use cases: If on your page you have a <form> cached with an outdated csrf_token().
When you submit the form, the CSRF protection will check matching tokens with the outdated CSRF token then it will thrown an TokenMismatchException.
But the HTTP header X-CSRF-TOKEN sent to the server is good, so we should check matching tokens with it before throwing an exception.

PS: I know my explanations are a bit confusing, just tell me if you want more clarifications.

@spencerdeinum
Copy link
Contributor

I'm trying to think of when you would have a an invalid _token from the form but a valid X-CSRF-TOKEN.

I see that the rails one will fall through || to check both but I'm not really sure if I understand the use case.

@GrahamCampbell
Copy link
Member

I don't think we need to change anything, and anything we did change would be breaking.

tortuetorche pushed a commit to efficiently/laravel_larasset_app that referenced this issue Sep 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants