Should cookies be set to set a safe flag?

I have a django application. This application has 2 main cookies that are returned from the server (csrftoken and sessionid). I set the SESSION_COOKIE_SECURE and CSRF_COOKIE_SECURE flags in the settings.py file to True, and if I examine the initial request to enter my application, I see that both of these cookies have a "safe" flag set in the response from the server.

When I view cookies in my application, I notice that there are “request cookies” and “response files”. “Answer files” are those with their flags set. Cookies do not do requests.

My question is: is there a way to force cookies to set their secure flag? Is this even a security issue? My application traffic exceeds https, so all connections between the browser and server will already be encrypted from this ...

+5
source share
1 answer

In fact, this is not so ... Flags are present only in the Set-Cookie header (response).

When the client (browser) receives the Set-Cookie header, it will store the flags along with the cookie value, but only for its own use (so that the browser itself can know when and where to send the cookie if necessary).

A Cookie header (request) cannot contain flags; this is just a list of <cookie-name>=<cookie-value> pairs, and when you (the server) receive them, you are not even guaranteed to set them yourself.
This is because any application under the same domain name can set cookies for this domain. For example, an application running on example.com/foo might set cookies for example.com/bar or even another.example.com.

However, by eliminating the possibility of really terrible errors in the browser, you can be sure that if you set the "safe" flag for cookies in your response, the receiving browser will not send it over an unencrypted connection. <w> This is not really 100% guaranteed, but it is really the only option you have, and almost the entire network relies on browsers that behave correctly, so you are not alone in this.

Unfortunately, this is how cookies work. Read the official standard for them here if you are interested in learning more about them.

+3
source

Source: https://habr.com/ru/post/1236086/


All Articles