-
-
Notifications
You must be signed in to change notification settings - Fork 17
fix(cli): redact credentials from database URL console logs #626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fe799ee
d1b7149
36ee595
e9537a7
501ab33
6cba59c
6643175
69cf57e
2b85025
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,22 @@ function evaluateUrl(value: string): string { | |
| } | ||
| } | ||
|
|
||
| function redactDatabaseUrl(url: string): string { | ||
| try { | ||
| const parsedUrl = new URL(url); | ||
| if (parsedUrl.password) { | ||
| parsedUrl.password = '***'; | ||
| } | ||
| if (parsedUrl.username) { | ||
| parsedUrl.username = '***'; | ||
| } | ||
| return parsedUrl.toString(); | ||
| } catch { | ||
| // If URL parsing fails, return the original | ||
| return url; | ||
ymc9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| function createDialect(provider: string, databaseUrl: string, outputPath: string) { | ||
| switch (provider) { | ||
| case 'sqlite': { | ||
|
|
@@ -125,15 +141,15 @@ function createDialect(provider: string, databaseUrl: string, outputPath: string | |
| }); | ||
| } | ||
| case 'postgresql': | ||
| console.log(colors.gray(`Connecting to PostgreSQL database at: ${databaseUrl}`)); | ||
| console.log(colors.gray(`Connecting to PostgreSQL database at: ${redactDatabaseUrl(databaseUrl)}`)); | ||
| return new PostgresDialect({ | ||
| pool: new PgPool({ | ||
| connectionString: databaseUrl, | ||
| }), | ||
| }); | ||
|
|
||
| case 'mysql': | ||
| console.log(colors.gray(`Connecting to MySQL database at: ${databaseUrl}`)); | ||
| console.log(colors.gray(`Connecting to MySQL database at: ${redactDatabaseUrl(databaseUrl)}`)); | ||
|
Comment on lines
+144
to
+152
|
||
| return new MysqlDialect({ | ||
| pool: createMysqlPool(databaseUrl), | ||
| }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.