【发布时间】:2019-01-08 06:45:17
【问题描述】:
使用 .Net Framework 4.7 的混合 webforms/mvc asp.net 应用程序在 Veracode 动态扫描中被标记为“会话固定”漏洞。这意味着 Veracode 获取登录页面,更改 SessionId cookie (ASP.NET_SessionId),然后使用有效的用户 ID 和密码发布以进行登录。 ASP.Net 登录用户,但获取此更改的 SessionId cookie 并继续使用它;使用注入的 SessionId 值的行为是缺陷。
换句话说,当 Veracode 获取页面时,SessionId cookie 可能是“abc123”。 Veracode 将该 cookie 更改为“def456”并回发。 ASP.Net 登录用户并从此使用“def456”作为 SessionId。
根据 Veracode,我必须使在成功登录之前创建的 ASP.Net_SessionID cookie 无效。这当然很容易做到,我可以在用户成功登录时简单地重置 ASP.NET_SessionId cookie。问题是,这会导致用户被重定向回登录页面。那么会发生什么:
- 用户提交登录页面。
- 服务器端,如果登录成功,我会将 ASP.NET_SessionId 重置为某个新值(通过调用 SessionIDManager.SaveSessionID(),这反过来会简单地重置 ASP.Net_SessionID cookie)。
- 用户被重定向到应用主页,然后立即重定向回登录页面
应用程序使用表单身份验证,并带有 webforms 登录页面。登录页面使用 asp.net Login 控件。在这个控件的“OnAuthenticate”事件中,我有这样的代码:
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool b = Membership.Validateuser(Login1.UserName, Login1.Password);
if(b)
{
e.Authenticated = true;
SessionIDManager mgr = new SessionIDManager();
string newId = mgr.CreateSessionID(Context);
mgr.SaveSessionID(Context, newId, out bool redirected, out bool cookieAdded);
}
}
这运行没有错误。 ASP.net 将用户重定向到应用程序主页。但随后 asp.net 立即将用户从应用程序主页重定向回登录页面。
有没有办法改变那个 SessionId cookie 以便
- Veracode 注入的 SessionId cookie 值被放弃。
- 用户保持身份验证,而不是简单地重定向回登录页面。
我尝试在各种页面事件(PreInit、Load 等)中运行更改 SessionId 的代码,所有这些事件都有相同的结果——用户被重定向回登录页面。
请不要将此问题标记为已回答。关于这个问题有几个答案,所有这些都建议像我上面那样重新设置 SessionId cookie,并且所有这些都有 cmets 指出这实际上不起作用。
【问题讨论】:
标签: asp.net session cookies veracode session-fixation