CWE-321 (hard-coded cryptographic key) covers key reuse across environments as much as literal key embedding: when dev and prod share an encryption key, a developer database compromise — a much lower-bar attacker target — exposes the key that also decrypts production data. NIST SC-12 requires that key management procedures account for environment lifecycle boundaries. Cross-environment key sharing also violates the broader key-management lifecycle expectations in PCI-DSS v4.0 Requirement 3.7 — dev/prod key separation is the only way trust boundaries remain meaningful under those procedures. Environment-specific keys constrain the blast radius of a dev credential compromise to the dev environment only.
Low because exploiting shared keys requires developer credential access in addition to database access, but the control gap converts a dev breach into a prod data exposure.
Use environment-specific KMS key IDs for each environment, managed through environment variables that differ per deployment target. In your deployment pipeline:
// src/lib/kms.ts — environment key selection at init time
const KMS_KEY_ID = (() => {
const env = process.env.NODE_ENV;
if (env === 'production') return process.env.AWS_KMS_KEY_ID_PROD!;
if (env === 'test') return process.env.AWS_KMS_KEY_ID_TEST!;
return process.env.AWS_KMS_KEY_ID_DEV!;
})();
if (!KMS_KEY_ID) throw new Error('KMS_KEY_ID not configured for environment');
In CI/CD, store AWS_KMS_KEY_ID_PROD, AWS_KMS_KEY_ID_STAGING, and AWS_KMS_KEY_ID_DEV as separate secrets in your CI secrets manager (GitHub Actions, Vercel Environment Variables). Add a pre-deploy assertion that the key ID matches the expected ARN prefix for the target environment — fail the deploy if they don't match.
finserv-encryption.pci-alignment.environment-specific-keyslow"1 KMS key found across all environments — dev and prod share AWS_KMS_KEY_ID" or "0 environment distinction: same ENCRYPTION_KEY in .env.development and .env.production"// Use environment-specific KMS keys
const kmsKeyId = process.env.NODE_ENV === 'production'
? process.env.AWS_KMS_KEY_ID_PROD
: process.env.AWS_KMS_KEY_ID_DEV;
# Vault paths per environment
vault kv get secret/prod/encryption-key
vault kv get secret/staging/encryption-key
vault kv get secret/dev/encryption-key
# Pre-deployment check
if [ "$ENVIRONMENT" == "prod" ] && [ "$AWS_KMS_KEY_ID" != "$AWS_KMS_KEY_ID_PROD" ]; then
echo "ERROR: Production must use prod KMS key"
exit 1
fi