Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spring.context.expression.maxLength property #31986

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import org.springframework.beans.factory.BeanExpressionException;
import org.springframework.beans.factory.config.BeanExpressionContext;
import org.springframework.beans.factory.config.BeanExpressionResolver;
import org.springframework.core.SpringProperties;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.ParserContext;
import org.springframework.expression.spel.SpelCompilerMode;
import org.springframework.expression.spel.SpelParserConfiguration;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
Expand Down Expand Up @@ -55,6 +57,19 @@
*/
public class StandardBeanExpressionResolver implements BeanExpressionResolver {

/**
* Property name for the maximum length of a SpEL expression: {@value}.
* @since 6.1.3
* @see SpelParserConfiguration#SpelParserConfiguration(SpelCompilerMode, ClassLoader, boolean, boolean, int, int)
*/
public static final String EXPRESSION_MAX_LENGTH_PROPERTY_NAME = "spring.context.expression.maxLength";
private static final int expressionMaxLength;

static {
String expressionMaxLengthString = SpringProperties.getProperty(EXPRESSION_MAX_LENGTH_PROPERTY_NAME);
expressionMaxLength = expressionMaxLengthString != null ? Integer.parseInt(expressionMaxLengthString) : SpelParserConfiguration.DEFAULT_MAX_EXPRESSION_LENGTH;
}

/** Default expression prefix: "#{". */
public static final String DEFAULT_EXPRESSION_PREFIX = "#{";

Expand Down Expand Up @@ -92,7 +107,7 @@ public String getExpressionSuffix() {
* Create a new {@code StandardBeanExpressionResolver} with default settings.
*/
public StandardBeanExpressionResolver() {
this.expressionParser = new SpelExpressionParser();
this.expressionParser = new SpelExpressionParser(new SpelParserConfiguration(null, null, false, false, Integer.MAX_VALUE, expressionMaxLength));
}

/**
Expand All @@ -101,7 +116,7 @@ public StandardBeanExpressionResolver() {
* @param beanClassLoader the factory's bean class loader
*/
public StandardBeanExpressionResolver(@Nullable ClassLoader beanClassLoader) {
this.expressionParser = new SpelExpressionParser(new SpelParserConfiguration(null, beanClassLoader));
this.expressionParser = new SpelExpressionParser(new SpelParserConfiguration(null, beanClassLoader, false, false, Integer.MAX_VALUE, expressionMaxLength));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SpelParserConfiguration {
* Default maximum length permitted for a SpEL expression.
* @since 5.2.24
*/
private static final int DEFAULT_MAX_EXPRESSION_LENGTH = 10_000;
public static final int DEFAULT_MAX_EXPRESSION_LENGTH = 10_000;

/** System property to configure the default compiler mode for SpEL expression parsers: {@value}. */
public static final String SPRING_EXPRESSION_COMPILER_MODE_PROPERTY_NAME = "spring.expression.compiler.mode";
Expand Down