要求の制限 <requestLimits>

概要

<requestLimits> 要素は、Web サーバーによって処理される HTTP 要求の制限を指定します。 これらの制限には、要求の最大サイズ、最大 URL の長さ、クエリ文字列の最大長が含まれます。 さらに、<requestLimits> 要素には、ユーザー定義の HTTP ヘッダー制限のコレクションを <headerLimits> 要素に含められます。この要素を使用して、HTTP ヘッダーにカスタム設定を定義できます。

Note

要求のフィルタリングが、HTTP 要求が要求の制限を超えたために HTTP 要求をブロックすると、IIS 7 は HTTP 404 エラーをクライアントに返し、要求が拒否された理由を識別する一意のサブ状態で次のいずれかの HTTP 状態をログに記録します。

HTTP サブ状態 説明
404.14 URL が長すぎる
404.15 クエリ文字列が長すぎる
413.1 コンテンツの長さが大きすぎる

これらのサブ状態によって、Web 管理者は IIS ログを分析し、潜在的な脅威を特定できます。

さらに、HTTP 要求が <headerLimits> 要素で定義されているヘッダーの制限を超えると、IIS 7 は次のサブ状態を持つ HTTP 404 エラーをクライアントに返します。

HTTP サブ状態 説明
431 要求ヘッダーが長すぎる

互換性

バージョン メモ
IIS 10.0 <requestLimits> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <requestLimits> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <requestLimits> 要素は IIS 8.0 では変更されませんでした。
IIS 7.5 <requestLimits> 要素は、IIS 7.5 では変更されませんでした。
IIS 7.0 <requestFiltering> コレクションの <requestLimits> 要素は IIS 7.0 で導入されました。
IIS 6.0 <requestLimits> 要素は、IIS 6.0 UrlScan [RequestLimits] 機能を置き換えます。

段取り

IIS 7 以降の既定のインストールには、要求のフィルタリングの役割サービスまたは機能が含まれます。 要求のフィルタリングの役割サービスまたは機能がアンインストールされている場合は、次の手順を使用して再インストールできます。

Windows Server 2012 または Windows Server 2012 R2

  1. タスク バーで [サーバー マネージャー]をクリックします。
  2. [サーバー マネージャー] で、[管理] メニューを選択し、[役割と機能の追加] を選択します。
  3. 役割と機能の追加ウィザードで、[次へ] を選択します。 [インストールの種類] を選択し、[次へ] を選択します。 対象サーバーを選択し、[次へ] を選択します。
  4. [サーバーの役割] ページで [Web サーバー (IIS)] を展開し、[Web サーバー][セキュリティ][要求のフィルタリング] の順に展開します。 次へ をクリックします。
    Screenshot of the Request Filtering option being highlighted.
  5. [機能の選択] ページで、[次へ] をクリックします。
  6. [インストール オプションの確認] ページで、[インストール] をクリックします。
  7. [結果] ページで、 [閉じる]をクリックします。

Windows 8 または Windows 8.1

  1. [スタート] 画面で、ポインターを左下隅まで移動し、[スタート] ボタンを右クリックし、[コントロール パネル] を選択します。
  2. [コントロール パネル][プログラムと機能] を選択し、[Windows の機能の有効化または無効化] を選択します。
  3. [インターネット インフォメーション サービス]を展開し、[World Wide Web サービス] を展開し、[セキュリティ] を展開して、[要求のフィルタリング] を選択します。
    Screenshot of the Request Filtering folder being highlighted.
  4. OK をクリックします。
  5. 閉じるをクリックします。

Windows Server 2008 または Windows Server 2008 R2

  1. タスク バーで [スタート] を選択し、[管理ツール] をポイントして、[サーバー マネージャー] を選択します。
  2. [サーバー マネージャー] 階層ウィンドウで [ロール] を展開し、[Web サーバー (IIS)] を選択します。
  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールし、[役割サービスの追加] を選択します。
  4. 役割サービスの追加ウィザード[役割サービスの選択] ページで、[要求のフィルタリング] を選択し、[次へ] を選択します。
    Screenshot of the Request Filtering option being highlighted and the only selected option.
  5. [インストール オプションの確認] ページで、[インストール] をクリックします。
  6. [結果] ページで、 [閉じる]をクリックします。

