ヘッダー制限 <headerLimits>

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

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

概要

<requestFiltering> コレクションの <headerLimits> 要素には、HTTP ヘッダーの最大サイズをバイト単位で指定する <add> 要素のコレクションが格納されます。

: 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/

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

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

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

  3. [ホーム] ウィンドウで [要求のフィルタリング] をダブルクリックします。

    拡大

  4. [要求のフィルタリング] ウィンドウで、[ヘッダー] タブをクリックし、[操作] ウィンドウで [Add Header] をクリックします。

    拡大

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

    拡大

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

構成

属性

なし。

子要素

要素 説明
add オプションの要素。

<headerLimits> コレクションに HTTP ヘッダーのサイズ制限を追加します。
clear オプションの要素。

<headerLimits> コレクションから HTTP ヘッダーに対するすべての参照を削除します。
remove オプションの要素。

<headerLimits> コレクションから 1 つの HTTP ヘッダーに対する参照を削除します。

構成サンプル

次の例の 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()