I'm developing a platform that allows users to create apps using PHP. Is there any safe way of allowing users to do this? Can you restrict use of functions that could damage existing source code or the server in anyway? I only want them able to use basic functions, and give them access to 1 database. This must be possible, because of the existence of shared servers, ran by many users. ...
Any advice?
You can list all disabled functions in your php.ini. You can set it differently for every vhost
disable_functions = "exec,passthru"
Shared hostings are just doing the same as I stated above.
Other functions that can be considered to diable: readfile,fopen,fsockopen,popen,file_get_contents, include,stream_context_create,chmod,chown
Complete list can be found here
But if you are using these functions inside your code also, It's better to made all code files readonly to apache user or for all, in this case chown and chmod disabling play great role.
Never did this before, but i think this approach can help you with a sane and secure environment.
If you are on ubuntu (debian based) i recommend you create a jailed chroot. From the link
A chroot is basically a special directory on your computer which prevents applications, if run from inside that directory, from accessing files outside the directory. In many ways, a chroot is like installing another operating system inside your existing operating system.
You must also install a dedicated instance of PHP that must be used by applications runned from inside of chroot'd directories.
You can configure your php.ini with "max_execution_time", "disable_functions", ... etc
this is exactly what you need actually.
I used to run a shared server using PHP safe mode, but apparently it's deprecated now.
A better solution is to run each user's PHP processes under a different user account, in a chroot jail, and let the OS worry about security. Users will be able to upload and run arbitrary code, but as long as it's properly sandboxed, they won't be able to do much harm.
You can also use disk quota. Use ulimits for per-user memory usage, and consider disallowing network connections (incoming and outgoing).
For the database, just set them up with a single database, with access to only their own, and don't give them privileges to create more.
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