@@ -70,8 +70,8 @@ func GetPoolerConfig(projectRef string) *pgconn.Config {
70
70
return nil
71
71
}
72
72
// There is a risk of MITM attack if we simply trust the hostname specified in pooler URL.
73
- if ! isSupabaseDomain (poolerConfig .Host ) {
74
- fmt .Fprintln (logger , "Pooler hostname does not belong to Supabase domain :" , poolerConfig .Host )
73
+ if ! strings . HasSuffix (poolerConfig .Host , "." + CurrentProfile . ProjectHost ) {
74
+ fmt .Fprintln (logger , "Pooler hostname does not belong to current profile :" , poolerConfig .Host )
75
75
return nil
76
76
}
77
77
fmt .Fprintln (logger , "Using connection pooler:" , Config .Db .Pooler .ConnectionString )
@@ -92,15 +92,6 @@ func ParsePoolerURL(connString string) (*pgconn.Config, error) {
92
92
return poolerConfig , nil
93
93
}
94
94
95
- func isSupabaseDomain (host string ) bool {
96
- switch GetSupabaseAPIHost () {
97
- case "https://api.supabase.green" :
98
- return strings .HasSuffix (host , ".supabase.green" )
99
- default :
100
- return strings .HasSuffix (host , ".supabase.com" )
101
- }
102
- }
103
-
104
95
// Connnect to local Postgres with optimised settings. The caller is responsible for closing the connection returned.
105
96
func ConnectLocalPostgres (ctx context.Context , config pgconn.Config , options ... func (* pgx.ConnConfig )) (* pgx.Conn , error ) {
106
97
if len (config .Host ) == 0 {
@@ -121,13 +112,29 @@ func ConnectLocalPostgres(ctx context.Context, config pgconn.Config, options ...
121
112
if config .ConnectTimeout == 0 {
122
113
config .ConnectTimeout = 2 * time .Second
123
114
}
115
+ options = append (options , func (cc * pgx.ConnConfig ) {
116
+ cc .TLSConfig = nil
117
+ })
124
118
return ConnectByUrl (ctx , ToPostgresURL (config ), options ... )
125
119
}
126
120
127
121
func ConnectByUrl (ctx context.Context , url string , options ... func (* pgx.ConnConfig )) (* pgx.Conn , error ) {
128
122
if viper .GetBool ("DEBUG" ) {
129
123
options = append (options , debug .SetupPGX )
130
124
}
125
+ // No fallback from TLS to unsecure connection
126
+ options = append (options , func (cc * pgx.ConnConfig ) {
127
+ if cc .TLSConfig == nil {
128
+ return
129
+ }
130
+ var fallbacks []* pgconn.FallbackConfig
131
+ for _ , fc := range cc .Fallbacks {
132
+ if fc .TLSConfig != nil {
133
+ fallbacks = append (fallbacks , fc )
134
+ }
135
+ }
136
+ cc .Fallbacks = fallbacks
137
+ })
131
138
return pgxv5 .Connect (ctx , url , options ... )
132
139
}
133
140
0 commit comments