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 9bb927ae64ca4edbf0c6b86666d46d71e0725ffa Author: opencode <[email protected]> AuthorDate: Tue Dec 1 22:06:02 2026 +0100 Recognise escaped credential keys when masking maskCredentials compared raw key text literally, while Properties.load decodes Unicode and backslash escapes. A password under a key such as \u0070assword or p\assword therefore reached logs in clear text. Decode property escapes in the candidate key before credential recognition, leaving the raw key and pair in the masked output. Add tests for Unicode and backslash spellings. mvn test passes: 1184 tests, 0 failures. --- .../apache/tomcat/jdbc/pool/PoolProperties.java | 61 +++++++++++++++++++++- .../tomcat/jdbc/pool/PoolPropertiesBase.java | 16 ++++++ 2 files changed, 76 insertions(+), 1 deletion(-) 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 127a8347c5..20de29f529 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 @@ -1571,7 +1571,8 @@ public class PoolProperties implements PoolConfiguration, Cloneable, Serializabl while (keyEnd < segmentEnd && !isCredentialValueSeparator(scrubbed.charAt(keyEnd))) { keyEnd++; } - if (keyEnd < segmentEnd && isCredentialKey(scrubbed.substring(keyStart, keyEnd))) { + if (keyEnd < segmentEnd + && isCredentialKey(decodePropertyEscapes(scrubbed.substring(keyStart, keyEnd)))) { // Keep the pair's key and the separator, hide the value. int valueEnd = segmentEnd; if (afterPairBoundary) { @@ -1618,6 +1619,64 @@ public class PoolProperties implements PoolConfiguration, Cloneable, Serializabl } + /** + * Decodes the escape sequences a {@link Properties} reader applies to a key, so a key written as + * {@code \u0070assword} or {@code p\assword} is recognised as the credential spelling it represents. Malformed + * escapes are left as they are; this is a comparison helper and must not reject a diagnostic string. + * + * @param value the raw key text + * + * @return the text with its property escape sequences decoded + */ + private static String decodePropertyEscapes(String value) { + StringBuilder decoded = new StringBuilder(value.length()); + for (int i = 0; i < value.length(); i++) { + char c = value.charAt(i); + if (c != '\\' || i + 1 >= value.length()) { + decoded.append(c); + continue; + } + char escaped = value.charAt(i + 1); + if (escaped == 'u' && i + 5 < value.length()) { + int codePoint = 0; + boolean valid = true; + for (int j = i + 2; j <= i + 5; j++) { + int digit = Character.digit(value.charAt(j), 16); + if (digit < 0) { + valid = false; + break; + } + codePoint = codePoint * 16 + digit; + } + if (valid) { + decoded.append((char) codePoint); + i += 5; + continue; + } + } + switch (escaped) { + case 't': + decoded.append('\t'); + break; + case 'n': + decoded.append('\n'); + break; + case 'r': + decoded.append('\r'); + break; + case 'f': + decoded.append('\f'); + break; + default: + decoded.append(escaped); + break; + } + i++; + } + return decoded.toString(); + } + + /** * Masks the credential values carried in an interceptor definition string, as a best-effort reading of that syntax * rather than a parse of it. Pairs at any parenthesis depth whose name is a key {@link #isCredentialKey recognises} 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 2dcaa5be41..7dd8a5893a 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 @@ -883,6 +883,22 @@ abstract class PoolPropertiesBase { "the other pair must keep printing with the pair masked, was: " + asString); } + @Test + void maskCredentialsRecognisesEscapedCredentialKeys() { + String[][] cases = { + { "\\u0070assword=secret", "\\u0070assword=********" }, + { "pa\\u0073sword=secret", "pa\\u0073sword=********" }, + { "p\\assword=secret", "p\\assword=********" }, + { "\\u0070assword=secret;foo=bar", "\\u0070assword=********;foo=bar" } }; + for (String[] testCase : cases) { + String masked = PoolProperties.maskCredentials(testCase[0]); + Assertions.assertEquals(testCase[1], masked, + "the escaped key must be recognised as a credential spelling"); + Assertions.assertFalse(masked.contains("secret"), + "the credential value must not leak, was: " + masked); + } + } + @Test void toStringWithholdsSQLStatementText() { PoolProperties properties = new PoolProperties(); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
