spring-cloud / spring-cloud/spring-cloud-gateway
Discuss safer alternative for SpEL string methods in DiscoveryClientRouteDefinitionLocator (Replacement for #4216)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
As noted in PR #4246 and issue #4216, the removal of withInstanceMethods() from SimpleEvaluationContext in DiscoveryClientRouteDefinitionLocator breaks path predicates that rely on standard String methods like replaceFirst().
Since withInstanceMethods() was intentionally removed to prevent SpEL injection security vulnerabilities, we cannot simply restore it.
Proposal:
We need to discuss a safer enhancement to allow users to format or manipulate serviceId strings in their predicates.
Possible alternatives:
- Provide a custom set of explicitly allowed SpEL functions (e.g.
#replaceFirst(target, regex, replacement)) registered directly in theStandardEvaluationContextorSimpleEvaluationContextspecifically for common string manipulations. - Introduce a new configuration property for
DiscoveryLocatorPropertiessuch asserviceIdRegexandserviceIdReplacementto natively handle regex substitutions during route definition generation without relying on SpEL evaluation at all.
Would love to hear the maintainers' thoughts on which approach would be preferred or if there are other secure ways to support this functionality.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading DiscoveryClientRouteDefinitionLocator and DiscoveryLocatorProperties, then review PR #4246 and issue #4216 for the security regression and existing use of String methods. Compare the proposed safe SpEL functions and configuration-property approaches without restoring withInstanceMethods(). Done means reaching a documented maintainer-approved design for secure serviceId manipulation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, security
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100