【问题标题】:Secure Flag for ASPXAUTH CookieASPXAUTH Cookie 的安全标志
【发布时间】:2014-02-03 15:44:19
【问题描述】:

我们有一个面向外部的应用程序,该应用程序由外部安全公司进行了渗透测试。应用程序已在 ASP.NET MVC4 上开发并在 IIS8/Windows 2012 Server 上运行。

报告的漏洞之一是 ASPXAUTH 不安全。当我检查 cookie 检查器时,有一些带有安全标志的 cookie。但 ASPXAUTH 不是其中之一。

我做了一些研究,并在 web.config 上设置了这些标志

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

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

尽管有这些设置,但身份验证 cookie 并未标记为安全。我认为这些标志应该足以将应用程序 cookie 标记为安全,但还有一些其他 cookie 也未标记为安全。我不太担心它们,因为它们不包含任何敏感信息。但我想将 ASPXAUTH 标记为安全。

我的问题是,

  1. 在 web.config 上设置这些标志后,没有安全标志的 ASPXAUTH 是否存在安全问题?
  2. 如果是这样,您能否告诉我将其标记为安全的正确方法是什么?

谢谢。

【问题讨论】:

    标签: security asp.net-mvc-4 forms-authentication


    【解决方案1】:

    回答你的第二个问题

    How to secure .ASPXAUTH token 可能重复

    根据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.
    

    【讨论】:

    • 谢谢。我已经阅读了该答案,这就是我在问题中所说的那样。我完全按照描述做了,但 ASPXAUTH 令牌 cookie 仍未标记为安全。
    • 我不想重复显而易见的事情,但 requireSSL 是您设置安全 cookie 标志的方式。 owasp.org/index.php/SecureFlag。要检查的一件事是配置文件的层次结构。它可能在顶部的 web.config 中设置,但在子目录中被覆盖。您也可以签入代码。 msdn.microsoft.com/en-us/library/…
    【解决方案2】:

    我发现这段代码使我的身份验证 cookie 变得安全。我不记得它的来源,但如果你将它添加到你的 global.asax 中,它会解决问题。我不知道为什么,但您的标签中的 requireSSL=true 不足以使其安全。

      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;
                }
            }
        }
    

    【讨论】:

    • @AnarchistGreek,对 IBM 的 AppScan 不起作用。它仍然声称 cookie 不安全。
    • 我明白了,您的代码需要编辑。 foreach 语句应该访问 Request.Cookies 而不是 Response.Cookies。
    【解决方案3】:

    您的问题似乎是因为您的表单配置不正确。你有:

    <forms ... requireSSL="" ... />
    

    你应该有

    <forms ... requireSSL="true" ... />
    

    根据MicrosofthttpCookies 标记中的requireSSL 属性被forms 标记的requireSSL 属性覆盖。您没有设置该值,但您指定它可能会导致 IIS 使用默认值 false。您应该将其设置为true

    【讨论】:

      【解决方案4】:

      对 AnarchistGeek 答案的更改:您不想直接迭代 Request.Cookies,因为使用响应集合添加 cookie 会使 cookie 立即在请求集合中可用(请参阅 HttpRequest.Cookies 文档中的注释@ 987654321@)。当您设置/更改响应 .ASPXAUTH cookie 时,这将给您留下“枚举器被实例化后集合已修改”错误,因为它也在修改请求集合。

      protected void Application_EndRequest(Object sender, EventArgs e)
      {
          string authCookie = FormsAuthentication.FormsCookieName;
          string[] cookieNames = Request.Cookies.AllKeys;
      
          foreach (string sCookie in cookieNames)
          {
              if (sCookie.Equals(authCookie))
              {
                  var httpCookie = Response.Cookies[sCookie];
                  if (httpCookie != null) httpCookie.Secure = true;
              }
          }
      }
      

      请注意,此特定解决方案将清除 .ASPXAUTH cookie 的现有值(请参阅此post

      【讨论】:

        猜你喜欢
        • 2018-03-25
        • 2011-01-29
        • 2013-12-02
        • 1970-01-01
        • 2018-02-03
        • 1970-01-01
        • 2012-10-13
        • 1970-01-01
        • 2012-11-23
        相关资源
        最近更新 更多