Re: Providing sandboxed versions of include and require language constructs

From: Date: Tue, 06 Mar 2012 16:13:58 +0000
Subject: Re: Providing sandboxed versions of include and require language constructs
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-58668@lists.php.net to get a copy of this message
On 03/06/2012 06:03 AM, John Crenshaw wrote: > I've seen a simple "safe" code evaluator put together using token_get_all. > I'm certain that you could create an include_restricted() function in userland using a similar > system: walk through the tokens looking for anything forbidden (this will be tricky, because there > are a lot of nooks that things could hide, like superglobals), then if everything looks good include > the file. Use a caching system of some sort to improve performance and eliminate redundant checks. Yeah, a token approach wouldn't work. $a = 'mysql_connect'; $a($args); trivially circumvents that. It would have to build new function/class hashtables directly which is rather expensive so from a performance perspective this would not be pretty. I suppose an opcode cache could cache these to speed this up quite a bit, but there would still need to be extra gear in place to manage multiple hash tables and some code to check if there was an overriding hash to be used for every op_array. -Rasmus

« previous php.internals (#58668) next »