Skip to content

Commit c25c44a

Browse files
committed
Hide mechanism properties in MongoCredential#toString
In some cases a mechanism property value can contain sensitive information, so the toString method should be conservative and not include any of them. JAVA-3381
1 parent eb4a479 commit c25c44a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

driver-core/src/main/com/mongodb/MongoCredential.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ public String toString() {
514514
+ ", userName='" + userName + '\''
515515
+ ", source='" + source + '\''
516516
+ ", password=<hidden>"
517-
+ ", mechanismProperties=" + mechanismProperties
517+
+ ", mechanismProperties=<hidden>"
518518
+ '}';
519519
}
520520
}

driver-core/src/test/unit/com/mongodb/MongoCredentialSpecification.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ class MongoCredentialSpecification extends Specification {
296296
credentialOne.hashCode() != credentialTwo.hashCode()
297297

298298
!credentialOne.toString().contains(password)
299+
credentialOne.toString().contains('password=<hidden>')
300+
301+
!credentialTwo.toString().contains(propertyKey.toLowerCase())
302+
!credentialTwo.toString().contains(propertyValue)
303+
credentialTwo.toString().contains('mechanismProperties=<hidden>')
299304
}
300305

301306
def 'testEqualsAndHashCode'() {

0 commit comments

Comments
 (0)