We're looking at allowing a way to embed custom code into a PHP application, and exploring secure/sandboxed ways to do that (e.g. if you've used Apex in Salesforce, or are familiar with ExpressionLanguage in Symfony, that kind of thing).
We're looking for a safe way to execute custom, user-supplied additional custom logic, but make sure it's restricted in that they can't supply e.g. code that executes dangerous filesystem commands.
What do I mean by "sandboxed"?
I want to allow untrusted, user-supplied code to execute.
e.g. we can't just allow someone to execute arbitrary PHP code, because they would have filesystem access and functions like exec(), file(), fopen(), etc. etc.
The nice thing about Twig is that the access given to users is extremely minimal. There's no functions you can use to e.g. access the file system or make HTTP calls.
What we're exploring
One thing we've exploring is allowing custom Twig to run, but the one downside to Twig is that it's really designed as a template language, so it's logic like this is sort of clunky because of all the extra brackets:
{% if foo.bar == 'test' %}
{% for line in lines %}
{% if line.rate > 10 %}
... more code here ...
{% endif %}
{% endfor %}
{% endif %}
It would be much cleaner/easier if we could just write:
if foo.bar == 'test'
{
for line in lines {
if line.rate > 10
{
... more code here ...
}
}
}
Is it possible / has anyone seen Twig extended to support multiple lines of code, and not require all of the {% and %}?
Or failing that... has anyone seen any other option for safely embedding untrusted, user-supplied logic in a PHP app? We've also looked at the PHP Lua extension as a potential option, but I'm not sure how maintained it is...