0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ApacheでGETのみ許可する設定

Last updated at Posted at 2015-03-23

POSTでリクエストがくるとwebサーバのログに載らなくて嫌じゃないですか?
POSTでリクエストが来たら弾くようにします。
ApacheのLimitExceptというディレクティブを使います。(http://httpd.apache.org/docs/2.4/ja/mod/core.html#limitexcept)

Webサーバの設定

httpd.conf
Alias /get_only/ /usr/home/qoAop/public_html/get_only/
<Directory "/usr/home/qoAop/public_html/get_only/">
        Options ExecCGI FollowSymLinks Includes
        AllowOverride None
        AddHandler cgi-script .cgi
        <LimitExcept GET>
                Order deny,allow
                Deny from all
        </LimitExcept>
</Directory>

サンプルプログラム

method.cgi
# !/usr/bin/perl
use strict;

my $env = $ENV{'REQUEST_METHOD'};

print <<EOM;
Content-Type: text/plain; charset=UTF-8

REQUEST_METHOD=$env
EOM

exit(0);

1;

動作確認

wgetで--post-dataをつけるとPOSTでリクエストしてくれるのでこれで確認します。

GET…200 OKで成功します。

sh-3.2$ wget -S --no-proxy -O -  http://127.0.0.1/get_only/method.cgi
--2015-03-23 18:21:54--  http://127.0.0.1/get_only/method.cgi
127.0.0.1:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています...
  HTTP/1.1 200 OK
  Date: Mon, 23 Mar 2015 09:21:54 GMT
  Server: Apache
  Connection: close
  Content-Type: text/plain; charset=UTF-8
長さ: 特定できません [text/plain]
`STDOUT' に保存中

    [<=>                                                                                                                ] 0           --.-K/s              REQUEST_METHOD=GET
    [ <=>                                                                                                               ] 19          --.-K/s 時間 0s

2015-03-23 18:21:54 (1.65 MB/s) - `-' へ保存終了 [19]

POST…403 Forbiddenで弾かれます。

sh-3.2$ wget -S --no-proxy -O - --post-data "a=b" http://127.0.0.1/get_only/method.cgi
--2015-03-23 18:22:10--  http://127.0.0.1/get_only/method.cgi
127.0.0.1:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています...
  HTTP/1.1 403 Forbidden
  Date: Mon, 23 Mar 2015 09:22:10 GMT
  Server: Apache
  Content-Length: 221
  Keep-Alive: timeout=5, max=100
  Connection: Keep-Alive
  Content-Type: text/html; charset=iso-8859-1
2015-03-23 18:22:10 エラー 403: Forbidden。```

ログ

127.0.0.1 - - [23/Mar/2015:18:21:54 +0900] "GET /get_only/method.cgi HTTP/1.0" 200 19 "-" "Wget/1.11.4 Red Hat modified" "-" 0 5958
127.0.0.1 - - [23/Mar/2015:18:22:10 +0900] "POST /get_only/method.cgi HTTP/1.0" 403 221 "-" "Wget/1.11.4 Red Hat modified" "-" 0 352
0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?