File tree Expand file tree Collapse file tree 4 files changed +31
-16
lines changed
backups/backups/usecases/postgresql
restores/usecases/postgresql
frontend/src/shared/theme Expand file tree Collapse file tree 4 files changed +31
-16
lines changed Original file line number Diff line number Diff line change @@ -719,17 +719,14 @@ func (uc *CreatePostgresqlBackupUsecase) createTempPgpassFile(
719719 return "" , nil
720720 }
721721
722- // Escape special characters in password as per PostgreSQL .pgpass format
723- // Per official PostgreSQL documentation: only backslash and colon need escaping
724- escapedPassword := strings .NewReplacer (
725- "\\ " , "\\ \\ " ,
726- ":" , "\\ :" ,
727- ).Replace (password )
722+ escapedHost := tools .EscapePgpassField (pgConfig .Host )
723+ escapedUsername := tools .EscapePgpassField (pgConfig .Username )
724+ escapedPassword := tools .EscapePgpassField (password )
728725
729726 pgpassContent := fmt .Sprintf ("%s:%d:*:%s:%s" ,
730- pgConfig . Host ,
727+ escapedHost ,
731728 pgConfig .Port ,
732- pgConfig . Username ,
729+ escapedUsername ,
733730 escapedPassword ,
734731 )
735732
Original file line number Diff line number Diff line change @@ -564,17 +564,14 @@ func (uc *RestorePostgresqlBackupUsecase) createTempPgpassFile(
564564 return "" , nil
565565 }
566566
567- // Escape special characters in password as per PostgreSQL .pgpass format
568- // Per official PostgreSQL documentation: only backslash and colon need escaping
569- escapedPassword := strings .NewReplacer (
570- "\\ " , "\\ \\ " ,
571- ":" , "\\ :" ,
572- ).Replace (password )
567+ escapedHost := tools .EscapePgpassField (pgConfig .Host )
568+ escapedUsername := tools .EscapePgpassField (pgConfig .Username )
569+ escapedPassword := tools .EscapePgpassField (password )
573570
574571 pgpassContent := fmt .Sprintf ("%s:%d:*:%s:%s" ,
575- pgConfig . Host ,
572+ escapedHost ,
576573 pgConfig .Port ,
577- pgConfig . Username ,
574+ escapedUsername ,
578575 escapedPassword ,
579576 )
580577
Original file line number Diff line number Diff line change 66 "os"
77 "path/filepath"
88 "runtime"
9+ "strings"
910
1011 env_utils "postgresus-backend/internal/util/env"
1112)
@@ -151,6 +152,24 @@ func VerifyPostgresesInstallation(
151152 logger .Info ("All PostgreSQL version-specific client tools verification completed successfully!" )
152153}
153154
155+ // EscapePgpassField escapes special characters in a field value for .pgpass file format.
156+ // According to PostgreSQL documentation, the .pgpass file format requires:
157+ // - Backslash (\) must be escaped as \\
158+ // - Colon (:) must be escaped as \:
159+ // Additionally, newlines and carriage returns are removed to prevent format corruption.
160+ func EscapePgpassField (field string ) string {
161+ // Remove newlines and carriage returns that would break .pgpass format
162+ field = strings .ReplaceAll (field , "\r " , "" )
163+ field = strings .ReplaceAll (field , "\n " , "" )
164+
165+ // Escape backslashes first (order matters!)
166+ // Then escape colons
167+ field = strings .ReplaceAll (field , "\\ " , "\\ \\ " )
168+ field = strings .ReplaceAll (field , ":" , "\\ :" )
169+
170+ return field
171+ }
172+
154173func getPostgresqlBasePath (
155174 version PostgresqlVersion ,
156175 envMode env_utils.EnvMode ,
Original file line number Diff line number Diff line change @@ -16,10 +16,12 @@ function getSystemTheme(): ResolvedTheme {
1616function getStoredTheme ( ) : ThemeMode {
1717 if ( typeof window !== 'undefined' ) {
1818 const stored = localStorage . getItem ( THEME_STORAGE_KEY ) ;
19+
1920 if ( stored === 'light' || stored === 'dark' || stored === 'system' ) {
2021 return stored ;
2122 }
2223 }
24+
2325 return 'system' ;
2426}
2527
You can’t perform that action at this time.
0 commit comments