File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
backend/internal/features
backups/backups/usecases/postgresql
restores/usecases/postgresql Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -719,11 +719,18 @@ 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 )
728+
722729 pgpassContent := fmt .Sprintf ("%s:%d:*:%s:%s" ,
723730 pgConfig .Host ,
724731 pgConfig .Port ,
725732 pgConfig .Username ,
726- password ,
733+ escapedPassword ,
727734 )
728735
729736 tempDir , err := os .MkdirTemp ("" , "pgpass" )
Original file line number Diff line number Diff line change @@ -564,11 +564,18 @@ 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 )
573+
567574 pgpassContent := fmt .Sprintf ("%s:%d:*:%s:%s" ,
568575 pgConfig .Host ,
569576 pgConfig .Port ,
570577 pgConfig .Username ,
571- password ,
578+ escapedPassword ,
572579 )
573580
574581 tempDir , err := os .MkdirTemp ("" , "pgpass" )
You can’t perform that action at this time.
0 commit comments