Input Validation and Representation - Header Manipulation: Cookies- C# Cookies - Header

1.1k Views Asked by At

Fortify has reported below issue Input Validation and Representation - Header Manipulation: Cookies

HttpApplication application = (HttpApplication)source;
            if (application.Context.Handler is IRequiresSessionState)
            {
                string abcCookieIdentity = "abc";
                HttpCookie abcCookie = application.Request.Cookies[abcCookieIdentity];                
                if (abcCookie == null)
                {
                    string mockIdentity = ConfigurationUtility.GetValue("AbcMockIdentity");
                    if (!string.IsNullOrWhiteSpace(mockIdentity))
                    {
                        abcCookie = new HttpCookie(abcCookieIdentity);
                        abcCookie.Secure = true;
                        abcCookie.HttpOnly = true;
                        abcCookie.Value = application.Session.SessionID + "#" + mockIdentity;
                        application.Response.Cookies.Add(abcCookie);
                    }
                }

            if (abcCookie != null)
            {
                if (application.Session != null)
                {
                    string internalSessionId = application.Session.SessionID;
                    abcCookie.Secure = true;
                    string[] cookieValues = abcCookie.Value.Split('#');

                    if (cookieValues[0].Equals(internalSessionId))
                    {
                        IIdentity identity = identity = new GenericI(cookieValues[1]);
                        IPrincipal principal = new GenericP(identity, new string[] { "Gent" });
                        Thread.CurrentPrincipal = principal;
                        application.Context.User = principal;

                        application.Request.Headers.Add("USER", cookieValues[1]);
                        
                        application.Response.Cookies.Add(abcCookie);

                        return;
                    }
                }
            }                
        }

I've tried to resolve by adding more details as cookies expiration etc.. still nothing worked.. Any help would be appreciated.. Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

I have to use Request.Form["values"] in my code.. which resolves the issue.