Monday, March 12, 2012

Using SQL Server Authentication (i.e. not Integrated/Trusted)? Concerned about your passwords being discoverable? Wish you could using something like SecureString?Check out the new SqlCredential in .Net 4.5

ADO.NET team blog - Safer passwords with SqlCredential


Many users of SqlClient with SQL Server Authentication have expressed interest in setting credentials outside of the connection string to mitigate the memory dump vulnerability of keeping the User Name and Password in the connection string. Starting with .Net Framework 4.5, we have introduced the ability to set the credentials outside of the connection string via the new SqlCredential Credential property of SqlConnection. Now the developer can create a SqlCredential object with a UserId and a SecureString Password to hold the credential values of a connection when connecting to a server. This helps mitigate the threat of credentials being leaked out to the page file in a page swap or being evident in a crash dump.


SqlCredential Class

More information about the new SqlCredential class can be found at:

For information on how to get or set the SqlConnection.Credential property, please refer to:

It’s important to note that the SqlCredential constructor only allows SecureString marked as read only to be passed in as the Password parameter or it will raise an ArgumentException. The new credential property is incompatible with existing UserId, Password, Context Connection=True, and Integrated Security=True connection string keywords, and setting the credential property on an open connection is not allowed. It is strongly recommended that you set PersistSecurityInfo=False (default) so the credential property is not returned as part of the connection once it is opened.

Connection Pooling with Credential Property

With this new improvement now the connection pooling algorithm also takes the Credential property into consideration in addition to the connection string property when creating connection pools and getting connections from the pool. Connections with the same connection string and same instance of Credential property will use the same connection pool, but connections with different instances of the Credential property will use different connection pools, even if they use the same UserId and Password. For example, the developer tries to open several connections with different configurations as below:


Of course the usage of SQL Server Integrated Authentication Mode is still the recommended way to authenticate for users with an Active Directory® infrastructure as there is no credential propagation and all security sensitive information is stored in the Active Directory’s database. And the usage of SQL Server Mixed Mode Authentication with UserId and Password specified in the connection string remains unchanged.


This is one of those thing that would so easily fall through the cracks with all the recent news and releases, so I wanted to call it out. If you have to use Standard security in your SQL Server apps then when you move to .Net 4.5, take this extra step to secure your users passwords. At first glance it looks pretty painless yet could have a nice security bang for the buck...

No comments: