Access credentials, such as passwords and access keys, should not be hardcoded in source code. Hardcoding credentials may cause leaks even after removing them. This is because version control systems might retain older versions of the code. Credentials should be stored securely and obtained from the runtime environment.
1function nonCompliant() {
2 // NonCompliant: Stored passwords directly in the code statement
3 $password = "3xAmpl3";
4 return KeyOrPassword::createFromPassword($password);
5}
1function compliant() {
2 // Compliant: Access sensitive information like passwords directly from environment variables
3 $password = $_ENV["SECRET"];
4 return KeyOrPassword::createFromPassword($password);
5}