Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Cannot access sessionid cookie using Javascript

I tried using several mechanisms, including the jquery cookie plugin. When I try to read this cookie, I always get an empty result. Chrome's Developer Console shows that the sessionid cookie is indeed set. However, there's a checkmark for the HTTP column for that cookie, which is different than the other cookies. I'm developing on my localhost, if that makes a difference.

like image 611
lairtech Avatar asked Jul 04 '13 18:07

lairtech


1 Answers

It's a HTTP-only cookie; they cannot be read by JavaScript.

http://en.wikipedia.org/wiki/HTTP_cookie#Secure_and_HttpOnly

It's explained in the documentation about sessions:

https://docs.djangoproject.com/en/dev/topics/http/sessions/#using-cookie-based-sessions

The behavior can be changed by setting SESSION_COOKIE_HTTPONLY to false (but that is not recommended; see link above).

like image 83
propeller Avatar answered Nov 14 '22 23:11

propeller