Skip to content

Commit fbaec27

Browse files
authored
Return error on requests with root username (#467)
Block request with the root username Fixes #466
1 parent bfb9a7f commit fbaec27

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

server/src/handlers/http/rbac.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ pub async fn list_users() -> impl Responder {
4848
pub async fn put_user(username: web::Path<String>) -> Result<impl Responder, RBACError> {
4949
let username = username.into_inner();
5050
validator::user_name(&username)?;
51+
if username == CONFIG.parseable.username {
52+
return Err(RBACError::BadUser);
53+
}
5154
let _ = UPDATE_LOCK.lock().await;
5255
if Users.contains(&username) {
5356
reset_password(username).await
@@ -81,6 +84,9 @@ pub async fn get_role(username: web::Path<String>) -> Result<impl Responder, RBA
8184
// Handler for DELETE /api/v1/user/delete/{username}
8285
pub async fn delete_user(username: web::Path<String>) -> Result<impl Responder, RBACError> {
8386
let username = username.into_inner();
87+
if username == CONFIG.parseable.username {
88+
return Err(RBACError::BadUser);
89+
}
8490
let _ = UPDATE_LOCK.lock().await;
8591
// fail this request if the user does not exists
8692
if !Users.contains(&username) {
@@ -125,6 +131,9 @@ pub async fn put_role(
125131
role: web::Json<serde_json::Value>,
126132
) -> Result<String, RBACError> {
127133
let username = username.into_inner();
134+
if username == CONFIG.parseable.username {
135+
return Err(RBACError::BadUser);
136+
}
128137
let role = role.into_inner();
129138
let role: HashSet<DefaultPrivilege> = serde_json::from_value(role)?;
130139
let role = role.into_iter().collect();
@@ -169,6 +178,8 @@ async fn put_metadata(metadata: &StorageMetadata) -> Result<(), ObjectStorageErr
169178

170179
#[derive(Debug, thiserror::Error)]
171180
pub enum RBACError {
181+
#[error("Request cannot be allowed for this user")]
182+
BadUser,
172183
#[error("User exists already")]
173184
UserExists,
174185
#[error("User does not exist")]
@@ -184,6 +195,7 @@ pub enum RBACError {
184195
impl actix_web::ResponseError for RBACError {
185196
fn status_code(&self) -> http::StatusCode {
186197
match self {
198+
Self::BadUser => StatusCode::BAD_REQUEST,
187199
Self::UserExists => StatusCode::BAD_REQUEST,
188200
Self::UserDoesNotExist => StatusCode::NOT_FOUND,
189201
Self::SerdeError(_) => StatusCode::BAD_REQUEST,

0 commit comments

Comments
 (0)