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

[7.0] Accept requests with the encrypted X-XSRF-TOKEN HTTP header #1069

Merged
merged 2 commits into from
Aug 20, 2019

Conversation

jessarcher
Copy link
Member

This updates TokenGuard to accept requests with a valid encrypted X-XSRF-TOKEN HTTP header in the same way as Laravel's VerifyCsrfToken middleware.

Amongst other things, this would allow us to simplify Laravel's bootstrap.js by taking advantage of Axios's default functionality to automatically send the X-XSRF-TOKEN header on same-origin requests using the contents of the XSRF-TOKEN cookie.

I note that this feature has been requested and rejected several times, often because of concerns it opens a CSRF vulnerability. I believe this is not the case because we are only opening it to accept requests with a valid X-XSRF-TOKEN HTTP header, which will never be automatically sent by the browser (on first party initiated requests or third party initiated requests), unlike the XSRF-TOKEN cookie which is always sent.

A valid X-XSRF-TOKEN HTTP header can only added by JavaScript with access to our cookies in the same way that a valid X-CSRF-TOKEN header can only be added by JavaScript with access to our DOM. It has to be running on our domain. An XSS vulnerability could bypass CSRF using either header, but that's always going to be the case and thankfully Laravel has great tools for protecting against XSS.

This is also no different to what is already happening in the VerifyCsrfToken middleware.

To help ease concerns, I have added a test to validate that the XSRF-TOKEN cookie alone is not sufficient to bypass TokenGuard.

This also addresses the PR request at #515 (comment)

I welcome as much scrutiny as possible on this as security is obviously the top priority.

Thanks!

This brings `Laravel\Passport\Guards\TokenGuard` in line with
`Illuminate\Foundation\Http\VerifyCsrfToken`.
Mistakenly copied from VerifyCsrfMiddleware
@driesvints driesvints changed the title Accept requests with the encrypted X-XSRF-TOKEN HTTP header [7.0] Accept requests with the encrypted X-XSRF-TOKEN HTTP header Aug 20, 2019
@taylorotwell taylorotwell merged commit 46558c3 into laravel:7.0 Aug 20, 2019
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

Successfully merging this pull request may close these issues.

2 participants