This is an automated email from the ASF dual-hosted git repository.

Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new d4db5e60d2 fix: DividePlugin specify-domain header to prevent cache 
pollution and restrict to configured upstreams (#6412)
d4db5e60d2 is described below

commit d4db5e60d27c7ba35d583e10068e0f77deac2ed4
Author: hengyuss <[email protected]>
AuthorDate: Sun Jul 5 16:53:52 2026 +0800

    fix: DividePlugin specify-domain header to prevent cache pollution and 
restrict to configured upstreams (#6412)
---
 .../apache/shenyu/plugin/divide/DividePlugin.java  | 30 +++++++++++++++-------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/DividePlugin.java
 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/DividePlugin.java
index d1d1cd7342..5505c8fdbb 100644
--- 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/DividePlugin.java
+++ 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/DividePlugin.java
@@ -61,7 +61,7 @@ public class DividePlugin extends AbstractShenyuPlugin {
     private static final String SHORTEST_RESPONSE = "shortestResponse";
 
     private Long beginTime;
-    
+
     @Override
     protected String getRawPath(final ServerWebExchange exchange) {
         return RequestUrlUtils.getRewrittenRawPath(exchange);
@@ -97,17 +97,29 @@ public class DividePlugin extends AbstractShenyuPlugin {
             Object error = ShenyuResultWrap.error(exchange, 
ShenyuResultEnum.CANNOT_FIND_HEALTHY_UPSTREAM_URL);
             return WebFluxResultUtils.result(exchange, error);
         }
-        Upstream upstream = LoadbalancerUtils.getForExchange(upstreamList, 
ruleHandle.getLoadBalance(), exchange);
+        List<String> specifyDomains = 
exchange.getRequest().getHeaders().get(Constants.SPECIFY_DOMAIN);
+        Upstream upstream;
+        if (CollectionUtils.isNotEmpty(specifyDomains)) {
+            String requested = specifyDomains.get(0);
+            upstream = upstreamList.stream()
+                    .filter(u -> u.getUrl().equals(requested))
+                    .findFirst()
+                    .map(u -> Upstream.builder()
+                            .url(u.getUrl())
+                            .protocol(u.getProtocol())
+                            .weight(u.getWeight())
+                            .warmup(u.getWarmup())
+                            .status(u.isStatus())
+                            .build())
+                    .orElseGet(() -> 
LoadbalancerUtils.getForExchange(upstreamList, ruleHandle.getLoadBalance(), 
exchange));
+        } else {
+            upstream = LoadbalancerUtils.getForExchange(upstreamList, 
ruleHandle.getLoadBalance(), exchange);
+        }
         if (Objects.isNull(upstream)) {
             LOG.error("divide has no upstream");
             Object error = ShenyuResultWrap.error(exchange, 
ShenyuResultEnum.CANNOT_FIND_HEALTHY_UPSTREAM_URL);
             return WebFluxResultUtils.result(exchange, error);
         }
-        // set the http url
-        List<String> specifyDomains = 
exchange.getRequest().getHeaders().get(Constants.SPECIFY_DOMAIN);
-        if (CollectionUtils.isNotEmpty(specifyDomains)) {
-            upstream.setUrl(specifyDomains.get(0));
-        }
         // set domain
         String domain = upstream.buildDomain();
         exchange.getAttributes().put(Constants.HTTP_DOMAIN, domain);
@@ -153,7 +165,7 @@ public class DividePlugin extends AbstractShenyuPlugin {
     protected Mono<Void> handleRuleIfNull(final String pluginName, final 
ServerWebExchange exchange, final ShenyuPluginChain chain) {
         return WebFluxResultUtils.noRuleResult(pluginName, exchange);
     }
-    
+
     private DivideRuleHandle buildRuleHandle(final RuleData rule) {
         return 
DividePluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
     }
@@ -185,5 +197,5 @@ public class DividePlugin extends AbstractShenyuPlugin {
         upstream.getSucceededElapsed().addAndGet(System.currentTimeMillis() - 
beginTime);
         upstream.getSucceeded().incrementAndGet();
     }
-    
+
 }

Reply via email to