保护 SSJS 免受未经验证的代码的影响
我想使用node.js(或其他SSJS解决方案),运行我自己的代码+内部编写的外部代码(不受信任)。
有什么方法可以分离和保护我自己的代码吗?我可以限制不受信任的代码的模块和系统影响(限制对文件、非 HTTP 端口等的访问)吗?
I want to use node.js (or other SSJS solution), running my own code + external written code inside (untrusted).
Any way to seperate and protect my own code? Could I limit the modules and system effect of th untrusted code (limit access to files, non HTTP ports, etc.)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以看看这个项目,它看起来很有前途:
http://github.com/gf3/node-沙箱
就我个人而言,我不使用 Node 来执行任意 SSJS。你可能不喜欢这个解决方案,但它对我来说工作了大约一年:
Spidermonkey API 的 Perl 实现(Spidermonkey 是 Firefox 的 JS 引擎)可用。我在一些 CGI 的帮助下将其连接起来。您可以在其中准确指定要公开的函数(当然,它是用 Perl...blech 编写的)并执行您喜欢的任何代码。由于整个设置完全沙盒化,因此不存在漏洞风险。它不模拟 DOM。
我在我的服务器上实现这一点的方法(为了防止滥用)是颁发令牌,通过另一台服务器上的 REST API 授予一次性访问权限。这是一个简单的 HMAC 实现,其中包含一个时间戳来强制令牌的合法性。当 Perl 脚本收到请求时,它会验证令牌并处理脚本(该脚本应该只是 POST 请求的一部分)。然后 Perl 脚本只写入结果。我的服务器设置为在 10 秒左右超时。
希望这有帮助!
You can check out this project, it seems very promising:
http://github.com/gf3/node-sandbox
Personally, I don't use Node to do arbitrary SSJS execution. You probably won't like this solution, but it's worked fine for me for about a year:
There's a Perl implementation of Spidermonkey's API (Spidermonkey is Firefox's JS engine) that's available. I hooked that up with the help of some CGI. You can specify in it exactly what functions you want to expose (granted, it's in Perl...blech) and execute whatever code you please. There's no risk of vulnerabilities since the entire setup is completely sandboxed. It does not simulate the DOM.
The way I implemented this on my server (to prevent abuse) was to issue tokens which granted a one-use access through a REST API on a different server. It's a simple HMAC implementation that includes a timestamp to enforce the legitimacy of the token. When the Perl script receives a request, it validates the token and processes the script (the script should just be part of a POST request). The Perl script then just writes the results. My server is set to hit a timeout at around 10 seconds.
Hope this helps!
请查看 Caja。它将第三方代码转换为一种形式,其中代码只能访问您明确授予它的对象。
Have a look at Caja. It translates third-party code to a form where the code only has access to the objects you explicitly grant it.
从 Node.js 文档中查看这一点
http://nodejs.org/api.html#script-runinnewcontext-105
Check out this from the node.js documentation
http://nodejs.org/api.html#script-runinnewcontext-105