note 28614 added to language.variables.predefined
| From: | lopez dot on dot the dot lists at yellowspace dot net | Date: | Sat, 18 Jan 2003 00:11:22 +0000 |
| Subject: | note 28614 added to language.variables.predefined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-42306@lists.php.net to get a copy of this message | ||
- Security Issue and workaround -
If You use "eval()" to execute code stored in a database or elsewhere, you might find this
tip useful.
Issue:
By default, all superglobals are known in every function.
Thus, if you eval database- or dynamically generated code (let's call it "potentially
unsafe code"), it can use _all_ the values stored in _any_ superglobal.
Workaround:
Whenever you want to hide superglobals from use in evaluated code, wrap that eval() in an own
function within which you unset() all the superglobals. The superglobals are not deleted by php in
all scopes - just within that function. eg:
function safeEval($evalcode) {
unset($GLOBALS);
unset($_ENV);
// unset any other superglobal...
return eval($evalcode);
}
(This example assumes that the eval returns something with 'return')
In addition, by defining such a function outside classes, in the global scope, you'll make sure
as well that the evaluated ('unsafe') code doesn't have access to the object
variables ($this-> ...).
--
http://www.php.net/manual/en/language.variables.predefined.php
http://master.php.net/manage/user-notes.php?action=edit+28614
http://master.php.net/manage/user-notes.php?action=delete+28614
http://master.php.net/manage/user-notes.php?action=reject+28614