-
Notifications
You must be signed in to change notification settings - Fork 56
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
make CSRF protection work out of the box (#71) #72
Conversation
Hey everyone. Is there any update on this? Seems to work great and would be cool to have it merged in🙂 |
I do have some second thoughts about this PR: It might be sufficient to simply add a This effectively disables CSRF protection whenever a request is made with Inertia. My thinking is that a potential CSRF attack cannot include custom headers, meaning that if a request is an inertia request, it cannot possibly be a CSRF attack. Please correct me if I'm wrong |
I did some research and you are right. I had no idea CSRF attacks cannot have custom headers. Inertia requests include custom headers, so therefore cannot be a CSRF attack. If anyone with more knowledge of CSRF can weight in on this it would be great :) |
Thanks for taking this on @buhrmi ! We sort of solved this with the installer that wires up the token by default, but that leaves out anyone who installs Inertia Rails manually, so this is much nicer. A few questions / asks.
Thanks again! I really love to see other people jumping in on the project (although that might not be apparent from our sometimes slow responses 😜) |
Not at all! Awesome project, really loving Inertia + Rails.
Certainly. While I'm not a Java developer, I think the Play Framework documentation summarized it pretty well:
If an inertia request is sent, it features the
However, I have not actually built any real world CSRF protection features - I just use whatever Rails gives me. So I'd very much like someone with more knowledge (such as @buhrmi who's idea it was) to confirm this is not a dumb thing to do. Thanks again for your fantastic work. I've been looking for something like Inertia for a very long time. |
I'm going to close this because it's been inactive for a bit and it looks like there's some debate on whether's its necessary. Please feel free to reopen if my read on this is incorrect! |
This PR removes the need for the manual steps to make CSRF protection work. It does this by storing the current form_authenticity_token in the
XSRF-TOKEN
cookie (which is picked up by Axios automatically) and adding the theX-XSRF-TOKEN
header value (which is sent by Axios by default) in the list of possible authenticity tokens. Fixes #71