Possible Duplicate:
PHP: How To Disable Dangerous Functions
Hi, this is my situation: I must let my clients enter PHP code, but only safe functions like string function, date function etc. So I need the danger PHP functions list to remove them by using string replace before save to PHP file. Any suggestion?
Forget it. Reliable function whitelisting is not possible in php. Example:
$x = 'e' . str_replace('y', 'x', 'yec');
...lots of code...
$x('format c:');
realistic options are
As far as I know, you can only use a black-list approach:
Of course, you have to consider how feasible it is to maintain an updated list of all builtin functions defined by all the possible extensions.
Another possibility I can think of is writing a simple tokenizer:
http://es2.php.net/manual/en/function.token-get-all.php
You can then check the functions used against a white list.
Update: I was under the wrong impression that token_get_all()
would identify function calls but it actually doesn't. They're all T_STRING
s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With