DaoKeCMS插件开发中常见的路径穿越坑:
文件操作时未校验路径,导致路径穿越漏洞,可访问插件目录外的文件。
// 错误!路径穿越
$file = get('file', '');
include plugin_dir() . '/' . $file;
// 正确!白名单校验
$allowed = ['list', 'edit', 'detail'];
$file = get('file', '');
if (!in_array($file, $allowed)) {
die('非法请求');
}
include plugin_dir() . '/' . $file . '.php';