我使用默认安装中的mod_wsgi
设置了Apache,使用一个非常简单的testing应用程序test.wsgi
:
def application(environ, start_response): status = '200 OK' output = 'Path: %s' % environ['PATH_INFO'] response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output]
Apache本身基本上是这样configuration的:
WSGIScriptAlias / /home/user/wsgi_test/test.wsgi
现在,如果我访问该服务器上的URL,我得到以下输出:
GET /test/../test/./test
=> Path: /test/test
GET /test/%2E%2E/abc
=> Path: /abc
GET /test%2fabc
=> 404 Not found
(由于AllowEncodedSlashes off
,我想) 因此,在我看来,Apache在将这些URL传递给应用程序之前parsing/预处理这些URL,这很好,因为它可以防止文件path不属于查询string的大量本地文件包含和目录遍历攻击。
一个人可以依靠这种行为,或者有一些/test/foo/../bar
方法来欺骗Apache实际上传递像/test/foo/../bar
的URL到应用程序? 如果可能的话,它会是一个Apache的bug吗?
安全指导“深度防御”build议您应该configurationApache来预处理path,但是您也应该自己防范危险path。
既然你可能更多地了解有效的path应该是什么样子,你应该能够提出更多的限制性testing,这比Apache一般可以做到的任何事情都容易得到。