5

I'm writing a collaborative project designed to allow code contributions from users. Users will be able to extend a class, add functionality etc, and submit the code back to the server for regular execution.

Is there a safe way to execute users' PHP code? A foolproof sanitizing method? What about infinite loops? Or should I offer a different scripting language?

2
  • 3
    this should not be handled by asking a question on StackOverflow. hire an expert or you are going to get in big troubles Commented Aug 7, 2009 at 15:37
  • It's a toy project I'm working on tonight with friends and b33r. I don't think a hired expert would be impressed :D Commented Aug 7, 2009 at 15:52

3 Answers 3

6
  • JailRoot for the DocumentRoot

  • SafeMode ON to allow access to files only on specific directories

  • Use a per USER MPM to limit system
    resources to the apache process

  • Set safe php.ini settings for memmory limit and max_execution_time

And as Saggi Malachi noted, this is very experimental, you have to monitor the actions on the server and have fallback szenarios, eg. cronjobs watching load average, if loadaverage is above threshold stop apache and sendmail.

Other good idea is to compile your own php und deny access to php functions which could be "exploited" by your users.

Sign up to request clarification or add additional context in comments.

Comments

0

Securing against users accessing or changing files can be done with safemode.

Securing against infinite loops require setting some amount of time the php interpreter gets to generate the site. set_time_limit

You also need to stop users communicating with outside servers to avoid it being used as a spam sender. allow_url_fopen

There are probably a lot of other more serious issues. This is no easy task.

Comments

0

Maybe I could use server-side Javascript instead with SpiderMonkey

It sounds much safer!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.