【问题标题】:SessionAuthenticationModule Cookie Handler not creating HttpOnly secure cookieSessionAuthenticationModule Cookie 处理程序未创建 HttpOnly 安全 cookie
【发布时间】:2013-05-29 19:48:12
【问题描述】:

我正在使用 System.IdentityModel 在 ASP.NET MVC4 Web 应用程序中使用带有声明主体的表单身份验证对用户进行身份验证。 (本文代码:http://brockallen.com/2013/01/26/replacing-forms-authentication-with-wifs-session-authentication-module-sam-to-enable-claims-aware-identity/

我的 ClaimsBasedAuthenticationService 类从 SessionSecurityToken 发出 SAM cookie,一切都很好......除了我刚才注意到它没有将会话 cookie 创建为 HTTPOnly 或要求它们需要 SSL。当我调试代码时,我可以看到 CookieHandler 对象上的这些属性在调试器中设置正确,但创建的最终会话 cookie 根本没有标记 HTTPOnly 和 Secure 标志。

我有 web.config 行来明确地将这些设置为 true:

<system.web>
  <httpCookies httpOnlyCookies="true" requireSSL="true" />
  <authentication mode="Forms">
     <forms ... requireSSL="true" />
  </authentication>
 ...
</system.web>
<system.identityModel.services>
  <federationConfiguration>
    <cookieHandler requireSsl="true" hideFromScript="true" />
  </federationConfiguration>
</system.identityModel.services>

有人可以告诉我是否还缺少其他东西以便从脚本中隐藏我的 FedAuth cookie (HTTPOnly) 并需要 SSL?

【问题讨论】:

  • 有人建议将属性 lockItem="true" 添加到 httpCookies 元素,但没有任何作用。

标签: asp.net-mvc-4 forms-authentication session-cookies wif claims-based-identity


【解决方案1】:

我正在使用相同的实现,但在使用 Fiddler2 时没有看到您的问题。但是,也许问题与您的调试工具有关?在 IE10 调试工具中,仅在首次接收到 cookie 时才会显示安全和 http only 标志。如果您使用 Chrome 调试工具进行检查,您应该会在所有请求中看到正确显示的标志。

【讨论】:

  • Chrome 开发工具也不显示。我尝试使用 Fiddler2,但它甚至不会显示整个请求,只显示主机名的“隧道”。不知道为什么 Fiddler 不像开发工具那样显示请求/响应详细信息。
  • 您是否设置了 Fiddler 来解密 HTTPS 流量?见工具 | Fiddler 选项,然后是 HTTPS 选项卡);实际上是中间人攻击,但您可以看到调试需要查看的内容。
【解决方案2】:

你搞定了吗?我一直在使用基本相同的代码,一切都很好。

我看不出以下建议与任何事情有任何关系,但我唯一能建议的就是设置 cookie 生命周期

<cookieHandler hideFromScript="true" requireSsl="true" persistentSessionLifetime="30" />

<forms loginUrl="/Whereever" timeout="30" requireSSL="true" />

<system.webServer>
  <modules>
    <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
  </modules>
</system.webServer>

【讨论】:

  • 我已经有一段时间没有从事那个项目了,但如果我记得,我认为属性设置正确,而开发工具只是在撒谎:)......或者至少这就是我喜欢的想法。
猜你喜欢
  • 2021-08-26
  • 2023-03-12
  • 1970-01-01
  • 2020-05-14
  • 1970-01-01
  • 2015-06-30
  • 2010-09-06
  • 1970-01-01
  • 2020-11-19
相关资源
最近更新 更多