Commit a1eac0f
## Summary
`database_setup.py` was logging the full `DATABASE_URL` (with PG
password) on every MDR API task startup. Shared CloudWatch retention
means anyone with `logs:FilterLogEvents` could recover the dev/demo DB
credential. Closes #938.
## Fix
Small `_redact_url(url) -> str` helper using `urlparse`/`urlunparse`:
```diff
-logger.info(f"DATABASE_URL : {DATABASE_URL}")
+logger.info("DATABASE_URL : %s", _redact_url(DATABASE_URL))
```
Output before:
```
DATABASE_URL : postgresql+asyncpg://postgres:sNa22:}33eS$u:b&X_XdZu!v~4<$r.P2@devmdrdb.dev.aws:5432/devMdrDb
```
Output after:
```
DATABASE_URL : postgresql+asyncpg://postgres:***@devmdrdb.dev.aws:5432/devMdrDb
```
Helper is best-effort: any parsing surprise (malformed URL, missing env
var producing a non-integer port) returns a `<unparseable-url>` sentinel
rather than raising — a logging path should never take down MDR startup.
## Tests
First tests under `test/components/lif/mdr_utils/` (new directory):
- `_redact_url` covers typical password redaction, special characters in
the password, no-port URLs, no-password URLs (IAM auth), and unparseable
input.
- A small `conftest.py` seeds dummy `POSTGRESQL_*` env vars so importing
`database_setup` doesn't fail at engine-construction time (these
pure-Python tests never touch a real DB).
`uv run pytest test/components/lif/mdr_utils/` — 5 passed.
## Follow-up (out of scope here)
- **Rotate dev + demo DB passwords.** Previous values are sitting in
CloudWatch retention.
- **Audit other LIF services** that share this logging pattern:
`graphql_*`, `translator_*`, `advisor_api`, etc. Same pattern, same fix
shape.
Both worth filing as separate issues once this lands.
## Risk
Very low. Pure-Python helper added, single log line changed from
f-string to lazy-format with redaction. No behavior change for the
engine itself — `create_async_engine` still gets the raw `DATABASE_URL`
(it needs the credential to actually connect).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 303eb63 commit a1eac0f
4 files changed
Lines changed: 95 additions & 1 deletion
File tree
- components/lif/mdr_utils
- test/components/lif/mdr_utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
18 | 50 | | |
19 | | - | |
| 51 | + | |
20 | 52 | | |
21 | 53 | | |
22 | 54 | | |
| |||
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
0 commit comments