spring-cloud / spring-cloud/spring-cloud-gateway

Discuss safer alternative for SpEL string methods in DiscoveryClientRouteDefinitionLocator (Replacement for #4216)

Open
#4,247 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
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:

  1. Provide a custom set of explicitly allowed SpEL functions (e.g. #replaceFirst(target, regex, replacement)) registered directly in the StandardEvaluationContext or SimpleEvaluationContext specifically for common string manipulations.
  2. Introduce a new configuration property for DiscoveryLocatorProperties such as serviceIdRegex and serviceIdReplacement to 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.