开发者

Ensuring user input code does not damage server when executed

I'm working on a web app that can allow the user to input some code, and it will be compiled and executed, and they can see开发者_开发技巧 the result. I'm coding the app in PHP and I need a way to ensure that if the user inputs some harmful code (this example is PHP), it can't execute and destroy my server. Example:

<?php
shell_exec('rm -rf /');
?>

I'm thinking that permissions on the uploaded code's file might do it just fine, but I wanted some secondary input. Thanks!


Do not do this unless you are a security professional. There are countless ways to destroy things that you can't possibly forsee.

The only case in which this is acceptable is if you give each user an actual user in the system with its own home directory, permission set, etc. and ensure that they can't actually touch anything that's not theirs whatsoever. And, even then, you'll still get hit with something you didn't expect.

I wouldn't trust myself to write something like this for another good 10 years, minimum, if even then. Users are never trustworthy, ever, and there's always someone smarter out there. No way am I giving out that kind of freedom.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