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

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

commit d312df91125a5cd6b9adb050dc70cc3b02c389c8
Author: opencode <[email protected]>
AuthorDate: Wed Oct 7 16:20:31 2026 +0200

    Trim whitespace when parsing the checkedOsUsers list in SecurityListener
    
    Entries in a comma separated checkedOsUsers configuration such as
    "root, admin" were stored without trimming, so an entry containing
    whitespace never matched the actual value of user.name and the
    prohibition check was silently disabled for that user. Trim each
    entry before adding it to the set of prohibited users.
---
 .../apache/catalina/security/SecurityListener.java |  1 +
 .../catalina/security/TestSecurityListener.java    | 52 ++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/java/org/apache/catalina/security/SecurityListener.java 
b/java/org/apache/catalina/security/SecurityListener.java
index 5acf512e30..c14405bad7 100644
--- a/java/org/apache/catalina/security/SecurityListener.java
+++ b/java/org/apache/catalina/security/SecurityListener.java
@@ -101,6 +101,7 @@ public class SecurityListener implements LifecycleListener {
         } else {
             String[] userNames = userNameList.split(",");
             for (String userName : userNames) {
+                userName = userName.trim();
                 if (!userName.isEmpty()) {
                     
checkedOsUsers.add(userName.toLowerCase(Locale.getDefault()));
                 }
diff --git a/test/org/apache/catalina/security/TestSecurityListener.java 
b/test/org/apache/catalina/security/TestSecurityListener.java
new file mode 100644
index 0000000000..14c7a3c5fb
--- /dev/null
+++ b/test/org/apache/catalina/security/TestSecurityListener.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.security;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestSecurityListener {
+
+    private final String originalUserName = System.getProperty("user.name");
+
+    @After
+    public void restoreUserName() {
+        if (originalUserName != null) {
+            System.setProperty("user.name", originalUserName);
+        } else {
+            System.clearProperty("user.name");
+        }
+    }
+
+    @Test
+    public void testCheckOsUserWithWhitespaceInList() {
+        SecurityListener listener = new SecurityListener();
+        listener.setCheckedOsUsers("root, admin");
+
+        System.setProperty("user.name", "admin");
+        try {
+            listener.checkOsUser();
+        } catch (Error e) {
+            // Expected. Before the fix the whitespace was not trimmed so the
+            // entry never matched and no Error was thrown.
+            return;
+        }
+        Assert.fail("User [admin] was expected to be prohibited by the " +
+                "configured list [root, admin]");
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to