aio-libs / aiohttp-session

Web sessions for aiohttp.web
http://aiohttp-session.readthedocs.io/
Other
236 stars 85 forks source link

EncryptedCookieStorage doesn't sign the cookies #375

Closed pbsds closed 5 years ago

pbsds commented 5 years ago

Encrypting the cookie is nice obfuscation, but encryption alone isn't enough to stop tampering of the cookie through brute force: Imagine knowing where in the session cookie a "is_admin" value would be. Flipping a "0" to a "1" could be done through brute force. Due to this issue, this module would likely fail a security audit.

To guarantee the cookie hasn't been tampered with by the user, the cookie should also be signed. Have a look at what Paseto or JWT does. Signing is more important than encryption in my opinion, unless you store secrets in the session token you want to keep from the user.

panagiks commented 5 years ago

Hello @pbsds and thank you for your contribution.

EncryptedCookieStorage utilizes cryptography's fernet module which is an implementation of the fernet specification. With a quick look into the specification docs (and more specifically in the verifying section) you can see that message integrity validation is baked into the specification.

For implementation specific details you can look at cryptography's source code (and more specifically at the signature verification function for the fernet module).

I hope this covers your concern. Thank you again for raising a potential security issue.

Best Regards, panagiks

pbsds commented 5 years ago

Ah, great! I didn't look into the details of fernet, assuming it only did encryption. A quick mention of there being signing as well in the readme would be great.