超级全局变量和register_globals
时间:2008-02-22 来源:octans
$GLOBALS, 所有全局变量数组
$_SERVER, 服务器环境变量数组
$_GET,通过GET方法传递给脚本的变量数组
$_POST, 通过POST方法传递给脚本的变量数组
$_COOKIE,cookie变量数组
$_REQUEST,所有用户输入的变量数组,包括$_GET, $_POST和$_COOKIE所包含的输入内容
$_FILES,与文件上传相关得变量数组
$_ENV,环境变量数组
$_SESSION,会话变量数组
php配置文件中的register_globals, Whether or not to register the EGPCS (Environment, GET, POST, Cookie, Server) variables as global variables.
在PHP 4.1中,添加了一组特殊数据以访问外部数据。这些数组可以在任何范围内调用,这使得外部数据的访问更方便。在PHP 4.2中,register_globals被默认关闭以鼓励使用这些数组以避免无经验的开发者编写出不安全的PHP代码。
从PHP4.2.0开始register_globals默认值由on变为off.主要原因是为了帮助程序员写出更安全的代码。
example1:
?php
// define $authorized = true only if user is authenticated
if (authenticated_user()) {
$authorized = true;
}
// Because we didn't first initialize $authorized as false, this
//might be defined through register_globals, like from GET
//auth.php?authorized=1
// So, anyone can be seen as authenticated!
if ($authorized) {
include "/highly/sensitive/data.php";
}
?>
如果register_globals设置为on的话,那么变量$authorized就可以通过url请求来注册为全局变量,比如auth.php?authorized=1,这样就跳过了登录验证的环节。
如果最初写上$authorized = false的话,无论register_globals是on还是off,都不会出现上面描述的安全漏洞。但对于经验少的程序员经常忘记。
编码规范:一定要验证用户输入的数据;一定要初始化自己的变量
参考
http://bbs.chinaunix.net/thread-161690-1-1.html
http://cn2.php.net/manual/en/security.globals.php
$_SERVER, 服务器环境变量数组
$_GET,通过GET方法传递给脚本的变量数组
$_POST, 通过POST方法传递给脚本的变量数组
$_COOKIE,cookie变量数组
$_REQUEST,所有用户输入的变量数组,包括$_GET, $_POST和$_COOKIE所包含的输入内容
$_FILES,与文件上传相关得变量数组
$_ENV,环境变量数组
$_SESSION,会话变量数组
php配置文件中的register_globals, Whether or not to register the EGPCS (Environment, GET, POST, Cookie, Server) variables as global variables.
在PHP 4.1中,添加了一组特殊数据以访问外部数据。这些数组可以在任何范围内调用,这使得外部数据的访问更方便。在PHP 4.2中,register_globals被默认关闭以鼓励使用这些数组以避免无经验的开发者编写出不安全的PHP代码。
从PHP4.2.0开始register_globals默认值由on变为off.主要原因是为了帮助程序员写出更安全的代码。
example1:
?php
// define $authorized = true only if user is authenticated
if (authenticated_user()) {
$authorized = true;
}
// Because we didn't first initialize $authorized as false, this
//might be defined through register_globals, like from GET
//auth.php?authorized=1
// So, anyone can be seen as authenticated!
if ($authorized) {
include "/highly/sensitive/data.php";
}
?>
如果register_globals设置为on的话,那么变量$authorized就可以通过url请求来注册为全局变量,比如auth.php?authorized=1,这样就跳过了登录验证的环节。
如果最初写上$authorized = false的话,无论register_globals是on还是off,都不会出现上面描述的安全漏洞。但对于经验少的程序员经常忘记。
编码规范:一定要验证用户输入的数据;一定要初始化自己的变量
参考
http://bbs.chinaunix.net/thread-161690-1-1.html
http://cn2.php.net/manual/en/security.globals.php
相关阅读 更多 +










