好吧,做了搜索,找不到任何接近此的東西,所以這裏...這個PHP代理腳本在htdocs/public_html之外提供文件的安全性如何?
我正在寫一個PHP 5.3 +代理腳本來提供www,htdocs, public_html等,例如/home/sites/example.com/data
這是一個Moodle插件模塊,所以如果你熟悉Moodle代碼,很好,如果不是的話,我已盡我所能地註釋了它。到目前爲止,這一切都按預期工作,但我還沒有對其進行更多的測試。
問題:這有多安全?我主要關心的是用戶獲得指定目錄之外的訪問權限。如果有什麼可以看到這是一個明顯的安全漏洞,請讓我知道。
腳本:提前
require_once('../../config.php'); // conatains $CFG object
require_once('../../lib/filelib.php'); // contains mimeinfo() and send_file() definitions
// Don't use Moodle required_param() to avoid sending any HTML messages to Flash apps
require_login(); // Users must be logged in to access files
global $CFG;
$swf_relative_path = get_file_argument(); // gets the appended URL e.g. /dir/subdir/file.jpg
$swf_ok = false;
if(strrpos($swf_relative_path,'.') > strlen($swf_relative_path) - 6) {
// Strip out special characters, extra slashes, and parent directory stuff
$swf_disallowed = array('../','\'','\"',':','{','}','*','&','=','!','?','\\','//','///');
$swf_replace = array('','','','','','','','','','','','','/','/');
$swf_relative_path = str_replace($swf_disallowed,$swf_replace,$swf_relative_path);
$swf_full_path = $CFG->dataroot.$CFG->swf_content_dir.$swf_relative_path;
if(file_exists($swf_full_path) && is_readable($swf_full_path)) {
$swf_path_info = pathinfo($swf_full_path);
$swf_mime_type = mimeinfo('type', $swf_path_info['basename']);
send_file($swf_full_path,$swf_path_info['basename'],'default',0,false,false,$swf_mime_type,false);
exit;
}
}
header('HTTP/1.0 404 Not Found'); // Send back a 404 so that apps don't wait for a timeout
exit('404 Error: File not found'); // Pure text output - Flash app friendly
謝謝! :)
Thanks str。最後,我使用了現有的Moodle功能。腳本在這裏:https://github.com/matbury/SWF-Activity-Module2.5/blob/master/swf/content.php – Matt