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

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

commit cff43d85af6361ed1ec0c385fcdd2622149770d7
Author: opencode <[email protected]>
AuthorDate: Tue Dec 1 22:44:50 2026 +0100

    Recognise passwd as a password alias
    
    PoolUtilities.isCredentialKey recognised password, pass and pwd, but not 
passwd. A password stored under passwd survived setPassword rotation or 
clearing, masked copies and driver-property cleanup, and appeared in logs.
    
    Add passwd to the alias predicate and update the affected documentation and 
tests for masking, rotation, clearing, defaults-backed entries and utility 
copies.
    
    mvn test passes: 1187 tests, 0 failures.
---
 .../apache/tomcat/jdbc/pool/DataSourceProxy.java   |  2 +-
 .../apache/tomcat/jdbc/pool/PoolProperties.java    |  6 +++---
 .../org/apache/tomcat/jdbc/pool/PoolUtilities.java |  8 ++++----
 .../apache/tomcat/jdbc/pool/PooledConnection.java  |  2 +-
 .../tomcat/jdbc/pool/jmx/ConnectionPool.java       |  2 +-
 .../tomcat/jdbc/pool/PoolPropertiesBase.java       | 22 +++++++++++++++++++---
 .../tomcat/jdbc/pool/util/PoolUtilitiesBase.java   |  2 ++
 7 files changed, 31 insertions(+), 13 deletions(-)

