ASP.NET MS11-100 : how can I change the limit on the maximum number of posted form values?

标签 asp.net post ms11-100

Microsoft 最近(2011 年 12 月 29 日)发布了一个更新,以解决 .NET Framework 中的几个严重安全漏洞。 MS11-100 引入的修复之一暂时缓解涉及哈希表冲突的潜在 DoS 攻击。此修复似乎破坏了包含大量 POST 数据的页面。在我们的例子中,在具有非常大的复选框列表的页面上。为什么会出现这种情况?

一些非官方消息来源似乎表明 MS11-100 对回发项目设置了 500 个限制。我找不到证实这一点的 Microsoft 消息来源。我知道 View 状态和其他框架功能会消耗掉一些限制。是否有任何配置设置可以控制这个新限制?我们可以不使用复选框,但它非常适合我们的特定情况。我们还想应用该补丁,因为它可以防止其他一些令人讨厌的事情。

Unofficial source discussing the 500 limit:

The bulletin fixes the DOS attack vector by providing a limit to the number of variables that can be submitted for a single HTTP POST request. The default limit is 500 which should be enough for normal web applications, but still low enough to neutralize the attack as described by the security researchers in Germany.

编辑:带有限制示例的源代码(似乎是 1,000,而不是 500) 创建一个标准 MVC 应用程序并将以下代码添加到主索引 View :

@using (Html.BeginForm()) 
{
    <fieldset class="fields">
        <p class="submit">
            <input type="submit" value="Submit" />
        </p>

        @for (var i = 0; i < 1000; i++)
        {
            <div> @Html.CheckBox("cb" + i.ToString(), true) </div>
        } 
    </fieldset>
}

此代码在补丁之前有效。之后就不行了错误是:

[InvalidOperationException: Operation is not valid due to the current state of the object.]
System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +82 System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +111
System.Web.HttpRequest.FillInFormCollection() +307

最佳答案

尝试在 web.config 中添加此设置。我刚刚在 .NET 4.0 上使用 ASP.NET MVC 2 项目对此进行了测试,使用此设置您的代码不会抛出异常:

<appSettings>
  <add key="aspnet:MaxHttpCollectionKeys" value="1001" />
</appSettings>

现在(应用安全更新后)应该可以更改限制。

<小时/>

我还没有更新我的机器,所以使用 Reflector 检查了 HttpValueCollection 类,它没有 ThrowIfMaxHttpCollectionKeysExceeded方法:

enter image description here

我安装了KB2656351 (.NET 4.0更新),在Reflector中重新加载程序集,方法出现:

enter image description here

所以这个方法绝对是新的。我在 Reflector 中使用了“Disassemble”选项,从代码中我可以看出它会检查 AppSetting:

if (this.Count >= AppSettings.MaxHttpCollectionKeys)
{
  throw new InvalidOperationException();
}

如果在 web.config 文件中找不到该值,则会将 System.Web.Util.AppSettings.EnsureSettingsLoaded 中的值设置为 1000 (内部静态类):

 _maxHttpCollectionKeys = 0x3e8;
<小时/>

此外,Alexey Gusarov 两天前发布了有关此设置的推文:

here这是 Jonathan Ness(MSRC 安全开发经理)和 Pete Voss(可信计算高级响应通信经理)问答的官方回答:

Q: Is AppSettings.MaxHttpCollectionKeys the new parameter that contains the maximum number of form entries?

A: Yes it is.

关于ASP.NET MS11-100 : how can I change the limit on the maximum number of posted form values?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8684049/

相关文章:

PHP 文件无法从index.html 获取$_POST 数据

asp.net - 使用 Jquery Mobile 和 ASP.NET MVC 3 Razor 下载文件

c# - LINQ查询参数可以为空

c# - 使用正则表达式删除长文本中字符附近的空格

javascript - Ajax POST - 同步请求的 'XMLHttpRequest.withCredentials' 已弃用

mysql - WordPress 添加自定义列

ASP.NET Web.config 继承不适用于 MS11-100 的 MaxHttpCollectionKeys 设置

asp.net - ASP.NET 中的哈希冲突问题是如何修复的 (MS11-100)?

c# - 安装 visual studio 2015 后 Microsoft Visual Studio 2012 已停止工作