Secure Flag for ASPXAUTH Cookie

2019-03-27 07:24发布

问题:

We have an externally facing application which was penetration-tested by an external security company. Application has been developed on ASP.NET MVC4 and running on IIS8/Windows 2012 Server.

One of the vulnerabilities reported was ASPXAUTH is not secure. When I checked on the cookie inspector, there are some cookies with Secure flag. But ASPXAUTH was not one of them.

I did a bit of research, and set these flags below on the web.config

<forms loginUrl="~/Account/Login" timeout="2880"  requireSSL=""  name="AppName" />

and

<httpCookies httpOnlyCookies="true" requireSSL="true" />

Despite these settings, the authentication cookie is not marked as secure. I assumed that thse flags should be enough to mark application cookies as secure, but there are a few other cookies which are also not marked as secure. I am not too concerned about them as they don't contain any sensitive information. But I would like to flag ASPXAUTH as secure.

My questions are,

  1. With these flags set on the web.config, is having ASPXAUTH without secure flag a security issue?
  2. If so, could you tell me what the correct way is to mark it as secure.

thanks.

回答1:

I found this piece of code to which made my authentication cookie secure. I cant remember the source of this but if you add it to your global.asax, it sorts the issue. I do not know why but requireSSL=true in your tag was not enough to make it secure.

  protected void Application_EndRequest(Object sender, EventArgs e)
    {
        string authCookie = FormsAuthentication.FormsCookieName;

        foreach (string sCookie in Request.Cookies)
        {
            if (sCookie.Equals(authCookie))
            {
                // Set the cookie to be secure. Browsers will send the cookie
                // only to pages requested with https
                var httpCookie = Response.Cookies[sCookie];
                if (httpCookie != null) httpCookie.Secure = true;
            }
        }
    }


回答2:

Your issue looks to be that because your form is incorrectly configured. You have:

<forms loginUrl="~/Account/Login" timeout="2880"  requireSSL=""  name="AppName" />

and you should have

<forms loginUrl="~/Account/Login" timeout="2880"  requireSSL="true"  name="AppName" />

According to Microsoft the requireSSL attribute in the httpCookies tag is overridden by the requireSSL attribute of the forms tag. You didn't set the value, but you specified it may cause IIS to use the default of false. You should set it to true.



回答3:

Answer for your secong question

Possible duplicate of How to secure .ASPXAUTH token

as per answer by xelco

To prevent forms authentication cookies from being captured and tampered with while crossing the network, ensure that you use SSL with all pages that require authenticated access and restrict forms authentication tickets to SSL channels by setting requireSSL="true" on the <forms> element.

To restrict forms authentication cookies to SSL channels set requireSSL="true" on the <forms> element, as shown in the following code:

<forms loginUrl="Secure\Login.aspx" requireSSL="true" ... />

By setting requireSSL="true", you set the secure cookie property that determines whether browsers should send the cookie back to the server. With the secure property set, the cookie is sent by the browser only to a secure page that is requested using an HTTPS URL.