diff --git 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
index ba4140e5c4..8b362712fd 100644
--- 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
+++ 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
@@ -1345,7 +1345,7 @@ public class DataSourceProxy implements PoolConfiguration 
{
 
     /**
      * Returns a copy of the database properties with the credential entries 
removed. A credential entry is one whose
-     * key is {@code password}, {@code pass} or {@code pwd}, ignoring case and 
surrounding whitespace. This object
+     * key is {@code password}, {@code pass}, {@code pwd} or {@code passwd}, 
ignoring case and surrounding whitespace. This object
      * doubles as its own JMX/bean surface and {@link #setPassword(String)} 
puts the password into the database
      * properties, so returning them as they are would expose the plaintext 
password through a getter while
      * {@link #getPassword()} is explicitly masked -
diff --git 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
index 767a97bece..30046f7b8a 100644
--- 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
+++ 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
@@ -977,7 +977,7 @@ public class PoolProperties implements PoolConfiguration, 
Cloneable, Serializabl
         this.passwordCleared = password == null;
         if (this.dbProperties != null) {
             // A non-null password replaces every spelling of the credential, 
not only the canonical
-            // lower-case key: an older pass, pwd or PASSWORD entry must not 
keep authenticating
+            // lower-case key: an older pass, pwd, passwd or PASSWORD entry 
must not keep authenticating
             // connections with the superseded value.
             removeCredentialDbProperties(password == null);
             if (password != null) {
@@ -989,7 +989,7 @@ public class PoolProperties implements PoolConfiguration, 
Cloneable, Serializabl
 
     /**
      * Removes every database property whose key is recognized as a password 
alias, so clearing the password also
-     * stops a value configured as {@code pass} or {@code pwd} from still 
authenticating connections. When a new
+     * stops a value configured as {@code pass}, {@code pwd} or {@code passwd} 
from still authenticating connections. When a new
      * password replaces the old one, the canonical entry is written again 
after this removal; the warning for a
      * credential the string still names is only wanted when the credential is 
actually being cleared.
      *
@@ -1532,7 +1532,7 @@ public class PoolProperties implements PoolConfiguration, 
Cloneable, Serializabl
      * Masks the credentials embedded in a raw configuration string so that a 
password typed into the JDBC URL or the
      * connection properties is not printed in cleartext. The pool applies 
this wherever it logs diagnostics about these
      * strings, so the log and the configuration dump agree on what a masked 
configuration looks like. Two shapes are
-     * scrubbed: the value of a pair whose key is {@code password}, {@code 
pass} or {@code pwd}, and the password of a
+     * scrubbed: the value of a pair whose key is {@code password}, {@code 
pass}, {@code pwd} or {@code passwd}, and the password of a
      * URL {@code user:password@host} or {@code user/password@host} userinfo 
section. The pass is best effort: secrets
      * carried under another key or in a driver-specific dialect are not 
recognised.
      *
diff --git 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolUtilities.java
 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolUtilities.java
index c3d38fa262..7937495b88 100644
--- 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolUtilities.java
+++ 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolUtilities.java
@@ -94,8 +94,8 @@ public class PoolUtilities {
 
     /**
      * Whether {@code key} names a credential, ignoring case and surrounding 
whitespace. The drivers accept
-     * {@code pass} and {@code pwd} as aliases of {@code password}, so a 
masked copy has to remove the same spellings
-     * the string maskers treat as credentials.
+     * {@code pass}, {@code pwd} and {@code passwd} as aliases of {@code 
password}, so a masked copy has to remove the
+     * same spellings the string maskers treat as credentials.
      *
      * @param key the property key to test, possibly {@code null}
      *
@@ -107,7 +107,7 @@ public class PoolUtilities {
         }
         String candidate = key.trim();
         return PROP_PASSWORD.equalsIgnoreCase(candidate) || 
"pass".equalsIgnoreCase(candidate)
-                || "pwd".equalsIgnoreCase(candidate);
+                || "pwd".equalsIgnoreCase(candidate) || 
"passwd".equalsIgnoreCase(candidate);
     }
 
     /**
@@ -157,7 +157,7 @@ public class PoolUtilities {
      * does, with every credential entry removed and every credential embedded
      * in a string value masked. A credential entry is one whose key is
      * recognised by {@link #isCredentialKey(String)}: {@code password},
-     * {@code pass} and {@code pwd}, ignoring case and surrounding whitespace.
+     * {@code pass}, {@code pwd} and {@code passwd}, ignoring case and 
surrounding whitespace.
      * A value can itself carry a credential - a {@code url} property whose
      * value is a URL with a userinfo password, or a value holding a
      * credential pair - so string values are passed through the same masking
diff --git 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
index 8890020fe9..d0418675f6 100644
--- 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
+++ 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
@@ -733,7 +733,7 @@ public class PooledConnection implements 
PooledConnectionMBean {
         }
         // The overlay is the credential setters' every-spelling rule at the
         // last boundary: while a credential field is set its value replaces
-        // every spelling of the key, so a superseded pass, pwd, PASSWORD or
+        // every spelling of the key, so a superseded pass, pwd, passwd, 
PASSWORD or
         // USER entry in the live collection cannot reach the driver next to
         // the canonical one. With the field unset nothing is removed: the
         // entry in the collection is then the one the driver gets, as
diff --git 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
index 9bc371b4a6..8951740a79 100644
--- 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
+++ 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
@@ -532,7 +532,7 @@ public class ConnectionPool extends 
NotificationBroadcasterSupport implements Co
     /**
      * Returns a copy of the database properties with the credential entries 
removed, so the JMX surface does not
      * expose the plaintext password while {@link #getPassword()} is 
explicitly masked. A credential entry is one whose
-     * key is {@code password}, {@code pass} or {@code pwd}, ignoring case and 
surrounding whitespace. A configuration
+     * key is {@code password}, {@code pass}, {@code pwd} or {@code passwd}, 
ignoring case and surrounding whitespace. A configuration
      * whose database properties are {@code null} - a state {@link 
PoolConfiguration#setDbProperties(Properties)}
      * accepts - has nothing to mask, so this returns {@code null}. 
{@inheritDoc}
      * <p>
diff --git 
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/PoolPropertiesBase.java
 
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/PoolPropertiesBase.java
index 89ad319ee0..548a7fc445 100644
--- 
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/PoolPropertiesBase.java
+++ 
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/PoolPropertiesBase.java
@@ -451,7 +451,7 @@ abstract class PoolPropertiesBase {
     @Test
     void settingNewCredentialsReplacesEveryCredentialAlias() {
         PoolProperties properties = new PoolProperties();
-        
properties.setConnectionProperties("keep=yes;pass=old;PWD=older;PASSWORD=oldest;USER=bob;user=old");
+        
properties.setConnectionProperties("keep=yes;pass=old;passwd=older2;PWD=older;PASSWORD=oldest;USER=bob;user=old");
 
         properties.setPassword("newpassword");
         properties.setUsername("alice");
@@ -460,6 +460,8 @@ abstract class PoolPropertiesBase {
                 "the canonical password entry must hold the new value");
         Assertions.assertNull(properties.getDbProperties().getProperty("pass"),
                 "an older pass alias must not keep authenticating 
connections");
+        
Assertions.assertNull(properties.getDbProperties().getProperty("passwd"),
+                "an older passwd alias must not keep authenticating 
connections");
         Assertions.assertNull(properties.getDbProperties().getProperty("PWD"),
                 "a case-variant pwd alias must not keep authenticating 
connections");
         
Assertions.assertNull(properties.getDbProperties().getProperty("PASSWORD"),
@@ -543,7 +545,7 @@ abstract class PoolPropertiesBase {
     @Test
     void clearingThePasswordAlsoStripsCredentialAliases() {
         PoolProperties properties = new PoolProperties();
-        
properties.setConnectionProperties("pass=one;pwd=two;password=three;user=u");
+        
properties.setConnectionProperties("pass=one;pwd=two;passwd=two-and-a-half;password=three;user=u");
 
         properties.setPassword(null);
 
@@ -553,9 +555,12 @@ abstract class PoolPropertiesBase {
                 "the pass alias must not keep authenticating connections");
         Assertions.assertNull(properties.getDbProperties().getProperty("pwd"),
                 "the pwd alias must not keep authenticating connections");
+        
Assertions.assertNull(properties.getDbProperties().getProperty("passwd"),
+                "the passwd alias must not keep authenticating connections");
         Assertions.assertEquals("u", 
properties.getDbProperties().getProperty("user"),
                 "non-credential entries must be left alone");
-        Assertions.assertEquals("pass=one;pwd=two;password=three;user=u", 
properties.getConnectionProperties(),
+        
Assertions.assertEquals("pass=one;pwd=two;passwd=two-and-a-half;password=three;user=u",
+                properties.getConnectionProperties(),
                 "the configured string is not rewritten by a credential 
clear");
     }
 
@@ -564,6 +569,7 @@ abstract class PoolPropertiesBase {
         Properties defaults = new Properties();
         defaults.setProperty("pass", "one");
         defaults.setProperty("pwd", "two");
+        defaults.setProperty("passwd", "two-and-a-half");
         defaults.setProperty(PoolUtilities.PROP_PASSWORD, "three");
         PoolProperties properties = new PoolProperties();
         properties.setDbProperties(new Properties(defaults));
@@ -574,6 +580,8 @@ abstract class PoolPropertiesBase {
                 "a defaults-supplied pass alias must be cleared");
         Assertions.assertNull(properties.getDbProperties().getProperty("pwd"),
                 "a defaults-supplied pwd alias must be cleared");
+        
Assertions.assertNull(properties.getDbProperties().getProperty("passwd"),
+                "a defaults-supplied passwd alias must be cleared");
         
Assertions.assertNull(properties.getDbProperties().getProperty(PoolUtilities.PROP_PASSWORD),
                 "a defaults-supplied password must be cleared");
         
Assertions.assertNull(PoolUtilities.clone(properties.getDbProperties()).getProperty("pass"),
@@ -899,6 +907,14 @@ abstract class PoolPropertiesBase {
         }
     }
 
+    @Test
+    void maskCredentialsRecognisesThePasswdAlias() {
+        Assertions.assertEquals("passwd=********", 
PoolProperties.maskCredentials("passwd=secret"),
+                "the passwd spelling must be masked like the other credential 
aliases");
+        Assertions.assertEquals("PASSWD=********;foo=bar", 
PoolProperties.maskCredentials("PASSWD=secret;foo=bar"),
+                "the passwd spelling must be recognised ignoring case and 
followed by the next pair");
+    }
+
     @Test
     void toStringWithholdsSQLStatementText() {
         PoolProperties properties = new PoolProperties();
diff --git 
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/util/PoolUtilitiesBase.java
 
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/util/PoolUtilitiesBase.java
index d5bda4d36b..132b8c6c4c 100644
--- 
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/util/PoolUtilitiesBase.java
+++ 
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/util/PoolUtilitiesBase.java
@@ -161,6 +161,7 @@ abstract class PoolUtilitiesBase {
         source.setProperty(PoolUtilities.PROP_PASSWORD, "secret1");
         source.setProperty("pass", "secret2");
         source.setProperty("pwd", "secret3");
+        source.setProperty("passwd", "secret3b");
         source.setProperty("PASSWORD", "secret4");
         source.setProperty(" Password ", "secret5");
 
@@ -176,6 +177,7 @@ abstract class PoolUtilitiesBase {
         Properties defaults = new Properties();
         defaults.setProperty("pass", "secret1");
         defaults.setProperty("pwd", "secret2");
+        defaults.setProperty("passwd", "secret2b");
         defaults.setProperty("PASSWORD", "secret3");
         defaults.setProperty("sslmode", "verify-full");
         Properties source = new Properties(defaults);


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

Reply via email to