Description
A key embedded in source can be recovered by anyone who can read the code, and rotating it requires a code change.
Potential impact
Depending on the key’s purpose, exposure may allow decryption of stored data or forgery of tokens or messages.
Remediation
Use separate keys for each environment and rotate them regularly. Use KMS-managed keys through the service. If the application needs the key material, supply it from a restricted secret manager.
Examples
Before
php
<?php
// Class member excerpt
private const ENCRYPTION_KEY = "Paintbrush";
After
php
<?php
$key = getenv('ENCRYPTION_KEY');
getenv('ENCRYPTION_KEY') only reads the variable. Before using the key, stop if its value is missing or malformed. Restrict access to the environment and the system that supplies it.