Home > php教程 > php手册 > body text

PHP中使用addslashes函数转义的安全性原理分析

WBOY
Release: 2016-06-06 20:18:04
Original
1480 people have browsed it

这篇文章主要介绍了PHP中使用addslashes函数转义的安全性原理分析,较为深入的分析了addslashes函数的用法及ecshop自定义函数addslashes_deep的不足之处,非常具有

本文实例讲述了PHP中使用addslashes函数转义的安全性原理分析。分享给大家供大家参考。具体分析如下:

先来看一下ECshop中addslashes_deep的原型

复制代码 代码如下:

function addslashes_deep($value) {
    if (empty($value)) {
        return $value;  //如为空,直接返回;
    } else {
        return is_array($value) ? array_map('addslashes_deep', $value): addslashes($value);
    }  //递归处理数组,直至遍历所有数组元素;
}


addslashes_deep函数本身没有问题,但使用时得注意一点
恰好今天也是在网上看到了有人发了关于使用这个函数使用的BUG注入漏洞
这个函数在引用回调函数addslashes时,只对数据的值进行转义,所以如果使用者在此过程中引用数组的键进行特定处理时,存在$key注入风险,此时可更改addslashes_deep函数,,使其同时对键值进行转义,或者使用时明确不引用键内容。

希望本文所述对大家的PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!