Skip to content

Commit 75fa14d

Browse files
author
Ryan Dew
committed
MLE-30243 Ensure password is sanitized in any logging
1 parent e992d81 commit 75fa14d

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

marklogic-client-api/src/main/java/com/marklogic/client/impl/ConnectionString.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33
*/
44
package com.marklogic.client.impl;
55

@@ -86,4 +86,11 @@ public String getPassword() {
8686
public String getDatabase() {
8787
return database;
8888
}
89+
90+
// Override toString() to avoid printing the password in logs or error messages
91+
@Override
92+
public String toString() {
93+
String db = (database != null) ? "/" + database : "";
94+
return username + ":****@" + host + ":" + port + db;
95+
}
8996
}

marklogic-client-api/src/test/java/com/marklogic/client/impl/DatabaseClientPropertySourceTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33
*/
44
package com.marklogic.client.impl;
55

@@ -197,6 +197,18 @@ void nonNumericPortInConnectionString() {
197197
assertEquals("Invalid value for connection string; port must be numeric, but was 'nonNumericPort'", ex.getMessage());
198198
}
199199

200+
@Test
201+
void toStringRedactsPassword() {
202+
ConnectionString cs = new ConnectionString("user:secret@localhost:8000", "connection string");
203+
assertEquals("user:****@localhost:8000", cs.toString());
204+
}
205+
206+
@Test
207+
void toStringRedactsPasswordWithDatabase() {
208+
ConnectionString cs = new ConnectionString("user:secret@localhost:8000/Documents", "connection string");
209+
assertEquals("user:****@localhost:8000/Documents", cs.toString());
210+
}
211+
200212
@Test
201213
void hostTakesPrecedence() {
202214
props.put(PREFIX + "host", "somehost");

0 commit comments

Comments
 (0)