ApacheのTRACEを無効にする

ApacheのTRACEを無効にする

TRACEメソッドって怖いんです
を読んで、あぁやってねぇ。。ってことで作業ついでにメモ

Apache1.3.34と2.0.55以降の場合のTRACE無効化

apacheの設定ファイル(httpd.conf)に

TraceEnable Off

と書いてapacheを再起動してやればよい。

  • TRACEが無効になっているかどうか確認
# telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
OPTIONS * HTTP/1.1
Host:localhost

HTTP/1.1 200 OK
Date: Wed, 02 Mar 2011 09:06:32 GMT
Server: Apache/2.2.3 (Red Hat)
Allow: GET,HEAD,POST,OPTIONS  ←TRACEがなければOK
Content-Length: 0
Connection: close
Content-Type: text/plain

Connection closed by foreign host.
Apache1.3.34と2.0.55より前の場合のTRACE無効化

mod_rewriteを利用してTRACEを無効化する。

mod_rewriteを有効にし、

RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* -[F]

httpd.confに記載、apacheを再起動。


ヴァーチャルホストを設定している場合は、
それぞれに

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* -[F]
</IfModule>

を記載する。

  • TRACEが無効になっているかどうか確認
# telnet test.jp 80
Trying 42.xxx.xxx.xxx...
Connected to test.jp.
Escape character is '^]'.
TRACE / HTTP/1.1
Host:test.jp

HTTP/1.1 403 Forbidden              ←アクセス禁止になっていればOK
Date: Wed, 02 Mar 2011 09:29:59 GMT
Server: Apache
Content-Length: 202
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /
on this server.</p>
</body></html>
Connection closed by foreign host.