From: Yusuke ENDOH Date: 2010-06-17T12:39:06+09:00 Subject: [ruby-dev:41632] Re: [Bug #3345] webrick test failure on Windows(?) 遠藤です。 2010年6月16日9:45 U.Nakamura : >> 担当者 Usaku NAKAMURAにセット > > え、なんで? > 報告したら担当しないといけないの? 報告者だからではなく、windows のプラットフォームメンテナということで 担当者にさせてもらいました。メンテナがいないライブラリの、プラット フォーム特有の問題はプラットフォームメンテナに見てもらうしかないかな と思って。 見たくないということでしたら、WONTFIX と判断する権限はあると思います。 >> prevent_directory_traversal の問題を正確に理解していないのですが、 >> 問題がおきるのが Windows だけで、\\ の扱いだけの問題だとしたら、 >> File.expand_path を使わず gsub で処理するといいのではないでしょう >> か。 > > 残念ながら \\ の扱いだけの問題ではないので... > 具体的には、短いファイル名形式を利用したアクセスや、NTFSデー > タストリームの主ストリーム明示指定アクセスなどによるアクセス > 制御回避を、File.expand_pathの正規化処理を利用して排除してい > ます。 > File.expand_pathが行っている正規化処理と同等の処理を全部ここ > に並べるのはさすがにちょっと。 File.expand_path は絶対パスに変換するメソッドであって、正規化に使う のは筋違いではないかという気がします。 trailing_pathsep? の処理が必要なことが傍証? 筋がどうこう言ってても security issue はしょうがないのでしょうがない のですが、じゃあこういうパッチはどうでしょうか。 windows では試していませんが。 diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb index 32c1965..4887903 100644 --- a/lib/webrick/httpservlet/filehandler.rb +++ b/lib/webrick/httpservlet/filehandler.rb @@ -214,16 +214,18 @@ module WEBrick # character in URI notation. So the value of path_info should be # normalize before accessing to the filesystem. + path = req.path_info.dup.force_encoding(Encoding.find("filesystem")) if trailing_pathsep?(req.path_info) # File.expand_path removes the trailing path separator. # Adding a character is a workaround to save it. # File.expand_path("/aaa/") #=> "/aaa" # File.expand_path("/aaa/" + "x") #=> "/aaa/x" - expanded = File.expand_path(req.path_info + "x") + expanded = File.expand_path(path + "x") expanded.chop! # remove trailing "x" else - expanded = File.expand_path(req.path_info) + expanded = File.expand_path(path) end + expanded.force_encoding(req.path_info.encoding) req.path_info = expanded end -- Yusuke Endoh