541Chapter 29SecurityIt s important to remember (Best web design) that setting register_globalsto
Wednesday, May 2nd, 2007541Chapter 29SecurityIt s important to remember that setting register_globalsto offdoes not prevent an ill- intentioned Web site user from setting variables for himself. It does, however, add anotherlayer of complexity to the cracker s job. It s no longer enough to simply send a variable to theserver; he or she must also know from which environment you expect that variable to come. And with register_globalsset to off, variables evaluated and set exclusively within thereceiving script are not in danger from any suspect request variables. Coupled with some wellthought out code, a potentially hazardous situation can be easily averted. Let s look at aquick example: // Bad example, don t do thisfunction check_user() { if (($user == $user_we_expected) && ($pass == $password_we_expected)) $registered user = 1; } if ($registered_user) { // Here are those names and addresses the cracker is after} The preceding example, written as if register_globalswere turned on, may at least look rea- sonable at first glance. Don t worry about where $user_we_expectedand $pass_we_expectedcome from right now. We ll just assume, for the time being, that these come from some otherfunction such as a database lookup. The first problem is the relatively open use of $userand$pass. These variables can come from anywhere and our script won t ask any questions; itjust dutifully processes these variables regardless of the source. Let s look again at a versionmodified to address this. We still haven t changed the value of register_globals. // Better example, but still needs workfunction check_user() { if (($_POST[user] == $user_we_expected) && ($_POST[pass] == $password_we_expected)) $registered user = 1; } if ($registered_user) { // Here are those names and addresses the cracker is after} So, for the low, low price of just 10 keystrokes, we ve narrowed the sources we will accept fora username and password. A cracker can no longer submit these through a GETargument likehttp://website/script?user=meat&pass=potatoes. These variables will simply expireineffectually at the end of the script execution. Our cracker can still send these variables, buthe is restricted to using a POSTmethod form. That brings us to a couple more issues concern- ing variable origin. A script kiddie could still use a simple form-posting script to rapidly submituser and password combinations in succession. This sort of brute force attack is successfulmore often that you might think, especially where usernames and passwords are poorly chosen. // We re almost therefunction check_user() { if($_SERVER[HTTP_REFERER] == $our address) { if (($_POST[user] == $user_we_expected)
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services