【发布时间】:2014-04-26 12:16:27
【问题描述】:
在没有ssl的情况下向服务器发出请求时,我实际上可以看到MVC3框架生成的纯文本验证令牌密钥。
此密钥存储在名为:_RequestVerificationToken_Lw__ 的 cookie 中
在混合安全环境中,实际上可以在对非 ssl 站点的初始请求中看到以纯文本形式发送到服务器的此令牌。此令牌在用户会话期间也是静态的。那么拥有这个令牌有什么用,因为它很容易被攻击者窃取,因为 cookie 会以纯文本形式到处乱扔。
不应该将此 cookie 标记为安全且永远不会以纯文本形式发送吗?或者至少在每次请求时都重新生成,这样安全信息就不会从 ssl 通道中泄露出来?
我说的是 MVC 3 AntiForgeryWorker 类中的这个块
private string GetAntiForgeryTokenAndSetCookie(HttpContextBase httpContext, string salt, string domain, string path)
{
string forgeryTokenName = AntiForgeryData.GetAntiForgeryTokenName(httpContext.Request.ApplicationPath);
AntiForgeryData token = (AntiForgeryData) null;
HttpCookie httpCookie = httpContext.Request.Cookies[forgeryTokenName];
if (httpCookie != null)
{
try
{
token = this.Serializer.Deserialize(httpCookie.Value);
}
catch (HttpAntiForgeryException ex)
{
}
}
if (token == null)
{
token = AntiForgeryData.NewToken();
string str = this.Serializer.Serialize(token);
HttpCookie cookie = new HttpCookie(forgeryTokenName, str)
{
HttpOnly = true,
Domain = domain
};
if (!string.IsNullOrEmpty(path))
cookie.Path = path;
httpContext.Response.Cookies.Set(cookie); //Ma, Why isn't this marked as "SECURE"
}
return this.Serializer.Serialize(new AntiForgeryData(token)
{
Salt = salt,
Username = AntiForgeryData.GetUsername(httpContext.User)
});
}
【问题讨论】:
-
您能否提供一个重现该问题的最小示例?
-
不确定您要查找的示例,该框架应该自行转储此令牌。但以防万一,上面有问题的代码块。
-
cookie 设置为 'HttpOnly',所以它不是不安全的。
-
不应该是安全的吗?我的意思是,否则中间的人可以拥有这个 cookie 并发起 CSRF 攻击。或者至少应该根据请求轮换该值,但事实并非如此。
-
对我来说,每次请求都会重新生成新令牌。
标签: asp.net asp.net-mvc asp.net-mvc-3 security csrf