Skip to content

Commit 3e96214

Browse files
committed
Hide password on cloned connections. Fixes #735
1 parent ced7f35 commit 3e96214

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

docs/content/connection-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ These are the other options that MySqlConnector supports. They are set to sensib
357357
<tr>
358358
<td>Persist Security Info, PersistSecurityInfo</td>
359359
<td>false</td>
360-
<td>When set to false or no (strongly recommended), security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state. Resetting the connection string resets all connection string values, including the password. Recognized values are true, false, yes, and no.</td>
360+
<td>When set to <code>false</code> or no (strongly recommended), security-sensitive information, such as the password, is not returned as part of the connection string if the connection is open or has ever been in an open state. Resetting the connection string resets all connection string values, including the password. Recognized values are true, false, yes, and no.</td>
361361
</tr>
362362
<tr>
363363
<td>ServerRSAPublicKeyFile, Server RSA Public Key File</td>

docs/content/tutorials/migrating-from-connector-net.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,4 @@ The following bugs in Connector/NET are fixed by switching to MySqlConnector. (~
210210
* [#97067](https://bugs.mysql.com/bug.php?id=97067): Aggregate functions on BIT(n) columns return wrong result
211211
* [#97300](https://bugs.mysql.com/bug.php?id=97300): `GetSchemaTable()` returns table for stored procedure with output parameters
212212
* [#97448](https://bugs.mysql.com/bug.php?id=97448): Connecting fails if more than one IP is found in DNS for a named host
213+
* [#97473](https://bugs.mysql.com/bug.php?id=97473): `MySqlConnection.Clone` discloses connection password

src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public sealed class MySqlConnection : DbConnection
2121
#endif
2222
{
2323
public MySqlConnection()
24-
: this(default)
24+
: this("")
2525
{
2626
}
2727

@@ -447,7 +447,7 @@ public override async ValueTask DisposeAsync()
447447
}
448448
}
449449

450-
public MySqlConnection Clone() => new MySqlConnection(m_connectionString);
450+
public MySqlConnection Clone() => new MySqlConnection(this);
451451

452452
#if !NETSTANDARD1_3
453453
object ICloneable.Clone() => Clone();
@@ -675,6 +675,12 @@ internal void SetState(ConnectionState newState)
675675
}
676676
}
677677

678+
private MySqlConnection(MySqlConnection other)
679+
: this(other.m_connectionString)
680+
{
681+
m_hasBeenOpened = other.m_hasBeenOpened;
682+
}
683+
678684
private void VerifyNotDisposed()
679685
{
680686
if (m_isDisposed)

tests/SideBySide/ConnectionTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,15 @@ public void CloneIsClosed()
162162
using var connection2 = (MySqlConnection) connection.Clone();
163163
Assert.Equal(ConnectionState.Closed, connection2.State);
164164
}
165+
166+
[SkippableFact(Baseline = "https://bugs.mysql.com/bug.php?id=97473")]
167+
public void CloneDoesNotDisclosePassword()
168+
{
169+
using var connection = new MySqlConnection(AppConfig.ConnectionString);
170+
connection.Open();
171+
using var connection2 = (MySqlConnection) connection.Clone();
172+
Assert.Equal(connection.ConnectionString, connection2.ConnectionString);
173+
Assert.DoesNotContain("password", connection2.ConnectionString, StringComparison.OrdinalIgnoreCase);
174+
}
165175
}
166176
}

0 commit comments

Comments
 (0)