Domain Empire

Is it safe to keep a plain text password retrieved from a password vault(CyberArk) in memory in a Java application?

Spaceship Spaceship
Watch

ravikumar321

New Member
Impact
0
I have an application that has an image upload feature, the images are stored on a 3rd party service which is basically an SFTP server. The credentials for accessing this storage were initially hard-coded in the java service class itself, and to secure it, I am planning to keep the SFTP server credentials in a password vault(CyberArk) and then retrieve the credential programmatically (when the application starts up) using the cyberArk REST API and certificate auth method. After retrieving the credentials from the vault, I plan to keep the password in memory and use it for subsequent communication with the SFTP server. Is this the correct approach? Or will this still be a security risk?

Note1: this is a Java Struts2 application and deployed as a war on JBoss server.

Note2: I read in some places that its safer to use char array instead of a string to store a password, but not sure if that is enough.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
I asked ChatGPT which they stated the following:

Your approach of storing the SFTP server credentials in a secure password vault like CyberArk and retrieving them programmatically is certainly an improvement over having the credentials hard-coded in your Java service class. Using a password vault like CyberArk mitigates the risk of the credentials being compromised if your code is ever exposed. Furthermore, by using the CyberArk REST API and certificate authentication method, you're adding an additional layer of security.

Keeping the password in memory and using it for subsequent communication with the SFTP server is a common approach. However, it's essential to understand that it still poses some risk. If an attacker gains access to the memory of the server where the application is running, they could potentially read the password. Although this is a more difficult attack vector to exploit, it's still a possibility. Additionally, if the application crashes and produces a core dump, the contents of the memory including the password could be written to disk.

You're correct in your note about storing passwords in a char array instead of a String. In Java, Strings are immutable and are stored in the String pool, meaning they can't be programmatically erased from memory and will remain in memory until being garbage collected, which may not occur until much later. On the other hand, a char array can be manually wiped from memory after use by setting all its elements to zero. This reduces the window of time in which a memory dump could potentially expose the password.

However, the above practice of using a char array is mainly beneficial when dealing with the password in your own code. If the library you use to connect to the SFTP server requires a String for the password, then at some point your password will end up in a String object, and the benefits of storing it as a char array are largely nullified.

To further enhance security, you may want to consider the following:

1. **Rotate Credentials Regularly:** Even with all the precautions, if the credentials somehow get compromised, regularly rotating them can limit the damage. You can set up automatic rotation policies in CyberArk itself.

2. **Least Privilege Principle:** Ensure that the account used by the application has the least privileges needed to perform its tasks. This way, even if the credentials are compromised, the potential damage will be limited.

3. **Monitor and Audit Access:** Regularly monitor and audit access to both CyberArk and the SFTP server to detect any suspicious activities early.

4. **Secure Your Application and Server:** Ensure that your application and server are secure. This includes regular patching, following secure coding practices, and other best practices for securing your server.

5. **Encryption:** If possible, encrypt the data before sending it to the SFTP server. This way, even if an attacker manages to compromise the SFTP server, they would not be able to read the data without the encryption key.

6. **Use of HSMs or Secure Enclaves:** If your environment allows, consider using Hardware Security Modules (HSMs) or Secure Enclaves for handling encryption keys and other sensitive data in a more secure manner. These provide hardware-level security and are designed to resist tampering and protect the data they handle even in the event of a system compromise.

Remember, no system is perfectly secure, and the aim is to make it as difficult as possible for potential attackers.

Hope this helps.
 
Last edited:
11
•••
Upvote 0
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back