要求制限 <requestLimits>

  • 概要
  • 互換性
  • セットアップ
  • 方法
  • 構成
  • サンプル コード

※本ページに挿入されている画像をクリックすると、画像全体が別ウィンドウで表示されます。

概要

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

: HTTP 要求が要求の制限を超えているために要求のフィルタリングによって HTTP 要求がブロックされると、IIS 7.0 は HTTP 404 エラーをクライアントに返し、要求が拒否された理由を特定する固有の副状態と共に次のいずれかの HTTP 状態をログに記録します。

HTTP 副状態 説明
404.10 要求ヘッダーが長すぎます。
404.11 URL にダブル エスケープが指定されています。
404.12 URL にハイビット文字が使用されています。
404.13 コンテンツの長さが長すぎます。
404.14 URL が長すぎます。
404.15 クエリ文字列が長すぎます。

Web 管理者は、これらの副状態を使用して IIS ログを分析し、潜在的な脅威を特定することができます。

互換性

  IIS 7.0 IIS 6.0
説明 <requestFiltering> コレクションの <requestLimits> は IIS 7.0 で新たに導入された要素です。 <requestLimits> 要素は、IIS 6.0 の UrlScan の RequestLimits 機能に代わるものです。

セットアップ

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

Windows Server 2008

  1. タスク バーの [スタート] ボタンをクリックし、[管理ツール] をポイントして [サーバー マネージャー] をクリックします。

  2. [サーバー マネージャー] のツリー表示で、[役割] を展開して [Web サーバー (IIS)] をクリックします。

  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールして [役割サービスの追加] をクリックします。

  4. 役割サービスの追加ウィザードの [役割サービスの選択] ページで、[要求フィルタ] を選択して、[次へ] をクリックします。

    拡大

  5. [インストール オプションの確認] ページで [インストール] をクリックします。

  6. [結果] ページで [閉じる] をクリックします。

Windows Vista

  1. タスク バーの [スタート] ボタンをクリックし、[コントロール パネル] をクリックします。

  2. [コントロール パネル][プログラムと機能] をクリックして、[Windows の機能の有効化または無効化] をクリックします。

  3. [Internet Information Services][World Wide Web サービス][セキュリティ] の順に展開します。

  4. [要求のフィルタリング] を選択して、[OK] をクリックします。

    拡大

方法

: このセクションの手順を実行するには、要求のフィルタリング用のユーザー インターフェイスが含まれている Microsoft Administration Pack for IIS 7.0 をインストールする必要があります。Microsoft Administration Pack for IIS 7.0 をインストールするには、次の URL を参照してください。

http://learn.iis.net/page.aspx/415/

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

  1. タスク バーの [スタート] ボタンをクリックして、[管理ツール] をポイントし、[インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウで、要求のフィルタリングの設定を変更する接続、サイト、アプリケーション、またはディレクトリに移動します。

  3. [ホーム] ウィンドウで [Request Filtering] をダブルクリックします。

    拡大

  4. [操作] ウィンドウで [Edit Feature Settings] をクリックします。

    拡大

  5. オプションを指定し、[OK] をクリックします。

    拡大

    たとえば、次のような変更を行うことができます。

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

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

  1. タスク バーの [スタート] ボタンをクリックして、[管理ツール] をポイントし、[インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウで、要求のフィルタリングの設定を変更する接続、サイト、アプリケーション、またはディレクトリに移動します。

  3. [ホーム] ウィンドウで [Request Filtering] をダブルクリックします。

    拡大

  4. [Request Filtering] ウィンドウで、[Headers] タブをクリックし、[操作] ウィンドウで [Add Header] をクリックします。

    拡大

  5. [Add Header] ダイアログ ボックスで、HTTP ヘッダーと、そのヘッダーの制限となる最大サイズを入力し、[OK] をクリックします。

    拡大

    たとえば、"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']" 

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()