You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The SecureString type does not actually fulfill the promises it makes to developers. MSDN already disrecommends its use in new code, and there's other documentation listing some technical reasons why it can't fulfill its promises.
We've already seen customers who use this type in server applications in an effort to fulfill auditing / compliance requirements, then those customers get bitten because they fail their audits. I detailed this a little more on Twitter, including suggesting mechanisms that customers could use to meet compliance requirements.
This legacy type is a different scenario than legacy types like ArrayList (the non-generic collection type). Types like ArrayList aren't recommended for new code because there are better alternatives available, but there's no real harm in keeping those older types around for compatibility reasons. Contrast this against SecureString, where the existence of the type is causing active harm to customers who use it and subsequently fail audits.
Since the type purports to make security promises to developers, and since it cannot fulfill those promises, it should be obsoleted in the next version of .NET Core.
Yes, for example the PasswordBox control returns password as SecureString. This prevents the password from being written out to log files and it’s required to work with some native Win32 authentication API.
The same way you can remove MD5 hash algorithm from .NET because people are using it to insecurely store passwords.
You've got about the only good example of using it right, powershell passwords being the other. MD5 at least as more legitimate uses (and is baked into the HTTP standard. Heck we can't remove 3DES because it's part of EMV).
If it was moved out of corefx and into a separate, unsuipported package, where eventually a lot of bad decisions will go and which would have a horrific name like Microsoft.Unsupported.UnsafeThings (this is why no-one lets me name stuff), where you could opt into using it, and would have to put an extra flag in your solution to maybe make people think some more, would that be helpful?
FYI I'm not suggesting deleting the type, only obsoleting it.
Jozef, who is the adversary in your scenarios threat model? How does the use of SecureString in this particular scenario thwart the adversary?
Edit: I ask not to be argumentative, but because there might exist an opportunity to create a better type for your scenario. We might be able to craft something more narrow in scope than what SecureString was trying to accomplish, and perhaps that replacement would be better suited for your application.
In addition to logging, PowerShell also relies on this type to determine when to prompt without echo. Would it make sense to have a SensitiveString type that would also zero out memory on dispose? At least this would set some expectation, and maybe allow migration over time.
Reacted by Niels Swimberghe, Keith Hill and Joel Bennett
SecureString has it's obvious usages in the WinForms, WPF and PowerShell API.
Without providing any replacement nor information how to do it right and what will you do to make existing workflows like asking for passwords in console apps, password boxes, etc. and preventing passwords from leaking in places like loggin it does make sense to delete a class from .NET Framwork.
Having such a needed class in unsupported library? Ehm, no, just no.
Reacted by stevenwdv, Tyler, Tigran TIKSN Torosyan, Felix Becker and Joel Bennett
@jozefizso I admit I am a little confused when you mention Win32. Windows has no idea about securestrings, they're purely a .NET concept. Which APIs are you thinking of here?
@jozefizso That's not a Win32 method, that's the marshaller method for how to pass a SecureString to a C function that takes wchar*. (Decrypt it, pass the pointer to where it's decrypted) Whatever Win32 functions are being called could work just as well with System.String, or char[].
I'm not a professional developer yet, so I don't know if my opinion counts, but it seems weird to me that this would be obsoleted. Aren't there still benefits in using this? If you're careful you can make sure that the string has a short, predetermined, lifetime.
But maybe I'm missing something: 'obsoleted' means that it is no longer needed because there is a better alternative, right? Can you tell me what this alternative would be? (For cases where we request a password from the user.) It seems to me that using a normal string would not be better, so I guess this is not what you mean.
Reacted by Jozef Izso, Tyler, Miguel Cudaihl and hilari0n
You populate it via a one-character-at-a-time source with no read-ahead, or
You populate it from a native wchar* (aka C# char*) in the SecureString(char*, int) constructor.
It is properly used
It is only ever used in a P/Invoke signature (or C# code that operates on the char* from the Marshaller output).
Effectively, if you've ever had the value in a System.String instance then you've lost all the "value" SecureString offers.
'obsoleted' means that it is no longer needed because there is a better alternative, right? Can you tell me what this alternative would be?
It depends on your threat model / risk concern:
If you believe someone is actively inspecting your memory (live or hiberfil.sys):
The password/sensitive-material needs to never be in your memory.
Windows: You need a secure desktop prompt that is feeding directly into LSASS, doing work in the LSA process, and sending only the "safe" result back to your process. (No, I don't think we have code to make that happen).
Linux/macOS: I don't know of a solution.
If you're concerned you'll accidentally print it in log statements:
Wrap a System.String in a struct with no ToString defined (or public override string ToString() => "** REDACTED **";
If you're just mildly concerned about the password being in WER uploads or pagefiles:
It seems to me that using a normal string would not be better, so I guess this is not what you mean.
It is. Just use System.String. Statistically speaking, you already had the value in a System.String (via a web request, or File.ReadAllText, or whatever), or you're at some point going to write a method like SecureStringToString, and now you've just warmed up your CPU for no real benefit.
If you're careful you can make sure that the string has a short, predetermined, lifetime.
So long as you never copied the data into byte[], char[], or System.String, sure. Most people aren't careful.
but it seems weird to me that this would be obsoleted
Very interesting discussion around SecureString. We've got some services that connect to Azure SQL DB from a WinForms app (No ASP.NET). Need to encrypt the ConnectionString's password (this password is not typed, by an user, it's hardcoded in the ConnectionString itself). I'm not able to use Azure's AKS as I'd still need to hardcode at least one secret. Would you recommend SecureString or any other approach to get this done securely? Thanks!
@sterenas Your scenario involves encryption of data at rest, such as connection strings being read from a config file? SecureString never helped with those scenarios; it only ever worked on ephemeral data.
If you've got persisted data you need to encrypt on the local box, using X.509 certificates (for server farms) or DPAPI (for consumer machines) is a typical solution. The data is encrypted at rest. Your application decrypts the payload locally and then can operate on the plaintext as it sees fit.
Your scenario involves encryption of data at rest, such as connection strings being read from a config file? SecureString never helped with those scenarios; it only ever worked on ephemeral data.
This may be technically true - in that when creating (for example) a PowerShell credential object it uses a secure string, but when we export that credential (e.g. get-credential | export-clixml cred.xml) the data is a long series of digits printed to a text file (not technically a secure string). That gets turned back into a secure string, and back into a credential. In that sense SecureString is pivotal to a process of securing keys and passwords at rest.
With a certificate the problem is merely moved. Whatever has the private key can authenticate. So now instead of having to keep a password or API key secure, the need is to keep the Private Key both secure secure at rest, AND available transparently.
So now instead of having to keep a password or API key secure, the need is to keep the Private Key both secure secure at rest, AND available transparently.
Certificate private keys can be marked non-exportable. As long as the cert is in the personal or machine store, the calling process never has access to the raw private key material. That's why using certs is so popular especially in headless environments like production servers. For consumer environments, DPAPI offers a similar capability.
Activity
blowdart commentedon Aug 18, 2019
@jozefizso You thumbed down this idea, so I'm assuming you use securestring right now. Is there any chance you could expand on your objection here?
jozefizso commentedon Aug 18, 2019
Yes, for example the
PasswordBoxcontrol returns password asSecureString. This prevents the password from being written out to log files and it’s required to work with some native Win32 authentication API.The same way you can remove MD5 hash algorithm from .NET because people are using it to insecurely store passwords.
blowdart commentedon Aug 18, 2019
You've got about the only good example of using it right, powershell passwords being the other. MD5 at least as more legitimate uses (and is baked into the HTTP standard. Heck we can't remove 3DES because it's part of EMV).
If it was moved out of corefx and into a separate, unsuipported package, where eventually a lot of bad decisions will go and which would have a horrific name like Microsoft.Unsupported.UnsafeThings (this is why no-one lets me name stuff), where you could opt into using it, and would have to put an extra flag in your solution to maybe make people think some more, would that be helpful?
GrabYourPitchforks commentedon Aug 18, 2019
FYI I'm not suggesting deleting the type, only obsoleting it.
Jozef, who is the adversary in your scenarios threat model? How does the use of SecureString in this particular scenario thwart the adversary?
Edit: I ask not to be argumentative, but because there might exist an opportunity to create a better type for your scenario. We might be able to craft something more narrow in scope than what SecureString was trying to accomplish, and perhaps that replacement would be better suited for your application.
SteveL-MSFT commentedon Aug 18, 2019
In addition to logging, PowerShell also relies on this type to determine when to prompt without echo. Would it make sense to have a
SensitiveStringtype that would also zero out memory on dispose? At least this would set some expectation, and maybe allow migration over time.jozefizso commentedon Aug 18, 2019
SecureStringhas it's obvious usages in the WinForms, WPF and PowerShell API.Without providing any replacement nor information how to do it right and what will you do to make existing workflows like asking for passwords in console apps, password boxes, etc. and preventing passwords from leaking in places like loggin it does make sense to delete a class from .NET Framwork.
Having such a needed class in unsupported library? Ehm, no, just no.
blowdart commentedon Aug 18, 2019
Part of the point of the issue is to gather feedback on what you use it for, however "obvious" uses doesn't help us very much. We want to know
We don't want to let our own biases make assumptions, we want you to be explicit please.
yuhong commentedon Aug 18, 2019
On crash dumps: https://devblogs.microsoft.com/oldnewthing/20161104-00/?p=94645
GrabYourPitchforks commentedon Aug 18, 2019
Related issue: GC support for zeroing the managed heap on compaction (https://github.com/dotnet/coreclr/issues/18386). The premise of that work item is to limit exposure of sensitive data in memory, regardless of whether it's in a string, array, or some other type.
blowdart commentedon Aug 19, 2019
@jozefizso I admit I am a little confused when you mention Win32. Windows has no idea about securestrings, they're purely a .NET concept. Which APIs are you thinking of here?
jozefizso commentedon Aug 20, 2019
Here it is: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.marshal.securestringtoglobalallocunicode
bartonjs commentedon Aug 20, 2019
@jozefizso That's not a Win32 method, that's the marshaller method for how to pass a SecureString to a C function that takes
wchar*. (Decrypt it, pass the pointer to where it's decrypted) Whatever Win32 functions are being called could work just as well withSystem.String, orchar[].stevenwdv commentedon Aug 21, 2019
I'm not a professional developer yet, so I don't know if my opinion counts, but it seems weird to me that this would be obsoleted. Aren't there still benefits in using this? If you're careful you can make sure that the string has a short, predetermined, lifetime.
But maybe I'm missing something: 'obsoleted' means that it is no longer needed because there is a better alternative, right? Can you tell me what this alternative would be? (For cases where we request a password from the user.) It seems to me that using a normal string would not be better, so I guess this is not what you mean.
bartonjs commentedon Aug 21, 2019
SecureString, on Windows, is useful if:
wchar*(aka C#char*) in theSecureString(char*, int)constructor.char*from the Marshaller output).Effectively, if you've ever had the value in a
System.Stringinstance then you've lost all the "value" SecureString offers.It depends on your threat model / risk concern:
System.Stringin a struct with noToStringdefined (orpublic override string ToString() => "** REDACTED **";System.String, and upvote https://github.com/dotnet/coreclr/issues/18386.System.String.It is. Just use
System.String. Statistically speaking, you already had the value in aSystem.String(via a web request, or File.ReadAllText, or whatever), or you're at some point going to write a method likeSecureStringToString, and now you've just warmed up your CPU for no real benefit.So long as you never copied the data into
byte[],char[], orSystem.String, sure. Most people aren't careful.We actually docs-deprecated it more than 2 years ago: https://github.com/dotnet/platform-compat/blob/master/docs/DE0001.md, with a big warning on MSDN/docs.microsoft.com (https://docs.microsoft.com/en-us/dotnet/api/system.security.securestring?view=netframework-4.8)
Now we're just moving it to a compile warning so more people notice.
6 remaining items
sterenas commentedon Apr 19, 2020
Very interesting discussion around SecureString. We've got some services that connect to Azure SQL DB from a WinForms app (No ASP.NET). Need to encrypt the ConnectionString's password (this password is not typed, by an user, it's hardcoded in the ConnectionString itself). I'm not able to use Azure's AKS as I'd still need to hardcode at least one secret. Would you recommend SecureString or any other approach to get this done securely? Thanks!
GrabYourPitchforks commentedon Apr 19, 2020
@sterenas Your scenario involves encryption of data at rest, such as connection strings being read from a config file?
SecureStringnever helped with those scenarios; it only ever worked on ephemeral data.If you've got persisted data you need to encrypt on the local box, using X.509 certificates (for server farms) or DPAPI (for consumer machines) is a typical solution. The data is encrypted at rest. Your application decrypts the payload locally and then can operate on the plaintext as it sees fit.
jhoneill commentedon Apr 19, 2020
This may be technically true - in that when creating (for example) a PowerShell credential object it uses a secure string, but when we export that credential (e.g.
get-credential | export-clixml cred.xml) the data is a long series of digits printed to a text file (not technically a secure string). That gets turned back into a secure string, and back into a credential. In that senseSecureStringis pivotal to a process of securing keys and passwords at rest.With a certificate the problem is merely moved. Whatever has the private key can authenticate. So now instead of having to keep a password or API key secure, the need is to keep the Private Key both secure secure at rest, AND available transparently.
GrabYourPitchforks commentedon Apr 19, 2020
Certificate private keys can be marked non-exportable. As long as the cert is in the personal or machine store, the calling process never has access to the raw private key material. That's why using certs is so popular especially in headless environments like production servers. For consumer environments, DPAPI offers a similar capability.
GrabYourPitchforks commentedon Jul 23, 2020
Video
Updated proposal at dotnet/designs#147.