You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2026/10/11 13:18:52 UTC

(tomcat) 11/20: Keep the derived membership name out of the exposed properties

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

rmaucher pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 725434a65f61aa57afbf3b9184814ff11913b036
Author: opencode <re...@apache.org>
AuthorDate: Sun Oct 11 12:24:05 2026 +0200

    Keep the derived membership name out of the exposed properties
    
    The membership provider is passed the derived membership name through
    the properties, but the builder injected the internal key into the
    very object that the service exposes through its properties, mixing a
    derived value into the administrator view of the configuration and
    into anything built from a dump or a reapply of it.
    
    The key now goes to the provider on a clone of the configuration,
    which also keeps the lookups through caller supplied defaults intact,
    while the exposed properties stay exactly as they were configured.
    
    Add a test that the exposed properties stay free of the internal key
    and that the start itself proves the provider received the name, for
    building the provider without it fails.
---
 .../tribes/membership/StaticMembershipService.java |  7 ++++--
 .../membership/TestStaticMembershipService.java    | 25 ++++++++++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/tribes/membership/StaticMembershipService.java b/java/org/apache/catalina/tribes/membership/StaticMembershipService.java
index 85fc6b9ae0..b4d9d3101e 100644
--- a/java/org/apache/catalina/tribes/membership/StaticMembershipService.java
+++ b/java/org/apache/catalina/tribes/membership/StaticMembershipService.java
@@ -97,8 +97,11 @@ public class StaticMembershipService extends MembershipServiceBase implements St
         provider.setMembershipListener(this);
         provider.setMembershipService(this);
         provider.setStaticMembers(staticMembers);
-        properties.setProperty("membershipName", getMembershipName());
-        provider.init(properties);
+        // Pass the derived membership name to the provider on a copy of the configuration, so the
+        // internal key does not leak into the properties this service exposes
+        Properties providerProperties = (Properties) properties.clone();
+        providerProperties.setProperty("membershipName", getMembershipName());
+        provider.init(providerProperties);
         return provider;
     }
 
diff --git a/test/org/apache/catalina/tribes/membership/TestStaticMembershipService.java b/test/org/apache/catalina/tribes/membership/TestStaticMembershipService.java
index a72fc0b7c7..ddafa78835 100644
--- a/test/org/apache/catalina/tribes/membership/TestStaticMembershipService.java
+++ b/test/org/apache/catalina/tribes/membership/TestStaticMembershipService.java
@@ -95,4 +95,29 @@ public class TestStaticMembershipService {
         }
         Assert.assertNull(service.getMembershipProvider());
     }
+
+    /*
+     * The membership name is derived for the provider alone. It must not leak into the
+     * configuration properties that the service exposes, while the provider must still receive
+     * it, which the start itself proves, as it would fail without the name.
+     */
+    @Test
+    public void testMembershipNameStaysOutOfTheExposedProperties() throws Exception {
+        GroupChannel channel = new GroupChannel();
+        channel.setName("TestStaticMembershipService-" + System.nanoTime());
+
+        StaticMembershipService service = new StaticMembershipService();
+        service.setChannel(channel);
+        service.addStaticMember(new StaticMember("127.0.0.1", 4004, -1));
+        service.setLocalMemberProperties("127.0.0.1", 4004, 0, 0);
+
+        int level = Channel.MBR_RX_SEQ | Channel.MBR_TX_SEQ;
+        service.start(level);
+        try {
+            Assert.assertFalse("the internal membership name must not leak into the properties",
+                    service.getProperties().containsKey("membershipName"));
+        } finally {
+            service.stop(level);
+        }
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org