是否可以实现一个类似安全管理器的工具来拦截对Rhino中java对象的调用
我正在考虑使用 Rhino 作为脚本语言,但想添加一个层来防止脚本执行任何操作。
在 java 中,我们可以验证类,并在发现我们希望阻止的 api 时发出抱怨。例如,如果您不希望用户接触文件系统,如果有人发现对 java.io.File 等的调用,则会抱怨。
类文件验证等效
- 是否存在一个阶段,可以在脚本加载后但在执行之前验证脚本?
- 当给 eval 一个 String 时,是否会调用相同的回调?
这将是首选,因为每个脚本或小脚本仅检查一次,之后就受到信任。
所有 java 方法调用的运行时拦截
- Rhino 是否在每次尝试执行函数调用时调用一些回调?
- 是否可以仅在某些 api 上安装此检查器,例如当尝试访问 java 类时。
这将允许其他真正的 javascript 对象在没有障碍的情况下执行...
是否有其他方法可以阻止调用 java 对象来执行我希望沙箱操作的操作?
Rhino SecurityController
我不太确定,必须尝试 callWithDomain() 方法。
I am thinking of using Rhino as a scripting language but would like to add a layer to prevent scripts from doing anything and everything.
In java one could verify classes and complain if one spots an api that we wish to prevent. Eg if you dnot want users to touch the filesystem complain if one spots calls to java.io.File etc.
Class file verification equivalent
- Is there a phase where one can verify a script once it has been loaded but before it is executed ?
- Is the same callback called when eval is given a String ?
This would be preferred as each script or scriptlet is only checked once and after that it is trusted.
Runtime interception of all java method calls
- Does Rhino call some callback with each attempt to execute a function call ?
- Is it possible to only install this checker on certain apis such as when one is attempting to access a java class.
This would allow other true javascript objects to execute without the barrier...
Is there some other way of preventing calls to java objects to do stuff that i wish to sandbox ?
Rhino SecurityController
Im not quite sure and will have to try the callWithDomain() method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决我的问题的支持方法是注册一个 ClassShutter。
The support approach to solve my problem is to register a ClassShutter.