mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-23 01:16:30 +00:00
Dont accept empty passwords
This commit is contained in:
36
src/auth.rs
36
src/auth.rs
@@ -85,6 +85,11 @@ where
|
|||||||
|
|
||||||
let mut response = vec![0; (len - 4) as usize];
|
let mut response = vec![0; (len - 4) as usize];
|
||||||
|
|
||||||
|
// Too short to be a password (null-terminated)
|
||||||
|
if response.len() < 2 {
|
||||||
|
return Err(Error::ClientError(format!("Password response too short")));
|
||||||
|
}
|
||||||
|
|
||||||
match stream.read_exact(&mut response).await {
|
match stream.read_exact(&mut response).await {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@@ -114,10 +119,7 @@ where
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
error_response(
|
error_response(
|
||||||
stream,
|
stream,
|
||||||
&format!(
|
&format!("Pool down for database: {}, user: {}", pool_name, username,),
|
||||||
"Pool down for database: {:?}, user: {:?}",
|
|
||||||
pool_name, username,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -190,7 +192,7 @@ impl ClearText {
|
|||||||
if password != &secret {
|
if password != &secret {
|
||||||
wrong_password(write, &self.username).await?;
|
wrong_password(write, &self.username).await?;
|
||||||
Err(Error::ClientError(format!(
|
Err(Error::ClientError(format!(
|
||||||
"Invalid password {{ username: {:?}, pool_name: {:?}, application_name: {:?} }}",
|
"Invalid password {{ username: {}, pool_name: {}, application_name: {} }}",
|
||||||
self.username, self.pool_name, self.application_name
|
self.username, self.pool_name, self.application_name
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@@ -205,14 +207,14 @@ impl ClearText {
|
|||||||
error_response(
|
error_response(
|
||||||
write,
|
write,
|
||||||
&format!(
|
&format!(
|
||||||
"No server password configured for database: {:?}, user: {:?}",
|
"No server password configured for database: {}, user: {}",
|
||||||
self.pool_name, self.username
|
self.pool_name, self.username
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Err(Error::ClientError(format!(
|
Err(Error::ClientError(format!(
|
||||||
"No server password configured for {{ username: {:?}, pool_name: {:?}, application_name: {:?} }}",
|
"No server password configured for {{ username: {}, pool_name: {}, application_name: {} }}",
|
||||||
self.username, self.pool_name, self.application_name
|
self.username, self.pool_name, self.application_name
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
@@ -223,16 +225,16 @@ impl ClearText {
|
|||||||
error_response(
|
error_response(
|
||||||
write,
|
write,
|
||||||
&format!(
|
&format!(
|
||||||
"No pool configured for database: {:?}, user: {:?}",
|
"No pool configured for database: {}, user: {}",
|
||||||
self.pool_name, self.username
|
self.pool_name, self.username
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Err(Error::ClientError(format!(
|
Err(Error::ClientError(format!(
|
||||||
"Invalid pool name {{ username: {:?}, pool_name: {:?}, application_name: {:?} }}",
|
"Invalid pool name {{ username: {}, pool_name: {}, application_name: {} }}",
|
||||||
self.username, self.pool_name, self.application_name
|
self.username, self.pool_name, self.application_name
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(pool) => {
|
Some(pool) => {
|
||||||
@@ -311,7 +313,7 @@ impl Md5 {
|
|||||||
wrong_password(write, &self.username).await?;
|
wrong_password(write, &self.username).await?;
|
||||||
|
|
||||||
Err(Error::ClientError(format!(
|
Err(Error::ClientError(format!(
|
||||||
"Invalid password {{ username: {:?}, pool_name: {:?}, application_name: {:?} }}",
|
"Invalid password {{ username: {}, pool_name: {}, application_name: {} }}",
|
||||||
self.username, self.pool_name, self.application_name
|
self.username, self.pool_name, self.application_name
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@@ -328,7 +330,7 @@ impl Md5 {
|
|||||||
wrong_password(write, &self.username).await?;
|
wrong_password(write, &self.username).await?;
|
||||||
|
|
||||||
Err(Error::ClientError(format!(
|
Err(Error::ClientError(format!(
|
||||||
"Invalid password {{ username: {:?}, pool_name: {:?}, application_name: {:?} }}",
|
"Invalid password {{ username: {}, pool_name: {}, application_name: {} }}",
|
||||||
self.username, self.pool_name, self.application_name
|
self.username, self.pool_name, self.application_name
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@@ -342,7 +344,7 @@ impl Md5 {
|
|||||||
error_response(
|
error_response(
|
||||||
write,
|
write,
|
||||||
&format!(
|
&format!(
|
||||||
"No password configured and auth_query is not set: {:?}, user: {:?}",
|
"No password configured and auth_query is not set: {}, user: {}",
|
||||||
self.pool_name, self.username
|
self.pool_name, self.username
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -403,7 +405,7 @@ impl Md5 {
|
|||||||
wrong_password(write, &self.username).await?;
|
wrong_password(write, &self.username).await?;
|
||||||
|
|
||||||
Err(Error::ClientError(format!(
|
Err(Error::ClientError(format!(
|
||||||
"Invalid password {{ username: {:?}, pool_name: {:?}, application_name: {:?} }}",
|
"Invalid password {{ username: {}, pool_name: {}, application_name: {} }}",
|
||||||
self.username, self.pool_name, self.application_name
|
self.username, self.pool_name, self.application_name
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@@ -433,14 +435,14 @@ impl Md5 {
|
|||||||
error_response(
|
error_response(
|
||||||
write,
|
write,
|
||||||
&format!(
|
&format!(
|
||||||
"No pool configured for database: {:?}, user: {:?}",
|
"No pool configured for database: {}, user: {}",
|
||||||
self.pool_name, self.username
|
self.pool_name, self.username
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Err(Error::ClientError(format!(
|
return Err(Error::ClientError(format!(
|
||||||
"Invalid pool name {{ username: {:?}, pool_name: {:?}, application_name: {:?} }}",
|
"Invalid pool name {{ username: {}, pool_name: {}, application_name: {} }}",
|
||||||
self.username, self.pool_name, self.application_name
|
self.username, self.pool_name, self.application_name
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user