Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an HTTPONLY cookie in Flask

I read Set "secure" attribute for Flask cookies, but it's for setting secure cookies, but I'm trying to set HTTPONLY cookies. They both are kind-of-secure cookies, but differ in specs (read more).

The cookie needs to be protected because it is about users' logging in information.

like image 339
이기름 Avatar asked Nov 24 '19 04:11

이기름


People also ask

How do you set HttpOnly cookie Flask?

Flask provides a configuration value SESSION_COOKIE_HTTPONLY which controls whether cookies are set to be http only. By default, however, it is set to True , so unless it's explicitly set to False , cookies will be http only.

How do you set cookies in a Flask?

In Flask, cookies are set on response object. Use make_response() function to get response object from return value of a view function. After that, use the set_cookie() function of response object to store a cookie. Reading back a cookie is easy.

How do you secure a cookie in Flask?

Flask cookies should be handled securely by setting secure=True, httponly=True, and samesite='Lax' in response. set_cookie(...). If these parameters are not properly set, your cookies are not properly protected and are at risk of being stolen by an attacker.


1 Answers

Flask provides a configuration value SESSION_COOKIE_HTTPONLY which controls whether cookies are set to be http only. By default, however, it is set to True, so unless it's explicitly set to False, cookies will be http only.

like image 193
Razzi Abuissa Avatar answered Oct 19 '22 16:10

Razzi Abuissa