-
Notifications
You must be signed in to change notification settings - Fork 24.4k
[5.8] Remove unnecessary X-CSRF-TOKEN header from our Axios instance #5083
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
[5.8] Remove unnecessary X-CSRF-TOKEN header from our Axios instance #5083
Conversation
This is unnessecery code because Axios already automatically adds a X-XSRF-TOKEN header from the XSRF-TOKEN cookie encrypted value on same-origin requests. The `VerifyCsrfToken` middleware and Passport's `TokenGuard` already allow using the `X-XSRF-TOKEN` header.
Maybe this is best targetting 6.0? |
@GrahamCampbell not sure why since this isn't a breaking change. The skeleton is only used for new installs. |
Remove manual adding of X-CSRF-TOKEN header (laravel#5083)
What about the meta tag? Can’t that be removed as well? |
laravel/echo still depends on it I can't think of any reason off the top of my head why it couldn't be modified to use the |
This reverts commit aa74fcb.
This is unnessecery code because Axios already automatically adds a X-XSRF-TOKEN header from the XSRF-TOKEN cookie encrypted value on same-origin requests. The `VerifyCsrfToken` middleware and Passport's `TokenGuard` already allow using the `X-XSRF-TOKEN` header.
* release/v2.2.0: (24 commits) Bump version Apply fixes from StyleCI Upgrade Laravel to v6.5 Update clockwork .gitignore file Override config files Upgrade to Laravel v6.3 Add missing config options Fix phone number input display issue Add new reauthentication config option Update config files to Laravel v6.2 Cast process.env.MIX_HASHIDS_LENGTH to number to fix JS error Update project to Laravel v6.2 Upgrade to Laravel v6 and update composer / npm packages Update jquery.validation library Use singular guard names for email verification brokers Use singular for passwords Enforce consistency Remove manual adding of X-CSRF-TOKEN header (laravel/laravel#5083) Update config files & enforce consistency Update media config options ...
In
bootstrap.js
we currently add aX-CSRF-TOKEN
HTTP header (note the 'C') to the Axios instance that we instantiate, using the value of a<meta>
tag added by the auth scaffolding. This is not necessary because Axios already has similar functionality enabled by default where it will add aX-XSRF-TOKEN
HTTP header (note the second 'X') using the value of theXSRF-TOKEN
cookie.On a current installation of Laravel, our Axios instance requests have both the
X-CSRF-TOKEN
and theX-XSRF-TOKEN
HTTP headers. The only difference is theX-CSRF-TOKEN
value is unencrypted, while theX-XSRF-TOKEN
value is encrypted.I believe we can safely remove the
X-CSRF-TOKEN
HTTP header configuration frombootstrap.js
because Laravel already verifies requests using theX-XSRF-TOKEN
HTTP header in theVerifyCsrfToken
middleware. The same is also now true for Passport >=7.4TokenGuard
for users consuming their API with JavaScript.I have verified that this works on a fresh Laravel 5.8 installation for Axios POST requests going through our
web
middleware group, as well as requests going through theauth:api
middleware when Passport is configured as linked above.I have submitted a draft PR at laravel/docs#5382 to update the docs if this is accepted.