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

Prevent csrf fixation attack (phx.gen.auth + CSRF) #5725

Conversation

ftes
Copy link
Contributor

@ftes ftes commented Feb 15, 2024

Plug.CSRFProtection docs:

we recommend developers to invoke delete_csrf_token/0 every time after they log a user in, to avoid CSRF fixation attacks.

I'm curious as to why that advice is not implemented in the phx.gen.auth templates.

There probably is a good reason I'm missing. If so, add that reason to the documentation?

Further reading:
https://hexdocs.pm/plug/Plug.CSRFProtection.html
https://security.stackexchange.com/a/22936
https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html

@josevalim
Copy link
Member

Can you please add these changes to Auth.renew_session instead? In there, you can simply call delete_csrf_token() at the top of the function. Thank you.

@ftes ftes force-pushed the phx-gen-auth-delete-csrf-token-after-login branch from bc23de7 to 0f8cff2 Compare February 23, 2024 07:09
@josevalim josevalim merged commit 15e0030 into phoenixframework:main Mar 10, 2024
4 of 6 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@josevalim josevalim changed the title Prevent session fixation attack (phx.gen.auth + CSRF) Prevent csrf fixation attack (phx.gen.auth + CSRF) Mar 11, 2024
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.

None yet

2 participants