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

feat(SpEL): implement to configure the limit of characters for SpEL expressions #1429

Merged
merged 2 commits into from
Jul 2, 2024

Conversation

j-sandy
Copy link
Contributor

@j-sandy j-sandy commented Jun 26, 2024

Spring Expression Lanuage (SpEL) has a default limit of 10,000 characters. Springframework provides the feature to configure the limit. This feature allows to configure the limit of characters for SpEL expressions.

Approach:
In order to use an expression with characters more than the given default limit, require to follow either of the below approaches:

  1. For Springframework >=5.3.28 and <6.1.3, by setting maximumExpressionLength field while instantiating the custom SpelParserConfiguration class.
    Make maximum SpEL expression length configurable spring-projects/spring-framework#30380
    Make maximum SpEL expression length configurable spring-projects/spring-framework#30446

  2. For Springframework >=6.1.3, by setting a JVM system property or Spring property named spring.context.expression.maxLength to the maximum expression length needed by your application.
    Make maximum length of SpEL expressions in an ApplicationContext configurable spring-projects/spring-framework#31952
    spring-projects/spring-framework@7855986

Spinnaker supports spring boot 2.7.18, that brings springframework 5.3.31 [https://docs.spring.io/spring-boot/docs/2.7.18/reference/html/dependency-versions.html#appendix.dependency-versions.propertie9]. So first approach need to be implemented along with spinnaker enhancement to expose the maximumExpressionLength field.

private final ParserContext parserContext = new TemplateParserContext("${", "}");

public ExpectedArtifactExpressionEvaluationPostProcessor(ObjectMapper mapper) {
public ExpectedArtifactExpressionEvaluationPostProcessor(
ObjectMapper mapper, @Autowired ExpressionProperties expressionProperties) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is @Autowired required here. Doesn't everything get autowired via @Component?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is required as we are using it in constructor of a component and concluding its use inside the constructor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But...we don't have it for ObjectMapper. Why is ExpressionProperties different?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified without using @Autowired, build and tests are passing. So, updating code as suggested.

@j-sandy j-sandy force-pushed the spel-expr-len branch 4 times, most recently from 61e42b3 to c39989a Compare July 2, 2024 16:39
…xpressions

Spring Expression Lanuage (SpEL) has a default limit of 10,000 characters. Springframework provides the feature to configure the limit. This feature allows to configure the limit of characters for SpEL expressions.

Approach:
In order to use an expression with characters more than the given default limit, require to follow either of the below approaches:
1. For Springframework >=5.3.28 and <6.1.3, by setting `maximumExpressionLength` field while instantiating the custom `SpelParserConfiguration` class.
spring-projects/spring-framework#30380
spring-projects/spring-framework#30446

2. For Springframework >=6.1.3, by setting a JVM system property or Spring property named `spring.context.expression.maxLength` to the maximum expression length needed by your application.
spring-projects/spring-framework#31952
spring-projects/spring-framework@7855986

Spinnaker supports spring boot 2.7.18, that brings springframework 5.3.31 [https://docs.spring.io/spring-boot/docs/2.7.18/reference/html/dependency-versions.html#appendix.dependency-versions.propertie9]. So first approach need to be implemented along with spinnaker enhancement to expose the `maximumExpressionLength` field.
@dbyron-sf
Copy link
Contributor

@Mergifyio update

Copy link
Contributor

mergify bot commented Jul 2, 2024

update

✅ Branch has been successfully updated

@dbyron-sf dbyron-sf marked this pull request as ready for review July 2, 2024 19:52
@dbyron-sf dbyron-sf added the ready to merge Approved and ready for merge label Jul 2, 2024
@mergify mergify bot added the auto merged label Jul 2, 2024
@mergify mergify bot merged commit d97ff35 into spinnaker:master Jul 2, 2024
5 checks passed
@j-sandy j-sandy deleted the spel-expr-len branch July 3, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants