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

FR: Return new CSRF token in response of any controller that consumes CSRF #3858

Closed
timkelty opened this issue Feb 18, 2019 · 5 comments
Closed

Comments

@timkelty
Copy link
Contributor

timkelty commented Feb 18, 2019

Currently, if you have an SPA or even just ajax requests to controllers that require a CSRF, you can pass it along, probably getting it from your template

Great – except now that CSRF has been used, so you need a new one, but if your page hasn't reloaded, you don't have one. Making a subsequent request just to get a CSRF is wasteful, and Craft doesn't really have a controller for that anyway (although you could use users/get-remaining-session-time).

What would be ideal is any controller that consumed a CSRF token, also created a new one and returned it in the json response.

Related: https://craftcms.stackexchange.com/questions/28735/csrf-in-headless-applications from @AugustMiller

@timkelty timkelty changed the title FR: Return CSRF token in response of any controller that consumes CSRF FR: Return new CSRF token in response of any controller that consumes CSRF Feb 18, 2019
@timkelty
Copy link
Contributor Author

On further examination, it seems this is only really needed for the login/logout controllers, as those generate a new CSRF.

@timkelty
Copy link
Contributor Author

👏

brandonkelly added a commit that referenced this issue Feb 19, 2019
@narration-sd
Copy link
Contributor

nice job, @timkelty - you can be a pretty handy guy :)

@khalwat
Copy link
Contributor

khalwat commented Feb 21, 2019

Thank you @timkelty

@AugustMiller
Copy link
Contributor

AugustMiller commented Feb 21, 2019

Very cool! Updated the Stack Overflow answer to mention this. ❤️

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

4 participants