自分のリポートがキッカケになって、Red Hat の Bugzilla に Bug 591293 が登録されました。 けっこうハマりやすいポイントだと思うので、注意喚起を兼ねて記事を起こしてみます(ここで書いてもあんまり読まれないけど...)。
問題の概要以下の全てを満たす場合:- Red Hat Enterprise Linux 5 (または CentOS 5.x などの RHEL 互換 OS) または Fedora を利用している。
- ディストリビューションの提供する(yum リポジトリの)httpd (バージョン 2.2 系) パッケージを利用している。
- /etc/httpd/conf/httpd.conf に以下の記述がある(デフォルトのまま編集していない場合など)。
<Files ~ "^\.ht"> Order allow,deny Deny from all </Files>
- Satisfy Any ディレクティブを .htaccess あるいは設定ファイル(/etc/httpd/conf.d/*.conf)で使用している。
この場合、Satisfy Any の設定をしているディレクトリ以下にある .ht で始まるファイル(.htaccess, .htpasswd, .htdigest, ...)がユーザから閲覧できるようになっている可能性があります。
Satisfy Any とは何かSatisfy Any ディレクティブを使うと、「Order」による IP アドレスベースのアクセス許可と「Require」によるユーザ認証ベースのアクセス許可を OR 条件にすることができます。 例えば、「ローカルのネットワークであれば常にアクセスを許可するが、それ以外ではパスワード認証が必要」というポリシーを実装したいとき、.htaccess に以下のように記述することができます。# ローカルネットワークからのみ許可 Order deny,allow Deny from all Allow from 192.168.0.0/16
# ユーザをパスワードで認証したときのみ許可 AuthType Basic AuthName "Members Only" AuthUserFile "/var/www/.htpasswd" Require valid-user
# Require または Allow のどちらかを満たせばよい。 Satisfy Any このとき「Satisfy Any」は、「もし Order ディレクティブの条件を満たしたら Require 不要でアクセス許可。ただし、Order ディレクティブの条件を満たさなくても、Require のユーザ認証が通ればアクセス許可」という動作をします。ここで .htaccess ファイルにアクセスした場合、- httpd.conf にある Order ディレクティブによって、アクセスは Deny from all される。
- Order ディレクティブの条件を満たさなかったので、.htaccess に書かれた Require ディレクティブでユーザ認証を行う。
- ユーザは、自身のユーザ名とパスワードでその認証を通過する。
- Order は満たさないが Require は満たされたので、.htaccess ファイルへのアクセスは許可される。
… というように、見えてはいけないはずの .ht* ファイルが見えてしまいます。“あなたの予想に反して、このページが見えているでしょうか?”とか訊いてる場合じゃないですよ。
対策/etc/httpd/conf/httpd.conf に書いてある上記の設定に、<Files ~ "^\.ht"> Order allow,deny Deny from all Satisfy All </Files> と「Satisfy All」を加えれば大丈夫になります。これは Apache の Web サイトからダウンロードできるソースコードに添付されているサンプル httpd.conf と同じ設定です。
おまけセキュリティ脆弱性ではないと思った(なぜなら Apache の仕様通りの動作だから)のですが、Bugzilla に登録するのが面倒だった :-) のと、いきなり Bugzilla に晒されるに耐える英語を書く自信がなかったので、Red Hat Security Response Team にメールしてみました。
この問題は 2008 年頃に気づいていたのですが、昨日別のサーバで同じ問題でハマってしまい、「デフォルトがこの設定なのは危ないな」と思った次第。興味のある方がおられるかもしれないので、送ったメール全体を掲載しておきます。Subject: RHEL5/6 httpd - insecurely configured
Dear Sirs or Madams,
I'm not sure this is a security issue or not, but I found that "httpd" package in RHEL5 / RHEL6 Beta is configured insecurely by default.
In "httpd.conf" file in the package, there is a <Files> directive that makes .ht* files invisible:
------------------------------------------------------------------------ <Files ~ "^\.ht"> Order allow,deny Deny from all </Files> ------------------------------------------------------------------------
This is insecure when used with "Satisfy Any" directive. For instance, if you place .htaccess file like this in the DocumentRoot (assuming "AllowOverride AuthConfig"):
------------------------------------------------------------------------ # Allow access from the local network: Order deny,allow Deny from all Allow from 192.168.0.0/16
# Require authorization if accessed from outside the local network AuthType Basic AuthName "Employees Only" AuthBasicProvider ldap AuthzLDAPAuthoritative on AuthLDAPURL ldap://localhost/dc=example,dc=com Require valid-user
# Need to satisfy any of "Allow" or "Require" Satisfy Any ------------------------------------------------------------------------
If a user passed the authorization using his username and password, all "Order" directives will be ignored because "Require" directive is "Satisfied"; as a result, .ht* files become visible to the user.
Since the use of "Satisfy Any" is a very common way to control access policy, and such .htaccess files often contain sensitive information like AuthLDAPBindPassword, I would like to ask you to change the default configuration to:
------------------------------------------------------------------------ <Files ~ "^\.ht"> Order allow,deny Deny from all Satisfy All </Files> ------------------------------------------------------------------------
This is also the default configuration of httpd.conf in the source tarball from Apache, as of httpd-2.2.15.
Yours faithfully,
Kenichi Maehashi およそ 1 時間後くらいに、「セキュリティアップデートとしてリリースする必要があるとは思わないけど、尤もだと思うから Bugzilla しておくよ」というような意味の返事が来ました。お仕事早いです。
|