Secret management keeps database passwords and connection strings out of source code. Store them securely using a key vault or environment variables instead. section 8.7.3
Committing credentials in configuration files exposes them to anyone with repository access. It also makes rotation difficult: the unsafe setup may require a full code deployment to change credentials. section 11.5
Listing 11.1 The Hardcoded Disaster
import psycopg2
def get_db_connection():
conn = psycopg2.connect( #A
host="prod-db.internal.castle.com",
database="orders_db",
user="admin", #B
password="Password123!" #C
)
return conn
This Python example hardcodes an admin username and password in a database connection—the kind of setup to avoid. section 11.5







