Yes indeed register_globals being on is a wide hole of a security risk. Until PHP version 4.2.0, this setting was on by default. The following is a example of exploitable source code
Code:
<?php
// ex1.php
if (some condition) {
$loggedin = 1;
}
if ($loggedin == 1) {
// allow access to something important
}
?>
If register_globals is on, a malicious users can pass a parameter, as follows:
Code:
www.site.com/ex1.php?loggedin=1.
Since the variable $loggedin was never initialized, the user gains access where they shouldn't.
Here's how the code can be secured.
Code:
<?php
// ex2.php
// first initialize the loggedin variable
$loggedin = 0;
if (some or other condition) {
$loggedin = 1;
}
if ($loggedin == 1) {
// allow access to something important
}
?>
If register_globals off, the first script would also be immune from that sort of attack. Rather, the variable would only be accessible as $_GET['loggedin'], where it can do much less harm.
Bookmarks