6

I'm trying to sandbox MVEL expression evaluation. Unfortunately, by default MVEL includes all java.lang.* classes in the expression language, so a user could call "Runtime.exit()" and kill the whole system.

How can I exclude all classes that I haven't explicitly added with addImport()?

I haven't been able to make heads or tails of the VariableResolvers.

ccleve
  • 15,239
  • 27
  • 91
  • 157

3 Answers3

3

As far as I known this is not supported.

I faced this need some time ago on a project of my company. We had to change MVEL quite a bit to introduce a way to configure a custom policy to control access to types and methods. The problem is that you can also access any class by its fully qualified name, so it was not just a matter of removing the default imports. Unfortunately I don't own the code to make it available.

1
ParserContext ctx = new ParserContext();

ctx.addImport("System", String.class);
ctx.addImport("Runtime", String.class);
Shaunak D
  • 20,588
  • 10
  • 46
  • 79
  • Your answer is in danger of deletion. You really need to explain what's happening here and how this answers the question posed. – David Hoelzer May 11 '15 at 19:25
0

Have you tried using AspectJ to constrain these calls from MVEL?

Adrian Herscu
  • 738
  • 1
  • 6
  • 19