Cookies with secrets
should be encrypted.
#5209
Replies: 5 comments 1 reply
-
The Django project has a big warning about this in its docs:
|
Beta Was this translation helpful? Give feedback.
-
Encrypted cookies means either that none of the data in the cookie can be used in the browser, or that the information necessary to decrypt the cookie must also be available in the browser for the browser to decrypt it, which means your secrets aren't actually secret. The most common use for cookies is to hold something like a session ID, or a user ID. If the values stored in the cookie are intended to be secret then you might want to encrypt the cookies, but if it's just something like a Session ID then you don't really gain anything by encrypting it, because there is nothing useful that someone can do with the cookie. The warning in Django isn't really relevant, it's warning you about two things: 1. that someone who obtains your secret key can use it to create valid cookies that include any content they want (which should be obvious, that's why they are called "secrets") and 2. that if you were using the "PickleSerializer" that the cookie data can include an executable payload (that anyone would choose to use a serializer that could include executable code is the real WTF in that warning). It's also worth nothing that the Django warning clearly says that their cookies are also signed but not encrypted. It might be worthwhile to add an option to encrypt cookies, but I'd argue that if you are storing information in cookies that is sensitive enough to need encryption, then it makes just as much sense for you to encrypt it before putting it into the cookie, because for everybody else there is no security risk from having the cookies signed but not encrypted and nothing to gain by encrypting them. |
Beta Was this translation helpful? Give feedback.
-
Converting this to a Proposal discussion, as per our Development Process. |
Beta Was this translation helpful? Give feedback.
-
Isn't HttpOnly enough? Combined with signing, they ensure the cookie
And for the first case, your encryption key should be as safe / vulnerable as your secret, so I can't see how an encrypted cookie give you extra protection? |
Beta Was this translation helpful? Give feedback.
-
Not supporting encryption of cookies on the basis that it could lead to accidentally disclosing the secret in the client highlights another issue with the current verification/use of secret: today, if you use a secret and it's accidentally disclosed to the client, you might be working on the assumption that the cookie has been signed and verified, when in fact someone can sign any cookie value themselves because they have the secret. On that basis, I would suggest encryption should be supported, or otherwise the verification mechanism should be removed as the justification is contradictory. Also worth noting that other communities like Rails support both signed and encrypted session cookies https://guides.rubyonrails.org/v7.0/security.html |
Beta Was this translation helpful? Give feedback.
-
Currently cookies with
secrets
are only signed, which can lead to security vulnerabilities as it's easy to see what's inside the cookie. Providingsecrets
implies that the cookie is encrypted, so I would like to ask for either a docs update to clarify this or a change to cookies such that they are encrypted when providingsecrets
.Beta Was this translation helpful? Give feedback.
All reactions