LoginSignup
1
1

More than 3 years have passed since last update.

Apache mod_access_compat の注意事項

Posted at

Allow ディレクティブの行にコメントを書くと挙動が狂った。
意図しない通信を許可してしまいかねないので自戒のためにメモ。

(そもそも Apache ではディレクティブと同じ行にコメントを書いてはいけないのだが)
https://httpd.apache.org/docs/2.4/en/configuring.html#syntax

Lines that begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on the same line as a configuration directive.

例えば CentOS 7 でパッケージインストールした httpd-2.4.6-90 でこういう設定をする

# rpm -q httpd
httpd-2.4.6-90.el7.centos.x86_64

# tail -5 httpd.conf
<Location /hoge>
  Order deny,allow
  Deny from all
  Allow from 127.0.0.1
</Location>

# systemctl start httpd

127.0.0.1 以外は /hoge にアクセスできない。
(何も設置してないので 127.0.0.1 からは 404 になっている)

# curl -sv -o /dev/null http://127.0.0.1/hoge 2>&1 | grep '^<'
< HTTP/1.1 404 Not Found
< Date: Mon, 20 Apr 2020 23:28:46 GMT
< Server: Apache/2.4.6 (CentOS)
< Content-Length: 202
< Content-Type: text/html; charset=iso-8859-1
<

# curl -sv -o /dev/null http://192.168.1.100/hoge 2>&1 | grep '^<'
< HTTP/1.1 403 Forbidden
< Date: Mon, 20 Apr 2020 23:28:48 GMT
< Server: Apache/2.4.6 (CentOS)
< Content-Length: 206
< Content-Type: text/html; charset=iso-8859-1
<

ここで Allow ディレクティブの行にコメントを書くと困ったことになる。

# tail -5 httpd.conf
<Location /hoge>
  Order deny,allow
  Deny from all
  Allow from 127.0.0.1 #comment
</Location>

# httpd -t
Syntax OK

# systemctl restart httpd

# curl -sv -o /dev/null http://127.0.0.1/hoge 2>&1 | grep '^<'
< HTTP/1.1 404 Not Found
< Date: Mon, 20 Apr 2020 23:29:44 GMT
< Server: Apache/2.4.6 (CentOS)
< Content-Length: 202
< Content-Type: text/html; charset=iso-8859-1
<

# curl -sv -o /dev/null http://192.168.1.100/hoge 2>&1 | grep '^<'
< HTTP/1.1 404 Not Found
< Date: Mon, 20 Apr 2020 23:29:46 GMT
< Server: Apache/2.4.6 (CentOS)
< Content-Length: 202
< Content-Type: text/html; charset=iso-8859-1
<

syntax check は通って、意図していない部分まで許可されてしまったようだ。
コメントをここに書かなければいいだけなので、深くは追わない。

ちなみに、CentOS 8 でパッケージインストールした httpd-2.4.37-16 では syntax check は同じく通るが、こういう事象は発生しなかった。
ソースからインストールした場合は syntax check でエラーになったので、独自のパッチを当てているようだ。

# /usr/local/apache2/bin/httpd -t
AH00526: Syntax error on line 509 of /usr/local/apache2/conf/httpd.conf:
No comments are allowed here

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1