Security Issues Retrieving Authentication Ticket From Current Httpcontext Rather Than From Authentication Cookie

From: Mike (anonymous_at_discussions.microsoft.com)
Date: 03/31/04

  • Next message: [MSFT]: "RE: Authenitcation, Authorization, and Personalization"
    Date: Tue, 30 Mar 2004 18:16:08 -0800
    
    

    Hi, I asked this question earlier but either no one could understand what I was asking or didn't know the answer, so I'll try again. What are security issues or risks if any involved in retrieving the authentication ticket from the current httpcontext rather than retrieving it from authentication cookie. Most of the examples I have come across retrieve the authentication ticket from the authentication cookie. I don't know how the httpcontext is built so an explantion or link might help.

    Here are two snippets of code showing how to assigned a principal to the current httpcontext.

    // Create principal from roles contained in the current httpcontext authentication tickets' userdata field
    if (Context.Request.IsAuthenticated)
    {
            string[] arrRoles;
            FormsIdentity ident;

            // retrieve user's identity from httpcontext user
            ident = (FormsIdentity)Context.User.Identity;

            // retrieve roles from the authentication ticket userdata field
            arrRoles = ident.Ticket.UserData.Split(new char[] {'|'});

            // create principal and attach to user
            Context.User = new GenericPrincipal(ident, arrRoles);
    }

    ---------------------------------------------------------------------------------------------------------------------
    // Create principal from roles contained in the authentication cookie's authentication tickets' userdata field
    //extract the forms authentication cookie
    string cookieName = FormsAuthentication.FormsCookieName;
    HttpCookie authCookie = Context.Request.Cookies[cookieName];

    if (null == authCookie)
    {
            //there is no authentication cookie
            return;
    }

    //extract and decrypt the authentication ticket from the forms authentication cookie
    FormsAuthenticationTicket authTicket = null;
    try
    {
            authTicket = FormsAuthentication.Decrypt(authCookie.Value);
    }
    catch//(Exception ex)
    {
            return;
    }

    if (null == authTicket)
    {
            //cookie failed to decryt
            return;
    }

    //parse out the pipe separate list of role names attached to the ticket when
    //the user was originally authenticated
    //when the ticket was created, the UserData property was assigned a
    //pipe delimited string of role names
    string[] roles = authTicket.UserData.Split(new char[] {'|'});

    //create a FormsIdentity object with the user name obtained from the ticket name
    //and a GenericPrincipal object that contains this identity together with the user's role list

    //create an Identity object
    FormsIdentity id = new FormsIdentity(authTicket);

    //this principal will flow throughout the request
    GenericPrincipal principal = new GenericPrincipal(id, roles);

    //attach the new principal object to the current HttpContext object
    Context.User = principal;


  • Next message: [MSFT]: "RE: Authenitcation, Authorization, and Personalization"

    Relevant Pages

    • Re: set httpcontext and still use anonymous auth, demo site
      ... However when i use anonymous the httpcontext does not get set. ... integrated authentication, however in order to demo from the internet we ... don't want to require a login prompt but still need there to be an ... just automatically login using this demo account. ...
      (microsoft.public.inetserver.iis.security)
    • Re: Logout from windows authentication??
      ... in fact, clearing the session collection won't help, since it does nothing ... Sorry I assumed you meant Integrated Windows Authentication. ... > the window should kill the current authentication process. ... >> authenticated info in the httpContext. ...
      (microsoft.public.dotnet.framework.aspnet)
    • Re: User.Identity.IsAuthenticated and requireSSL=true
      ... You have to run all pages that rely on authentication under SSL - on every request the authentication cookie is round-tripped and you don't that to be stolen or sniffed from the wire. ... back to http mode, User.Identity.IsAuthenticated becomes false again ...
      (microsoft.public.dotnet.framework.aspnet.security)
    • Re: Web request with an existing cookie...
      ... My understanding is that it depends on the type of authentication you are ... The CrendentialCache is used to store login credentials for multiple ... can I pass an authentication cookie that all ready exists on my hard drive ...
      (microsoft.public.dotnet.framework.aspnet)
    • Re: can you prevent malicious use of browser back button in forms
      ... What I'm trying to ask here is how can you prevent a malicious user making use of the forms authentication cookie that hasn't yet expired due to a timeout? ... >> I have a Web App that uses forms authentication to secure sections. ...
      (microsoft.public.dotnet.framework.aspnet.security)