我有一个这样设置的重写规则:
RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI} -f RewriteRule ^(.*)$ cache/$1 [QSA,PT,L]
这个规则的简单解释:它检查在caching目录中是否存在请求的文件。 如果是这样,那么它就提供caching目录。
例如, http://somehost.tld/about.html的请求将从http://somehost.tld/cache/about.html提供 (如果此文件存在)。
我关心的是如果RewriteRule不安全。 是否有人可以像这样请求一个URL,用双重句点来移动一个目录:
HTTP://somehost.tld/../../private_file.txt
所以导致private_file.txt从我的apache公共文件夹上的目录服务?
包括..
在URL中不能在HTTP请求级别或浏览器级别上工作。 浏览器只是解决相对path,发送一个适当的文件的请求(封顶在服务器的根目录)。 所以在地址栏中input:
http://somehost.tld/../../private_file.txt
会导致一个HTTP请求:
http://somehost.tld/private_file.txt
换句话说,有人将不得不手动制作../..
的HTTP请求到达Apache。 然后, HTTP 400 Bad Request
。 来自我的本地服务器(没有重写规则)的示例:
ritsuko:~ spyder$ curl -v http://localhost/../randomfile * About to connect() to localhost port 80 (#0) * Trying ::1... connected * Connected to localhost (::1) port 80 (#0) > GET /../randomfile HTTP/1.1 > User-Agent: curl/7.19.4 (universal-apple-darwin10.0) libcurl/7.19.4 OpenSSL/0.9.8l zlib/1.2.3 > Host: localhost > Accept: */* > < HTTP/1.1 400 Bad Request < Date: Wed, 17 Feb 2010 13:18:40 GMT < Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8l DAV/2 < Content-Length: 226 < Connection: close < Content-Type: text/html; charset=iso-8859-1 < <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>400 Bad Request</title> </head><body> <h1>Bad Request</h1> <p>Your browser sent a request that this server could not understand.<br /> </p> </body></html> * Closing connection #0
Apache不允许“向上移动一个目录”。