-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
Description
Bug Description
PgConnectionOptions
tries to get the password from the pgpass file when the struct is created, but the caller can then use the builder API to change options that affect which password is taken from the file, so we can end up with the wrong password.
sqlx/sqlx-postgres/src/options/mod.rs
Lines 136 to 138 in 7e7dded
pub fn new() -> Self { | |
Self::new_without_pgpass().apply_pgpass() | |
} |
sqlx/sqlx-postgres/src/options/mod.rs
Lines 174 to 185 in 7e7dded
pub(crate) fn apply_pgpass(mut self) -> Self { | |
if self.password.is_none() { | |
self.password = pgpass::load_password( | |
&self.host, | |
self.port, | |
&self.username, | |
self.database.as_deref(), | |
); | |
} | |
self | |
} |
For example, we can select a different host here and it will not read the pgpass file again (and even if it did, it might already have gotten the wrong password and would not change it):
sqlx/sqlx-postgres/src/options/mod.rs
Lines 203 to 206 in 7e7dded
pub fn host(mut self, host: &str) -> Self { | |
self.host = host.to_owned(); | |
self | |
} |
Info
- SQLx version: 0.7.1
- SQLx features enabled: postgres
- Database server and version: Postgres