Hard-coded credentials

Hard-coded credentials

Description

Storing passwords, client secrets or API keys directly in source code may allow immediate misuse if the code is exposed.

Potential impact

Service accounts may be compromised, APIs misused, or additional permissions obtained.

Remediation

Protect secrets in a store such as Secret Manager and supply them through runtime environment variables when appropriate. Revoke exposed values, issue replacements and update the applications that use them.

Examples

Before

php
<?php
$client_secret = "ABigLongSecret";

After

php
<?php
$client_secret = getenv('CLIENT_SECRET');

The code reads CLIENT_SECRET from the runtime environment. Have the application stop at startup if the value is missing or empty. Restrict access to the environment variable, its delivery mechanism, and any configuration dumps.

References