Creating a very secure login with cookies and java

倾然丶 夕夏残阳落幕 提交于 2020-01-04 02:20:07

问题


I'm designing a very secure login mechanism using play framework2. Since Play does not have a notion of sessions and keep things in the cookies (which I like) I was wondering what are the security measures I need to think about. We obviously going to use SSL to communicate the login credentials and also the cookie is going to be encrypted value of some of user's information like their email or userid. Is it possible that someone can sniff that cookie or get a hold of it from another user's cookie and reuse it? how can i make this more secure?


回答1:


In fact the cookie isn't encrypted. It is signed. This signature comes from the application.secret in your application.conf.

It means that anyone can see the content of the cookie (and eventually try to spoof other sessions or change their login/id/token...)

From Play documentation :

Of course, cookie values are signed with a secret key so the client can’t modify the cookie data (or it will be invalidated).

I am not a security guru, but, if you keep your application secret secret, it seams enough to me.

Discussion about the strength of the signature are welcome !




回答2:


Well if you want it really secure, you should general communicate via SSL not only for login. Otherwise someone can get the Cookie. The main-problem you have with the cookie-solution or better the play session is that you have no session-timeout. So imagine that I was able to get the cookie, I can use this user account forever. So you need something like a session-timeout. This becomes really tricky if there are more then one request from the same client, because both try to change the same cookie. A workaround is to handle the session timeout via cache, but have in mind that you need a distributed cache solution if you run in a cluster.

You can try to follow changes at https://launchpad.net/permsec the security solution I wrote. This is an open todo I must do.




回答3:


If there's a risk of eavesdropping the communication and stealing the cookie, you can make things harder for the attacker. For example add IP address of the computer in the signed cookie. If someone else steals it, he'll have to use the same IP address as the victim. It's not impossible but it raises the bar.



来源:https://stackoverflow.com/questions/11232304/creating-a-very-secure-login-with-cookies-and-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!