We are using GraalVM for some scripting requirements in our product. The version of the GraalVM is 21.2.0 We are using JavaScript and Groovy. We want to forbid some methods on certain classes from using in scripts. Example :
mytest.js
var testService=Java.type('mypackage.TestService');
new testService().forbiddenJavaMethod(); // this should not be called
TestService.java
package mypackage;
public class TestService{
public void forbiddenJavaMethod(){
// business logic
}
}
Is there a way to achieve this in Graal ? I could not find a way to do "method" filtering. Any other approach to solve this?
You can configure host access when configuring the context. Namely
https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/Context.Builder.html#allowHostAccess-org.graalvm.polyglot.HostAccess-
Where the host access can be
https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/HostAccess.html
Or you can go into a lot more fine-grained control using the
HostAccess.Builderhttps://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/HostAccess.Builder.html