Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django CSRF cookie HttpOnly

Is it possible to set the django csrf cookie to be http-only? Alike to SESSION_COOKIE_HTTPONLY with session cookie, but for the csrf one?

like image 370
Mark Avatar asked Jun 02 '12 11:06

Mark


People also ask

Should CSRF cookie be HttpOnly?

The answer is no - the HTTPOnly flag will not mitigate any of this. But let us concentrate on solving CSRF issue.

How does Django CSRF work?

Django has a {% csrf_token %} tag that is implemented to avoid malicious attacks. It generates a token on the server-side when rendering the page and makes sure to cross-check this token for any requests coming back in. If the incoming requests do not contain the token, they are not executed.

How do I mark cookies as HttpOnly?

Here is an example of how you can do this in PHP using the setcookie function: setcookie("sessionid", "QmFieWxvbiA1", ['httponly' => true]); The last value (true) represents setting the HttpOnly attribute.


1 Answers

A new setting, CSRF_COOKIE_HTTPONLY, is available in Django 1.6+.

like image 179
knite Avatar answered Sep 28 '22 07:09

knite