-
Notifications
You must be signed in to change notification settings - Fork 90
SecureString Thread-locale cache #70
Comments
I'm torn. While I do want bullet proof code, the intent of this class is that it be mostly immutable - except for when we are done using it. When we are done analyzing it, passwords should be cleared out and no longer in memory. At that point passfault should be done using an instance of this object - so thread safety shouldn't be a concern. So I'd hate to slow down access to SecureString by making it thread-safe. On copying the array, that's a great point. In fact I bet I do that same thing in the servlet code. Yep, here it is: https://github.com/OWASP/passfault/blob/master/jsonService/src/main/java/org/owasp/passfault/web/PassfaultServlet.java Nice find! |
If you use read-write locks, the access penalty shouldn't be noticable. Maybe you find a better way to prevent thread-local caching and optimization, which is the actual goal (wolatile?). Btw. I was also told, that filling the array with |
Only synchronizing
But that would require allocating a new array, or you have an array constant containing only Side note: There is also the |
Looking at the SecureString implementation, wouldn't it be better to put a synchronized block on the chars-array around the
Arrays.fill
call?E.g.
=> This would give assurance, that the JVM doesn't optimize anything around fill and prevent thread-local caching (as per this thread)
Actually you could make this class thread-safe while at it, with read-locks for all other methods and write-lock for the clear().
Additionally it's not clear, that the class creates a copy of the input char-array. It's likely users forget to clear their input "manually" after creating an instance.
If you want I can make a PR.
The text was updated successfully, but these errors were encountered: