mod_rewrite+mod_jkで変換前のURLがTomcatに渡ってしまう
via. mod_jk 1.2.23 からは ForwardURICompat オプションがデフォルトではなくなった - 夜の Discovery
mod_jk+mod_rewrite+Tomcatを使ったありがちなURL変換ネタですが、システム移行中のプロジェクトで思いっきりハマってました。
mod_jk1.2.23のchangelogに
とあります。要は、JkOptionのforwardingオプションのデフォルトが
Change the default value of JkOptions to ForwardURICompatUnparsed. The old default value was ForwardURICompat. This should make URL interpretation between Apache httpd and Tomcat consistent (prevent double decoding problems). (rjung)
ForwardURICompat
から
ForwardURICompatUnparsed
に変更したということで、httpdが受け取ったオリジナルのURL(mod_rewriteで変換したURLではない)がそのままTomcatに送信されるようになった、ということです。
とりあえず、
JkOptions +ForwardURICompat
とすれば、mod_rewriteで変換したURLがTomcatに渡されるようになりました。各オプションについては、以下のURLを参照してください。
ただし、この仕様変更はCVE-2007-1860に対処したものです。
最後のparagraphにも「この問題は場合に依りけり」とありますが、短絡的に使うのではなく問題ないかを確認してから使うようにした方が良いと思います。
CVE-2007-1860 A double encoded ".." in a URL can be used to access URLs on the AJP backend, for which no mod_jk forwarding rule exists (patch for CVE-2007-0450 was insufficient).This version fixes the problem by using ForwardURICompatUnparsed as the default for the forwarding JkOption. You can similarly fix the problem for all previous versions of mod_jk by setting "JkOption ForwardURICompatUnparsed". If you upgrade to version 1.2.23 please ensure, that you do not have a different forwarding option in your existing configuration. We highly recommend, that you are consulting the forwarding documentation, especially concerning the implications for interaction with mod_rewrite.
Please note that this issue only affects configurations, which use a prefix forwarding rule like "/myapp/*" or "/myapp/*.jsp" to restrict access to the context "/myapp". The issue will allow malicious URLs to reach "/otherapp" or "/otherapp/*.jsp" as well.