Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

c# - invalidate aspx authentication cookie

I have an asp.net web form. when a user authenticate, it create a Secured cookie called .aspxauth

uppon logout, I call these 2 methods

FormsAuthentication.SignOut(); 
Session.Abandon()

Problem is that we had penetration test and if I steal the cookie, logout and manually reinsert the cookie, I become loggued in again. So the .aspauth isn't invalidated server side.

I've googled it and I can't find the answer to that security breach.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Microsoft has acknowledged this issue here: https://support.microsoft.com/en-us/kb/900111

They offer several ideas for mitigating this vulnerability:

  1. protect the application by using SSL
  2. Enforce TTL and absolute expiration
  3. Use HttpOnly cookies and forms authentication in ASP.NET 2.0
  4. Use the Membership class in ASP.NET 2.0

Regarding the last one, I'll paste the contents from the site for convenience/preservation:

When you implement forms authentication in ASP.NET 2.0, you have the option of storing user information in a Membership provider. This option is a new feature that is introduced in ASP.NET 2.0. The MembershipUser object contains specific users.

If the user is logged in, you can store this information in the Comment property of the MembershipUser object. If you use this property, you can develop a mechanism to reduce cookie replay issues in ASP.NET 2.0. This mechanism would follow these steps:

  1. You create an HttpModule that hooks the PostAuthenticateRequest event.
  2. If a FormsIdentity object is in the HttpContext.User property, the FormsAuthenticationModule class recognizes the forms authentication ticket as valid.
  3. Then, the custom HttpModule class obtains a reference to the MembershipUser instance that is associated with the authenticated user. You examine the Comment property to determine whether the user is currently logged in.

Important: You must store information in the Comment property that indicates when the user explicitly signed out. Also, you must clear the information that is in the Comment property when the customer eventually signs in again.

If the user is not currently logged in as indicated by the Comment property, you must take the following actions:

  1. Clear the cookie.
  2. Set the Response.Status property to 401.
  3. Make a call to the Response.End method that will implicitly redirect the request to the logon page.

By using this method, the forms authentication cookie will only be accepted if the user has not been explicitly signed out and the forms authentication ticket has not yet expired.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...