插件踩坑经验:路径穿越📅 2025-10-26  |  👁 179 次浏览

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';
  • 文件操作时用白名单校验
  • 禁止..和:等穿越路径字符
  • 框架安装校验已禁止穿越路径
  • 插件内部也应做路径校验

芒阳网络团域cms开发中心

Copyright © 2023 刀客CMS内容管理系统