简体   繁体   English

ASP.NET Forms身份验证和持久身份验证Cookie安全性

[英]ASP.NET Forms Authentication and Persistent Authentication Cookie Security

When we are using ASP.NET Forms Authentication in any of ASP.NET frameworks (ASP.NET MVC, Web Forms, etc.), we persist the authentication cookie in client's browser. 当我们在任何ASP.NET框架(ASP.NET MVC,Web窗体等)中使用ASP.NET Forms Authentication时,我们会在客户端的浏览器中保留身份验证cookie。 As a best practice, we set the cookie as HttpOnly and secure. 作为最佳实践,我们将cookie设置为HttpOnly并且安全。 We also make all transactions over SSL. 我们还通过SSL进行所有交易。 No matter what kind of mechanism we use to authenticate the user (OAuth, ASP.NET Membership Provider, etc), we still need to persist the authentication for better user experience. 无论我们使用何种机制来验证用户(OAuth,ASP.NET成员资格提供程序等),我们仍然需要保持身份验证以获得更好的用户体验。

With all those in place, I am assuming that someone can still get the cookie out of the client browser and issue requests with those auth cookie values. 有了所有这些,我假设某人仍然可以从客户端浏览器中获取cookie并使用这些auth cookie值发出请求。 This cannot be detected by the server and we would be giving protected data to someone else. 服务器无法检测到这种情况,我们会将受保护的数据提供给其他人。

One think I have in mind to lower the risk here is to ask client's password everytime when s/he tries to take some serious actions (such as changing the e-mail address, accessing profile info, etc.) but this doesn't solve anything and can be pretty annoying for the client. 有人认为我想降低这里的风险是每当他/她试图采取一些严肃的行动(例如更改电子邮件地址,访问个人资料信息等)时询问客户的密码,但这并不能解决什么,对客户来说可能很烦人。

Do you have any approach that you are actively following for this kind of issues? 对于这类问题,您有任何积极关注的方法吗? Or what would be the best possible way to persist the authentication in clients browser? 或者在客户端浏览器中保持身份验证的最佳方法是什么?

You're pretty much doing everything right to being with. 你几乎做了一切正确的事情。

If you're using the membership provider then the cookie is flagged as HTTP only (as you said) so it's not going to be accessible via client script such as a malicious piece of XSS. 如果您正在使用成员资格提供程序,那么cookie将仅标记为HTTP(如您所述),因此无法通过客户端脚本(如恶意的XSS)访问该cookie。

If you've got the cookie flagged as secure then I assume you've set the "RequireSSL" flag on forms auth to true. 如果您已将cookie标记为安全,那么我假设您已将表单身份验证中的“RequireSSL”标志设置为true。 By doing this the cookie is not going to be sent in any requests to the server that don't go out over HTTPS so even if you accidentally slip in an HTTP request (which the browser should warn the user about anyway if it's content embedded on an HTTPS page), the cookies won't be sent. 通过这样做,cookie不会在任何不通过HTTPS发送到服务器的请求中发送,因此即使您不小心插入HTTP请求(如果嵌入了内容,浏览器应警告用户无论如何一个HTTPS页面),不会发送cookie。

The only other thing you could do - and this doesn't offer much defence on top of what you've got but it's a good practice - is to use HSTS as well. 你可以做的唯一的另一件事 - 这并不能提供你所拥有的多少防御,但这是一个很好的做法 - 也是使用HSTS。 I talk about this in OWASP Top 10 for .NET developers part 9: Insufficient Transport Layer Protection as an additional means of ensuring requests continue to be sent over a secure channel. 我在面向.NET开发人员的OWASP Top 10中谈到了这一点:第9部分:传输层保护不足 ,这是确保通过安全通道继续发送请求的另一种方法。

Short of getting into some serious re-engineering of the membership provider, there's really not much more you can do. 如果没有对会员提供商进行一些严肃的重新设计,那么你可以做的事情真的不多。 You could tie the session to an IP and not accept requests if it changes but this can cause problems (ie IPs which change and doesn't protect you from multiple people on the same address). 您可以将会话绑定到IP,如果更改但不接受请求,但这可能会导致问题(即IP会更改并且不会保护您免受同一地址上的多个人的攻击)。 You could also create a fingerprint of the browser (ie everything sent in the request headers) and ensure subsequent requests match but we're getting into very fine detail here. 您还可以创建浏览器的指纹(即在请求标头中发送的所有内容)并确保后续请求匹配,但我们在此处详细介绍。

Ultimately though, security should be tailored to the value of the assets it's protecting and the likelihood of malicious activity. 但最终,安全性应根据其保护的资产的价值和恶意活动的可能性进行调整。 You don't say what it is you're protecting, but if it's a financial system you're going to go to greater lengths than if it's a simple commenting engine on a blog. 你没有说你正在保护什么 ,但如果它是一个金融系统,你会比在博客上使用简单的评论引擎更长。

In summary, it looks like you're doing a great job, just consider the appropriateness of the measures you've implemented in the context of the value of what you're protecting. 总而言之,看起来你做得很好,只考虑你所保护的价值背景下所实施的措施的适当性。 Oh - and if you're using the SQL membership provider for credential storage, make sure you read Our password hashing has no clothes then stop doing that! 哦 - 如果您正在使用SQL成员资格提供程序进行凭据存储,请确保您已阅读我们的密码哈希没有衣服然后停止这样做!

With extra on all that you have done, and having in mind this question I extra suggest, to keep more information's on the server about the user together with the authentication cookie, so if some one steal the cookie and try to use it, is also must meet and all the rest characteristics of the client to be able to use it. 有了额外的所有你已经完成的事情,并且考虑到这个问题,我额外建议,在服务器上保存关于用户的更多信息以及身份验证cookie,所以如果有人窃取cookie并尝试使用它,也是必须满足客户的所有其他特征才能使用它。

Some of the rest information's that I keep and check is they are the same together with the authentication cookie. 我保留并检查的其他一些信息是与认证cookie一起使用的信息。

  1. session cookie connected with the authentication cookie. 会话cookie与身份验证cookie连接。
  2. Browser id connected with 浏览器ID连接
  3. Ip of the user is connected with 用户的IP连接
  4. Javascript must be enable 必须启用Javascript

I know that some one can say that all that can be clone by a hacker - if the hacker can take the cookie why can not get and the rest of them. 我知道有人可以说所有这些都可以被黑客克隆 - 如果黑客可以拿走cookie,为什么不能和其他人一起。 Well nothing is 100% guarantee in the scenarios and if some one can take all that information's is actually can have and the password its self and login - at least you make it a little bit more secure. 没有什么是在场景中100%保证,如果有人可以获取所有信息,实际上可以拥有和密码自己和登录 - 至少你使它更安全一点。

You're already using HTTPS and encrypting the cookies, which is fairly secure. 您已经在使用HTTPS并加密Cookie,这是相当安全的。

If you're still worried, I would suggest storing additional information about the user's session on the server (IP address, User Agent, etc) and verifying that against the information provided during the session. 如果您仍然担心,我建议在服务器上存储有关用户会话的其他信息(IP地址,用户代理等),并根据会话期间提供的信息进行验证。

If the user changes their email address, you could send a revoke link to the original email address, so if that change is unauthorised, the true owner is alerted to the change. 如果用户更改了他们的电子邮件地址,您可以将撤销链接发送到原始电子邮件地址,因此如果该更改未经授权,则会向真正的所有者发出更改通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM