1

What is the best way to protect sensitive text input and store it in memory until form submission is complete and then clear it out shortly thereafter?

I'm looking to protect sensitive information such as patient information and login credentials while being submitted on page in iOS, Android and Windows Phone via a cryptographic method. I need to call an API and check with the server if the information is correct, and if not, ask for re-entry, without having to lose all other valid information.

I do not want plaintext data to linger/persist if user doesn't fully complete the submission form or if data is inadvertently written to page files.

2
  • 1
    At least Windows should offer methods to enforce that data blocks remain in RAM. Additionally there should be user based encryption solutions on all if these platforms (I think) such as DPAPI.
    – SEJPM
    Commented Mar 19, 2016 at 17:38
  • If you are specifically worried about being written to disk, on Linux you can use mlock() or mlockall(), which locks memory to RAM and prevents it from being swapped out.
    – forest
    Commented Apr 4, 2016 at 3:57

2 Answers 2

1

If you are working in a language which gives you access to the memory locations of the strings being entered, you could overwrite the sensitive information with null bytes when the user leaves the page/stops entering input for a certain amount of time.

0

I assume you're working in Java since you tagged the question with "Android".

If you're really afraid that your memory might be snooped, you're pretty much dead in the water if you're going up against someone with a decent level of sophistication. But there are a few "security through obscurity" techniques that might protect you against a casual snoop.

To start with, sensitive data should be stored in Character[] array and not in String. Once you've used it, you "burn" it by overwriting with zeros and then freeing. This is standard best practices and you should always do this.

You could try "encrypting" the data while it's stored in memory. The simplest way is to XOR it with a long pseudo-random string of bytes. This will make it unintelligible to someone casually scanning through a memory dump, but once they de-compile your app, they'll likely find out what your obfuscation algorithm was and also figure out what piece of memory you used to store the sensitive data.

As another poster mentioned, you should take the trouble to make sure your memory is never swapped to long-term storage. There are system calls you can make in Linux to prevent swapping, but I think their use in Java would be ill-advised. The good news is, I don't think Android uses swap, so this won't be an issue for you.

1
  • this applies to iOS, android and Windows Phone. I'm was concerned with memory being swapped to long term storage in case other peers down the road do not handle things carefully. Seems like things are much easier with existence of a TPM to handle the cryptographic method or with use of DPAPI for Windows Phone, than in Android.
    – TJ Aodha
    Commented Mar 22, 2016 at 3:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .