[7.0] Accept requests with the encrypted X-XSRF-TOKEN HTTP header #1069
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This updates
TokenGuard
to accept requests with a valid encryptedX-XSRF-TOKEN
HTTP header in the same way as Laravel'sVerifyCsrfToken
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 theX-XSRF-TOKEN
header on same-origin requests using the contents of theXSRF-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 theXSRF-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 validX-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 bypassTokenGuard
.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!