确保用户输入代码在执行时不会损坏服务器 [英] Ensuring user input code does not damage server when executed

查看:38
本文介绍了确保用户输入代码在执行时不会损坏服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 web 应用程序,它可以允许用户输入一些代码,它会被编译和执行,他们可以看到结果.我正在用 PHP 编写应用程序,我需要一种方法来确保如果用户输入了一些有害代码(这个例子是 PHP),它就不能执行和破坏我的服务器.示例:

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.

我不相信自己能在接下来的 10 年里写出这样的东西,至少,即使那样.用户永远不值得信赖,永远,而且总有更聪明的人存在.我绝不会给这种自由.

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.

这篇关于确保用户输入代码在执行时不会损坏服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