How to handle Passwords Securely in Source Code

The use of plaintext passwords in source code is unsafe and should be avoided from an Security IT point of view. Unfortunately, this is a common practice.

Keep in mind that in case you are using a code repository with version control the plaintext is story in current and history versions of the source code.

Best Practices to handle Passwords securely in source

The following situations should be handled:

  • Use password securely in current branch
  • Remove plaintext password vulnerability in version history

Handle Credentials securely in current Branch

There are different ways to handle credentials in current branch:

  • Store the credentials in a configuration file that is not pushed to the code repository
  • Store the credentials in a database
  • Use a cloud provider service for managing secrets
  • Leveraging environment variables

A key management system like password manager, credential vault or hardware security module (HSM), should be used to store the passwords, instead of having it as cleartext.

The main different between a password manager and HSM is that the first is software-based and focused on availability the second is hardware-based and focused on confidentiality.

Password managers and HSM usually use authentication methods such as API keys, OAuth tokens, or other authentication tokens.

Remove plaintext Password vulnerability in Version History

Ways to remove plaintext password vulnerability in version history.

  • Delete all historical branches with the password

Delete all historical branches with the password is not safe enough because code may have been already seen.

Password Management by Programming Language

Passwords should be managed in a different way depending on the programming language.

Indications about how to manage password safely based on programming language:

You might also be interested in…

Leave a Reply

Your email address will not be published. Required fields are marked *