Skip to content

Commit

Permalink
fix(webserver): Prevent disabled accounts from authenticating (#1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam authored Jan 26, 2024
1 parent 04f6d4e commit c83cc41
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ee/tabby-webserver/src/schema/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ pub enum TokenAuthError {
#[error("Password is not valid")]
InvalidPassword,

#[error("User is disabled")]
UserDisabled,

#[error(transparent)]
Other(#[from] anyhow::Error),

Expand All @@ -160,6 +163,9 @@ pub enum OAuthError {
#[error("The user is not invited to access the system")]
UserNotInvited,

#[error("User is disabled")]
UserDisabled,

#[error(transparent)]
Other(#[from] anyhow::Error),

Expand Down Expand Up @@ -187,6 +193,9 @@ pub enum RefreshTokenError {
#[error("User not found")]
UserNotFound,

#[error("User is disabled")]
UserDisabled,

#[error(transparent)]
Other(#[from] anyhow::Error),

Expand Down
11 changes: 11 additions & 0 deletions ee/tabby-webserver/src/service/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ impl AuthenticationService for DbConn {
return Err(TokenAuthError::UserNotFound);
};

if !user.active {
return Err(TokenAuthError::UserDisabled);
}

if !password_verify(&input.password, &user.password_encrypted) {
return Err(TokenAuthError::InvalidPassword);
}
Expand Down Expand Up @@ -250,6 +254,10 @@ impl AuthenticationService for DbConn {
return Err(RefreshTokenError::UserNotFound);
};

if !user.active {
return Err(RefreshTokenError::UserDisabled);
}

let new_token = generate_refresh_token();
self.replace_refresh_token(&token, &new_token).await?;

Expand Down Expand Up @@ -353,6 +361,9 @@ impl AuthenticationService for DbConn {
};

let user = if let Some(user) = self.get_user_by_email(&email).await? {
if !user.active {
return Err(OAuthError::UserDisabled);
}
user
} else {
let Some(invitation) = self.get_invitation_by_email(&email).await? else {
Expand Down

0 comments on commit c83cc41

Please sign in to comment.