Upcoming PHP 5.3 beefs up security

07.10.2008
PHP security guru Stefan Esser recently on some of the changes and important security issues that are likely to have significant effects for the everyday PHP coder (and user) with the release of the upcoming PHP 5.3.

Probably the simplest and most effective change that will come with PHP 5.3 is a modification to the way that $_REQUEST superglobal variables are handled. After several years of known vulnerability, it seems that the PHP developers are finally addressing one of the most risky elements of the scripting language.

For those who are unaware, the $_REQUEST superglobal variable in PHP is able to be called from anywhere in any PHP script, can not be overwritten/replaced by a user variable of the same name (though the contents can be changed) and is an associative array with the values passed via GET, POST and via cookie to the particular script ($_GET, $_POST, $_COOKIE PHP superglobals).

It took several years for the idea of disabling in the php.ini to be a default practice, and it is due to be removed from PHP 6.0 (if register_globals was enabled, any local variable could be overwritten by an equivalently named element of a superglobal array - $_GET['foo'] would overwrite $foo), but it still persists in odd corners of the Internet.

The difficulties associated with stamping out the register_globals directive are sure to be have been in the minds of the language developers when deciding to change the handling of $_REQUEST. As described by Esser, the primary change to $_REQUEST is a means to control what superglobals are looked at to form $_REQUEST, and in which order, without actually destroying or modifying the original superglobals. This means that $_REQUEST could be used to only monitor $_GET and $_POST submitted variables and ignore $_COOKIE values, or any other combination of the three.

Why not just get rid of $_REQUEST all-together, since $_GET, $_POST, and $_COOKIE already exist? Too many applications built in PHP are likely to use $_REQUEST in some form to enable a complete cutout of the superglobal. $_REQUEST does make the developer's life a little easier as they can accept user input from $_GET or $_POST without discrimination (though it is poor form to do so), but there are significant risks with allowing the user to arbitrarily overwrite values in either $_GET or $_POST.