Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set HttpOnly cookie in Django?

How do I set HttpOnly cookie in Django?

And is it worth the effort to prevent XSS?

like image 787
Aviah Laor Avatar asked Aug 20 '10 09:08

Aviah Laor


People also ask

How do I set HttpOnly cookies?

Set HttpOnly cookie in PHPini_set("session. cookie_httponly", True); This is the most common way to set cookies in PHP, empty variables will hold their default value.

How do I save JWT in HTTP only cookies?

HTTP Only JWT Cookie: In a SPA(Single Page Application) Authentication JWT token either can be stored in browser 'LocalStorage' or in 'Cookie'. Storing JWT token inside of the cookie then the cookie should be HTTP Only. The HTTP-Only cookie nature is that it will be only accessible by the server application.

When should HttpOnly cookies be set?

Use the HttpOnly attribute to prevent access to cookie values via JavaScript. Cookies that are used for sensitive information (such as indicating authentication) should have a short lifetime, with the SameSite attribute set to Strict or Lax . (See SameSite attribute, above.)


1 Answers

Use

SESSION_COOKIE_HTTPONLY = True

in settings.py

like image 133
greg Avatar answered Oct 08 '22 01:10

greg