Windows Vista または Windows 7

  1. タスク バーで、[スタート][コントロール パネル] の順に選択します。
  2. [コントロール パネル][プログラムと機能] を選択し、[Windows の機能の有効化または無効化] を選択します。
  3. [インターネット インフォメーション サービス][World Wide Web サービス][セキュリティ] の順に展開します。
  4. [要求のフィルタリング] を選択し、[OK] を選択します。
    Screenshot of the Request Filtering folder being selected and highlighted.

操作方法

IIS 7.0 ユーザーの場合の注意: このセクションの一部の手順では、要求のフィルタリング用のユーザー インターフェイスを含む IIS 7.0 用 Microsoft 管理パックをインストールする必要がある場合があります。 IIS 7.0 用 Microsoft 管理パックをインストールするには、次の URL を参照してください。

要求のフィルタリング機能の設定と要求の制限を編集する方法

  1. インターネット インフォメーション サービス (IIS) マネージャーを開きます。

    • Windows Server 2012 または Windows Server 2012 R2 を使用している場合:

      • タスク バーで、[サーバー マネージャー] を選択し、[ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順に選択します。
    • Windows 8 または Windows 8.1 を使用している場合:

      • Windows キーを押しながら文字 X を押し、[コントロール パネル] を選択します。
      • [管理ツール] を選択し、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
    • Windows Server 2008 または Windows Server 2008 R2 を使用している場合:

      • タスク バーで、[スタート] ボタンを選択し、[管理ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順に選択します。
    • Windows Vista または Windows 7 を使用している場合:

      • タスク バーで、[スタート][コントロール パネル] の順に選択します。
      • [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウで、要求のフィルタリング設定を変更する接続、サイト、アプリケーション、またはディレクトリに移動します。

  3. [ホーム] ウィンドウで、[要求のフィルタリング] をダブルクリックします。
    Screenshot of the Default Web Site Home screen's Home pane.

  4. [操作] ウィンドウで、[機能設定の編集] を選択します。
    Screenshot of the Request Filtering screen, showing the File Name Extensions and Hidden Segment tab.

  5. オプションを指定し、[OK] を選択します。
    Screenshot of the Edit Request Filtering Settings dialog box, showing four selectable fields.たとえば、次のような変更を加える場合があります。

    • 2048 を指定して、URL の最大長を 2 KB に変更します。
    • 1024 を指定して、クエリ文字列の最大長を 1 KB に変更します。
    • [一覧にない動詞を許可する] チェック ボックスをオフにして、一覧に含まれていない HTTP 動詞へのアクセスを拒否します。

HTTP ヘッダーの制限を追加する方法

  1. インターネット インフォメーション サービス (IIS) マネージャーを開きます。

    • Windows Server 2012 または Windows Server 2012 R2 を使用している場合:

      • タスク バーで、[サーバー マネージャー] を選択し、[ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順に選択します。
    • Windows 8 または Windows 8.1 を使用している場合:

      • Windows キーを押しながら文字 X を押し、[コントロール パネル] を選択します。
      • [管理ツール] を選択し、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
    • Windows Server 2008 または Windows Server 2008 R2 を使用している場合:

      • タスク バーで、[スタート] ボタンを選択し、[管理ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順に選択します。
    • Windows Vista または Windows 7 を使用している場合:

      • タスク バーで、[スタート][コントロール パネル] の順に選択します。
      • [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウで、要求のフィルタリング設定を変更する接続、サイト、アプリケーション、またはディレクトリに移動します。

  3. [ホーム] ウィンドウで、[要求のフィルタリング] をダブルクリックします。
    Screenshot of the Default Web Site Home screen, showing the Failed Request Tracing Rules, Handler Mappings, and H T T P Redirect options.

  4. [要求のフィルタリング] ウィンドウで、[ヘッダー] タブを選択し、[操作] ウィンドウの [ヘッダーの追加] を選択します。
    Screenshot of the Request Filtering pane, showing the H T T P Verbs and Headers tabs.

  5. [ヘッダーの追加] ダイアログ ボックスで、HTTP ヘッダーとヘッダーの制限に必要な最大サイズを入力し、[OK] を選択します。
    Screenshot of the Add Header dialog box, showing the Header and Size limit fields.

    たとえば、"Content-type" ヘッダーには、要求の MIME タイプが含まれています。 値として 100 を指定すると、"Content-type" ヘッダーの長さは 100 バイトに制限されます。

構成

属性

属性 説明
maxAllowedContentLength 省略可能な uint 属性。

要求内のコンテンツの最大長をバイト単位で指定します。

既定値は 30000000 であり、約 28.6 MB になります。
maxQueryString 省略可能な uint 属性。

クエリ文字列の最大長をバイト単位で指定します。

既定値は 2048 です。
maxUrl 省略可能な uint 属性。

URL の最大長をバイト単位で指定します。

既定値は 4096 です。

子要素

要素 説明
headerlimits 省略可能な要素です。

HTML ヘッダーのサイズ制限を指定します。

構成サンプル

次の Web.config ファイルの例では、"Content-type" ヘッダーの長さが 100 バイトを超える HTTP 要求のアクセスを拒否するように IIS を構成します。

<configuration>
   <system.webServer>
      <security>
         <requestFiltering>
            <requestLimits>
               <headerLimits>
                  <add header="Content-type" sizeLimit="100" />
               </headerLimits>
            </requestLimits>
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>

サンプル コード

次のコード サンプルでは、"Content-type" ヘッダーの長さが 100 バイトを超える HTTP 要求のアクセスを拒否するように IIS を構成します。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /+"requestLimits.headerLimits.[header='Content-type',sizeLimit='100']"

PowerShell

$requestLimits = Get-IISConfigSection -CommitPath 'Default Web Site' -SectionPath 'system.webServer/security/requestFiltering' | Get-IISConfigElement -ChildElementName 'requestLimits'
$headerLimits = Get-IISConfigCollection -ConfigElement $requestLimits -CollectionName 'headerLimits'
New-IISConfigCollectionElement -ConfigCollection $headerLimits -ConfigAttribute @{ 'header'='Content-Type'; 'sizeLimit'=100 }

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetWebConfiguration("Default Web Site");
         ConfigurationSection requestFilteringSection = config.GetSection("system.webServer/security/requestFiltering");
         ConfigurationElement requestLimitsElement = requestFilteringSection.GetChildElement("requestLimits");
         ConfigurationElementCollection headerLimitsCollection = requestLimitsElement.GetCollection("headerLimits");

         ConfigurationElement addElement = headerLimitsCollection.CreateElement("add");
         addElement["header"] = @"Content-type";
         addElement["sizeLimit"] = 100;
         headerLimitsCollection.Add(addElement);

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetWebConfiguration("Default Web Site")
      Dim requestFilteringSection As ConfigurationSection = config.GetSection("system.webServer/security/requestFiltering")
      Dim requestLimitsElement As ConfigurationElement = requestFilteringSection.GetChildElement("requestLimits")
      Dim headerLimitsCollection As ConfigurationElementCollection = requestLimitsElement.GetCollection("headerLimits")

      Dim addElement As ConfigurationElement = headerLimitsCollection.CreateElement("add")
      addElement("header") = "Content-type"
      addElement("sizeLimit") = 100
      headerLimitsCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site";
var requestFilteringSection = adminManager.GetAdminSection("system.webServer/security/requestFiltering", "MACHINE/WEBROOT/APPHOST/Default Web Site");

var requestLimitsElement = requestFilteringSection.ChildElements.Item("requestLimits");
var headerLimitsCollection = requestLimitsElement.ChildElements.Item("headerLimits").Collection;

var addElement = headerLimitsCollection.CreateNewElement("add");
addElement.Properties.Item("header").Value = "Content-type";
addElement.Properties.Item("sizeLimit").Value = 100;
headerLimitsCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site"
Set requestFilteringSection = adminManager.GetAdminSection("system.webServer/security/requestFiltering", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set requestLimitsElement = requestFilteringSection.ChildElements.Item("requestLimits")
Set headerLimitsCollection = requestLimitsElement.ChildElements.Item("headerLimits").Collection

Set addElement = headerLimitsCollection.CreateNewElement("add")
addElement.Properties.Item("header").Value = "Content-type"
addElement.Properties.Item("sizeLimit").Value = 100
headerLimitsCollection.AddElement(addElement)

adminManager.CommitChanges()