Skip to content

Commit a368e34

Browse files
authored
fix: support special characters in db urls (NangoHQ#2575)
This commit URL encodes db username and password when used inside postgres db url If db urls are set as env vars, users must URL encode them if they contain any special char ## Checklist before requesting a review (skip if just adding/editing APIs & templates) - [ ] I added tests, otherwise the reason is: - [ ] I added observability, otherwise the reason is: - [ ] I added analytics, otherwise the reason is:
1 parent 12d7342 commit a368e34

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

docs-v2/host/self-host/self-hosting-instructions.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Records saved by syncs can be persisted in a dedicated database. If you opt in f
5151
```
5252
RECORDS_DATABASE_URL=postgresql://user:password@host:port/dbname
5353
```
54+
Special characters in the RECORDS_DATABASE_URL should be URL encoded.
5455
If not specified, the records will be stored in the main database.
5556

5657
<Tip>

packages/orchestrator/lib/app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const databaseSchema = envs.ORCHESTRATOR_DATABASE_SCHEMA;
1212
const databaseUrl =
1313
envs.ORCHESTRATOR_DATABASE_URL ||
1414
envs.NANGO_DATABASE_URL ||
15-
`postgres://${envs.NANGO_DB_USER}:${envs.NANGO_DB_PASSWORD}@${envs.NANGO_DB_HOST}:${envs.NANGO_DB_PORT}/${envs.NANGO_DB_NAME}`;
15+
`postgres://${encodeURIComponent(envs.NANGO_DB_USER)}:${encodeURIComponent(envs.NANGO_DB_PASSWORD)}@${envs.NANGO_DB_HOST}:${envs.NANGO_DB_PORT}/${envs.NANGO_DB_NAME}`;
1616

1717
try {
1818
const dbClient = new DatabaseClient({ url: databaseUrl, schema: databaseSchema });

packages/records/lib/db/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const schema = envs.RECORDS_DATABASE_SCHEMA;
55
const databaseUrl =
66
envs.RECORDS_DATABASE_URL ||
77
envs.NANGO_DATABASE_URL ||
8-
`postgres://${envs.NANGO_DB_USER}:${envs.NANGO_DB_PASSWORD}@${envs.NANGO_DB_HOST}:${envs.NANGO_DB_PORT}/${envs.NANGO_DB_NAME}`;
8+
`postgres://${encodeURIComponent(envs.NANGO_DB_USER)}:${encodeURIComponent(envs.NANGO_DB_PASSWORD)}@${envs.NANGO_DB_HOST}:${envs.NANGO_DB_PORT}/${envs.NANGO_DB_NAME}`;
99
const runningMigrationOnly = process.argv.some((v) => v === 'migrate:latest');
1010
const isJS = !runningMigrationOnly;
1111

0 commit comments

Comments
 (0)