Would I be taking a big security risk by trusting the content of the $_SERVER variable array to get the name of php file using $_SERVER['PHP_SELF']?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Not at all, this can not actually be a risk at all as long as you don't use data from user. That is, use one of these:
Many but not all of the $_SERVER variables are attacker controlled. For instance
$_SERVER['SCRIPT_NAME']
is safe where as$_SEVER['PHP_SELF']
is a vary dangerous variable and is often the source of xss:PoC:
It is easy to see this vulnerability in action by looking at phpinfo.
There is no special mechanism in effect to protect this variable. You can write to it as you can to any other variable. So you have to protect it against tampering like any other variable (disable register_globals, avoid variable variables, etc.). Then you can trust it.
As a workaround to be sure, you can define your own constants early in your program:
and use predefined constants where available, e.g.
__FILE__
.From the php.net manual:
So, if you are aware of all users who have access to change server configuration, (and all scripts in your session that may modify the contents of the variable) you can be reasonably sure of the
$_SERVER
variable's data.