mod_securityでアップローダが動かなくなる

注意しよう

ファイル名によって不可

アップロードのフォームで、Shift_JISで、ファイルの最後に「表」がついていると

/var/log/httpd/modsec_audit.log

で下記のようなエラー。

==xxxxxxx==============================
Request: test.example.com 192.168.0.1 - - [06/Dec/2006:13:00:00 +0900] "POST
/upload.cgi HTTP/1.1" 403 281 "http://example.com/upload.html"
"Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.8.0.7) Gecko/20060909 Fi
refox/1.5.0.7" xxxxxxxxxxxxxxxxx-xxxxxx "-"
Handler: cgi-script

                                                                              • -

POST /upload.cgi HTTP/1.1
Host: test.example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.8.0.7) Gecko/2
0060909 Firefox/1.5.0.7
(略)
Content-Type: multipart/form-data; boundary=---------------------------26500
1916915724
Content-Length: 841
mod_security-message: Access denied with code 403. Error processing request
body: Multipart: invalid Content-Disposition header (-10): form-data; name="
File"; filename="\x82\xdd\x82\xbf\x82\xe1\x82\xa2\x82\xe2\x82\xf1\95\\" [severity "EMERGE
NCY"]
mod_security-action: 403

28
[POST payload not available]

最後「表」で終わるファイル名なんてつける訳ないじゃんか、拡張子あるんだし、て思っているあなた、残念でした! いまだに Mac OS 9 を使っている人がかなり多いので、拡張子なんて概念ねえよこの業界は!

アップロード中はmod_securityにテンポラリが取られちゃう

CentOS4のばあい、rpmで入れると、

/etc/httpd/conf.d/modsecurity.conf

が、

    # Designate a directory for temporary files
# storage. It is a good idea to change the
# value below to a private directory, just as
# an additional measure against race conditions
SecUploadDir /tmp
SecUploadKeepFiles Off

なってるので、まず/tmpにアップされてから中身検査されて、cgiに渡される。

これって、アップロード中の進捗を表示するようなCGIアップローダーやばいかも。

特定のCGIだけ除外するには

/etc/httpd/conf/httpd.conf

で、


SecFilterInheritance Off
SecFilterEngine Off

などするといいよ。セキュリティ的にいいかどうかは各自にお任せ。