ヘッダーの制限 <headerLimits>

概要

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

Note

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

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

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

互換性

バージョン メモ
IIS 10.0 <headerLimits> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <headerLimits> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <headerLimits> 要素は IIS 8.0 では変更されませんでした。
IIS 7.5 <headerLimits> 要素は、IIS 7.5 では変更されませんでした。
IIS 7.0 <requestLimits> コレクションの <headerLimits> 要素は 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 Web Server and Security node expanded displaying Request Filtering selected.
  5. [機能の選択] ページで、[次へ] をクリックします。
  6. [インストール オプションの確認] ページで、[インストール] をクリックします。
  7. [結果] ページで、 [閉じる]をクリックします。

Windows 8 または Windows 8.1

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

Windows Server 2008 または Windows Server 2008 R2

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

Windows Vista または Windows 7

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

操作方法

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

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 Default Web Site Home with Request Filtering selected.

  4. [要求のフィルタリング] ウィンドウで、[ヘッダー] タブを選択し、[操作] ウィンドウの [ヘッダーの追加] を選択します。
    Screenshot of Request Filtering pane and Headers tab with Add Header displayed in the Actions pane.

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

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

構成

属性

なし。

子要素

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

HTTP ヘッダーのサイズ制限を <headerLimits> コレクションに追加します。
clear 省略可能な要素です。

HTTP ヘッダーへのすべての参照を <headerLimits> コレクションから削除します。
remove 省略可能な要素です。

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

構成サンプル

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