Common PHP Security Mistakes
In one of my previous articles, I mentioned the top 5 security mistakes made in PHP. This article is a follow-up, with some more common security mistakes.
Software >> PHP Programming
common PHP security mistakes
In one of my previous articles, I mentioned the top 5 security mistakes made in PHP. This article is a follow-up, with some more common security mistakes.
System Calls
In PHP, there are different ways to execute system calls.
The system(),exec(), and passthru() all allow you to execute operating-system commands from within your scripts.
Each of these functions, if not checked, can also allow a malicious user to exploit your system and execute commands that could possible access private files and information.
Protecting your system from this attack
The input from the user, no matter the context, should never be trusted. PHP provides two functions, escapeshellarg() and escapeshellcmd().
The escapeshellarg() function is designed to remove or otherwise eliminate any potentially harmful characters received from user input for use as arguments to system commands (in our case, the zip command).
The syntax for this function is as follows:escapeshellarg($command)
where $command is the input to clean, and the return value is the cleaned string. When executed, this function will add single quotes around the string and escape (add a slash in front of) any single quotes that exist in the string.
escapeshellcmd() is similar to this function, except it will only escape characters that have a special meaning to the underlying operating system. If user input will be used as part of the argument list for a system call, the escapeshellarg() function is always the better choice.
File Uploads
PHP will create a file with the uploaded content, but will not check whether the filename is valid, or if the type and size are correct
A user could potentially create his own form specifying the name of some other file that contains sensitive information and submit it, resulting in the processing of that other file.
Solution
use move_uploaded_file() or is_uploaded_file(). However, there are some other problems with user-uploaded files and check the $_FILES super global array to make sure that the user has uploaded the correct file type/size.
Including Files
In PHP you can include local or remote files by using include(), include_once(), require() and require_once(). It allows you to have separate files for classes, reused code and so on, increasing the maintainability and readability of your code.
The concept of including remote files is dangerous in itself, though, because the remote site could be compromised or the network connection could be spoofed. In either scenario, you are injecting unknown and possibly hostile code directly into your script.
Another issue to think about when including files, is if a file that is included is dependent on user input. This poses a potential securty issue, which can be fixed by verifying and cleaning incoming varialbes.
Conclusion
Don’t trust any incoming variables ($_GET,$_POST, or $_COOKIE). These can all be set by a malicious user and possibly compromise the securty of your system.
-
Lastest Articles
10 principles of search engine friendly web design
Search engine friendly web design is web design that is planned around known search engine optimization principles. If ranking well in the search engines is important to you then the first step towards6 tips to improve results from your website
Make sure you know why you want a website and what you want your website to do for you. Write down some broad goalsCross Browser Compatibility
there are really only two types of browsers you need to consider. If you run a fairly standard website, these will probably account for 99% of your audienceHow to get the Web 2.0 Look and Feel
refers to the new wave of community driven websites, it is also increasingly used to describe the fresh and clean design approach they useRevealing Facebook Application XSS Holes
Beginning tomorrow, September 1st, I will begin posting full technical details of cross-site scripting vulnerabilities that I have discovered in Facebook applicationsFacebook Applications are Now Even More Valuable Hacking Targets
which I called a FAXX hack, enables one to not only post links to Facebook for viral effects but also harvest a wealth of information on victimized users along the wayNew Trick to View Hidden Facebook Photos and Tabs
Last December, I posted a bit of JavaScript known as a bookmarklet that allowed you to see photo albums for any Facebook user if the album privacy settings allowed itUsing Google Buzz Can Expose Your Gmail Address
In short, having a public Google profile (which you might have created when checking out Google Buzz) can allow others to figure out your Gmail addressGoogle Takes Small Steps for Buzz, Points to Big Solutions for Social Networking
Buzz, Google's controversial attempt to unseat Facebook as the most mainstream of social activity stream readers, just made some much-needed changes that Facebook could learn from as wellGet Satisfaction Turns Facebook Fan Pages into Customer Support Hubs
Get Satisfaction, the popular online customer service company, just announced that it is bringing its service to Facebook fan pages


























