Analysis on the security principle of escaping using the addslashes function in PHP

Source: Internet
Author: User
This article mainly introduces the security principle of using the addslashes function escape in PHP, and analyzes the usage of the addslashes function and the limitations of the ecshop user-defined function addslashes_deep, which is very useful, for more information about how to use the addslashes function escape in PHP, see the following example. Share it with you for your reference. The specific analysis is as follows:

Let's take a look at the prototype of addslashes_deep in ECshop.

The code is as follows:

Function addslashes_deep ($ value ){
If (empty ($ value )){
Return $ value; // if it is null, return directly;
} Else {
Return is_array ($ value )? Array_map ('addslashes _ deep ', $ value): addslashes ($ value );
} // Recursively process the array until all array elements are traversed;
}


The addslashes_deep function is no problem, but you must pay attention to it when using it.
Today, we also saw a BUG injection vulnerability on the internet about using this function.
When this function references the callback function addslashes, only the data values are escaped. Therefore, if the user references the array key for specific processing during this process, there is a risk of $ key injection, in this case, you can change the addslashes_deep function to escape the key value at the same time, or explicitly do not reference the key content during use.

I hope this article will help you with PHP programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.