fix: percent-encode credentials when building DATABASE_URL (#126)#167
Conversation
…#126) When DATABASE_URL is not provided, entrypoint.sh assembled it by interpolating POSTGRES_USER, POSTGRES_PASSWORD and POSTGRES_DB directly into a postgres:// URL. Any reserved URL character in those values (for example a '#', '/' or '?' in the password) produced an invalid URL, and pg-connection-string's new URL() call then threw ERR_INVALID_URL, preventing the container from starting. Percent-encode the user, password and database components via encodeURIComponent before building the URL so passwords containing special characters work without manual escaping.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe entrypoint script now builds the PostgreSQL connection string by percent-encoding username, password, and database name components using a new ChangesDatabase URL Encoding
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
Looks good to me. Clean fix and I don't see any issues here. Approving! |
|
🎉 This PR is included in version 1.8.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Before you submit
What does this PR do?
When
DATABASE_URLis not explicitly set,server/entrypoint.shbuildsit by interpolating
POSTGRES_USER,POSTGRES_PASSWORD, andPOSTGRES_DBraw into a
postgres://URL. Any reserved URL character in the password(
#,/,?,@,:, space) corrupts the string — a#in particularturns everything after it into a URL fragment — so
pg-connection-string'snew URL()throwsERR_INVALID_URLand the container crashes duringrunMigrationsbefore it can boot.This adds a small
urlencode()helper that pipes each credential componentthrough
node -e 'encodeURIComponent(...)'before assembling the URL. Hostand port are intentionally left unencoded.
Fixes #126
How did you test this?
Reproduced the failure with node directly: building the URL the old way with
a password containing
#and callingnew URL()throwsERR_INVALID_URL.With the encoded form it parses cleanly, the host/port/db fields are intact,
and
decodeURIComponentreturns the original plaintext — so Postgres receivesthe correct password. Also ran
sh -n server/entrypoint.shto confirm nosyntax errors, and verified the helper handles empty values correctly
(encoding to empty, preserving the existing default-fallback behaviour).
Screenshots
N/A — no UI changes.
Anything non-obvious in the diff?
urlencode()shells out tonode -e 'encodeURIComponent(...)'rather thana pure-shell loop. This is intentional: node is always available here (the
runtime is
node:alpineand the very next lines runnode dist/scripts/migrate.jsand
node dist/main.js), andencodeURIComponentgives a fully-correctRFC 3986 encoder with no edge cases to hand-roll.
Checklist
sh -nclean; repo has no shell test suite).env, personal configs)Summary by CodeRabbit