部分产品存在通过api/products接口的selectId参数进行sql注入风险,存在于标准版本/pro版本/多门店版本;需要自行检查此漏洞是否进行修复;当前漏洞已在最新发布的版本中更新修复;请参考发帖日期和发布日期来自行判断;
修复方案:
增加参数过滤,增加参数类型严格转换
修复实例:下方例子按照标准版本来修复,其他产品按照当前例子进行对比修复
1、修改crmeb/app/api/controller/v1/store/StoreProductController.php文件中的lst方法里面的接收参数,修改成下图
[['selectId', 'd'], 0],
[['productId', 'd'], 0],
[['coupon_category_id', 'd'], 0],
2、修改crmeb/app/model/product/product/StoreCategory.php,增加 (string)
按照上方截图中就可以修复此漏洞;
【系统安全增强】建议优化
Request.php 增加了可以过滤参数的方法;
1、修改crmeb/app/Request.php这个文件
public function more(array $params, bool $suffix = false, bool $filter = true): array
{
$p = [];
$i = 0;
foreach ($params as $param) {
if (!is_array($param)) {
$p[$suffix == true ? $i++ : $param] = $this->param($param);
} else {
if (!isset($param[1])) $param[1] = null;
if (!isset($param[2])) $param[2] = '';
if (is_array($param[0])) {
$name = is_array($param[1]) ? $param[0][0] . '/a' : $param[0][0] . '/' . $param[0][1];
$keyName = $param[0][0];
} else {
$name = is_array($param[1]) ? $param[0] . '/a' : $param[0];
$keyName = $param[0];
}
$p[$suffix == true ? $i++ : ($param[3] ?? $keyName)] = $this->param($name, $param[1], $param[2]);
}
}
if ($filter && $p) {
$p = $this->filterArrayValues($p);
}
return $p;
}
/**
* 过滤接数组中的字符串
* @param $str
* @param bool $filter
* @return array|mixed|string|string[]
*/
public function filterArrayValues($array)
{
$result = [];
foreach ($array as $key => $value) {
if (is_array($value)) {
// 如果值是数组,递归调用 filterArrayValues
$result[$key] = $this->filterArrayValues($value);
} else {
if (in_array($key, $this->except) || is_int($value) || is_null($value)) {
$result[$key] = $value;
} else {
// 如果值是字符串,过滤特殊字符
$result[$key] = filter_str($value);
}
}
}
return $result;
}
2、在crmeb/app/common.php 文件中最后增加下面代码
if (!function_exists('filter_str')) {
/**
* 过滤字符串敏感字符
* @param $str
* @return array|mixed|string|string[]|null
*/
function filter_str($str)
{
$rules = [
'/\.\./', // 禁用包含 ../ 的参数
'/\<\?/', // 禁止 php 脚本出现
'/\bor\b.*=.*/i', // 匹配 'or 1=1',防止 SQL 注入(注意边界词 \b 和不区分大小写 i 修饰符)
'/(select[\s\S]*?)(from|limit)/i', // 防止 SQL 注入
'/(union[\s\S]*?select)/i', // 防止 SQL 注入
'/(having|updatexml|extractvalue)/i', // 防止 SQL 注入
'/sleep\((\s*)(\d*)(\s*)\)/i', // 防止 SQL 盲注
'/benchmark\((.*)\,(.*)\)/i', // 防止 SQL 盲注
'/base64_decode\(/i', // 防止 SQL 变种注入
'/(?:from\W+information_schema\W)/i', // 注意这里的 (?:...) 是不合法的,应该是 (?:...) 表示非捕获组,但通常我们不需要这个
'/(?:current_|user|database|schema|connection_id)\s*\(/i', // 防止 SQL 注入(注意去掉了不必要的 (?:...))
'/(?:etc\/\W*passwd)/i', // 防止窥探 Linux 用户信息
'/into(\s+)(?:dump|out)file\s*/i', // 禁用 MySQL 导出函数
'/group\s+by.+\(/i', // 防止 SQL 注入
'/(?:define|eval|file_get_contents|include|require|require_once|shell_exec|phpinfo|system|passthru|preg_\w+|execute|echo|print|print_r|var_dump|(fp)open|alert|showmodaldialog)\(/i', // 禁用 webshell 相关某些函数
'/(gopher|doc|php|glob|file|phar|zlib|ftp|ldap|dict|ogg|data)\:\/\//i', // 防止一些协议攻击(注意协议后的三个斜杠)
'/\$_(GET|POST|COOKIE|FILES|SESSION|ENV|GLOBALS|SERVER)\[/i', // 禁用一些内置变量,注意 PHP 变量名通常是大写的
'/<(iframe|script|body|img|layer|div|meta|style|base|object|input)/i', // 防止 XSS 标签植入
'/(onmouseover|onerror|onload|onclick)\=/i', // 防止 XSS 事件植入
'/\|\|.*?(?:ls|pwd|whoami|ll|ifconfig|ipconfig|&&|chmod|cd|mkdir|rmdir|cp|mv)/i', // 防止执行 shell(注意去掉了不合适的 ifconfog)
'/\sand\s+.*=.*/i' // 匹配 and 1=1
];
if (filter_var($str, FILTER_VALIDATE_URL)) {
$url = parse_url($str);
if (!isset($url['scheme'])) return $str;
$host = $url['scheme'] . '://' . $url['host'];
$str = $host . preg_replace($rules, '', str_replace($host, '', $str));
} else {
$str = preg_replace($rules, '', $str);
}
return $str;
}
}