English 中文(简体)
Caching plaintext passwords in memory of WCF service
原标题:

This probably sounds like a terrible idea at first glance, but here is my scenario: I have a Windows service that exposes several WCF endpoints using Username authentication. The custom authenticator will either look up the user s credentials in a local database (password is stored as salted SHA-1), or it will make a WCF request to another service to validate the password. (There is an enum on the User object that can be Internal or External, indicating which authentication source to use).

I m finding that performing either the lookup+hash check or making the WCF call is expensive to do on every single request to my service, so I would like to cache username/password information. Each item in the cache would have a lifetime, so for instance if the item in the cache is 60 seconds old, upon the next request the authenticator will verify the credentials against the original source instead of the cache, and then update it.

For the local database, I could simply store the username/SHA1 pair in a Dictionary, and on each request from an "Internal" user I would just have to re-hash the supplied password and compare it. For an "External" user, I would only have the plaintext password submitted to the authenticator, so it would be up to me to hash it and store it as part of the cache. Although this certainly saves me the overhead of a database request or a remote service call, I still have to perform the hash operation each time.

The service in question will run on an internal server with good physical as well as network security. Is it an acceptable practice to store the plaintext password in the cache instead of storing a hashed version? In that case my risk seems to be an attacker dumping the memory of the process and getting the passwords. If I consider that risk acceptable, is there any other reason I should avoid having the plaintext passwords in memory?

If I opt to use plaintext passwords, I think that SecureString could limit my risk to an extent. Is it worth the trouble to use SecureString (implementing it seems very roundabout)? I am well aware of the risk of persistently storing passwords un-hashed, however I m not sure what the consensus seems to be on volatile storage of plaintext passwords.

最佳回答

SecureString uses encrypted memory, so this would likely improve performance over doing the hashing yourself each time. But you would have to profile it in your environment.

As to the risk of storing plain passwords in memory, that is not a question which can be answered in this context. I could just say, yes its OK. Because it is for my situation, for various reasons. But that wouldn t be the same as yours.

Here is what I suggest: Consider the ramifications of the passwords leaking -- basically how much would it be worth ($ or $$$?) to a hacker to possess a password? Most security problems these days come from a financial incentive. Relatively speaking, pure vandalism is outclassed by these guys.

Now compare that to the possibility that the security could be compromised in a totally different manner, i.e. SQL Injection or telephoning a user to "Verify their account". If the $ value of a couple of passwords is high and there is no other way to obtain them, then perhaps you should keep encrypting them (and now you have justified the cost of a more powerful server!). And make sure you then secure the crypto keys -- once a hacker has your server, those keys are likely as easy to access as program memory.

On the other hand, if the value is low and there are other possible exploits readily available (and there often are), you could make a reasonable argument that it isn t worth the hacker s time to compromise the server and dump the memory.

Good luck.

问题回答

The service in question will run on an internal server with good physical as well as network security.

As long as that is true from now till eternity (or the next patch, which ever comes first) storing a cached password in ram as plain-text is fine. If you where storing the entire password DB in ram (say your persistent storage is too slow) I think storing them as secure strings would be better, but since you are only storing a few passwords for at most 1 minute, I see no problem.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签