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

CSRF token #5

Open
brejoc opened this issue Feb 16, 2017 · 8 comments
Open

CSRF token #5

brejoc opened this issue Feb 16, 2017 · 8 comments
Labels

Comments

@brejoc
Copy link
Owner

brejoc commented Feb 16, 2017

Django is expecting a CSRF token with POST requests to prevent Cross Site Request Forgeries. This also includes AJAX POST requests.

With a normal form this looks like this:

<form action="" method="post">{% csrf_token %}

Looks like there are two ways to implement this.

@brejoc brejoc added the bug label Feb 16, 2017
@kezabelle
Copy link

There's a third way, I believe:
ic-on-beforeSend="xhr.setRequestHeader('X-CSRFToken', '{{ csrf_token }}');"

@brejoc
Copy link
Owner Author

brejoc commented Mar 22, 2017

You are right @kezabelle. Thanks a lot! I'm thinking about introducing a template tag to make it more convenient.

@1cg
Copy link

1cg commented Mar 22, 2017 via email

@brejoc
Copy link
Owner Author

brejoc commented Mar 22, 2017

@carsongross That would be awesome. Django is very frontend agnostic, so this is our job. I see no reason not to introduce a CSRF meta tag. I would indeed prefer this over anything else. It is easy to implement and solves the problem.
Now we only have to convince all the frameworks to use the same header field name. Django uses X-CSRFToken and Rails X-CSRF-Token. You can change that in the Django settings. But I've not tried that yet.

@ammsa
Copy link

ammsa commented Mar 26, 2017

+1 for an out of the box support on CSRF tokens

@brejoc
Copy link
Owner Author

brejoc commented Mar 31, 2019

@chg20 Any news on this? I'm just asking, because I was not following the latest changes and would like to catch up. Thanks!

@1cg
Copy link

1cg commented Mar 31, 2019

How does django encode the CSRF token?

@brejoc
Copy link
Owner Author

brejoc commented Apr 1, 2019

@chg20 Seems like the best way to get it is from the cookies. Hm… maybe intercooler could have a hook that gets called when implemented and then each framework would be able to ship a tiny snippet that would set the csrf tokens or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants