fix: remove hardcoded fallback password from DB connection #84
No reviewers
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-database#84
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/remove-default-db-password"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
'sba_dev_password_2024'fallback default from PostgreSQL connection setup indb_engine.pyRuntimeErroron startup ifPOSTGRES_PASSWORDenv var is not setTest plan
POSTGRES_PASSWORDis unsetPOSTGRES_PASSWORDis setPOSTGRES_PASSWORD🤖 Generated with Claude Code
AI Code Review
Files Reviewed
app/db_engine.py(modified) — the only file changed in this PRFindings
Correctness
_postgres_password = os.environ.get("POSTGRES_PASSWORD")followed by an explicitNonecheck andRuntimeErroris the right pattern — it causes a fast, loud failure at startup rather than a silent connection failure or an attempt to connect with a wrong credential.PooledPostgresqlDatabaseaspassword=_postgres_password, eliminating the fallback entirely.Security
'sba_dev_password_2024'is gone as a fallback default. This is the fix, and it is correctly implemented.RuntimeErrormessage does not leak any credential values — it states only the missing variable name, which is safe to log.Style & Conventions
_postgres_passwordprivate-convention prefix is a clear signal that this is a module-level intermediate value not for external use, appropriate here.app/dependencies.pyand other active files in the project.main.py,db_engine.pyare legacy, not in use." This refers specifically to the root-level legacy files, notapp/db_engine.py. The changed file (app/db_engine.py) is actively imported by every router underapp/routers_v3/and is very much in production use. The fix targets the correct, live file.Suggestions (non-blocking)
docker-compose.ymlalready passesPOSTGRES_PASSWORD=${SBA_DB_USER_PASSWORD}to both the Postgres and API containers, so existing deployments are not broken by this change. The PR test plan item to verify dev and prod compose files is already satisfied.RuntimeErroris raised whenDATABASE_TYPE=postgresqlandPOSTGRES_PASSWORDis absent would prevent regression, but its absence is not a blocker.Verdict: APPROVED (posted as COMMENT — self-review restriction)
The security fix is correct, targeted, and safe. The hardcoded fallback credential is gone, the error path is explicit and informative, and no regressions were introduced by the cosmetic cleanup. Ready to merge.
Automated review by Claude PR Reviewer
AI Code Review
Files Reviewed
app/db_engine.py(modified)Findings
Correctness
_postgres_passwordcheck runs at module import time inside theif DATABASE_TYPE.lower() == "postgresql":block, so theRuntimeErrorfires before any routes become available. Fail-fast behaviour is correct.Security
'sba_dev_password_2024'is removed. No credentials remain in the changed code.password=None, which deferred failure to connection time).RuntimeErrorat startup is better UX and avoids a potential silent misconfiguration window.Style & Conventions
_postgres_password(leading underscore, module-level) is a reasonable naming convention for a transient intermediate value that doesn't need to be exported.Edge Cases
POSTGRES_PASSWORD=""(empty string):os.environ.get("POSTGRES_PASSWORD")returns"", which is notNone, so the guard passes and an empty password is forwarded toPooledPostgresqlDatabase. This would fail at connection time with a less clear error. However, an empty password is an unlikely misconfiguration, and guarding against it (e.g.if not _postgres_password) is arguably over-engineering for this fix. Not blocking.Suggestions
Verdict: APPROVED
Clean, correct implementation. Removes the hardcoded credential and provides a clear startup-time error with a meaningful message. Strictly better than the
None-passthrough approach. No issues found.Automated review by Claude PR Reviewer
Security fix verified — hardcoded fallback password removed, RuntimeError on missing env var, docker-compose already wires the variable. Clean and ready to merge.
Re-approving after whitelist update.