diff --git a/meilisearch-http/src/index_controller/uuid_resolver.rs b/meilisearch-http/src/index_controller/uuid_resolver.rs index d8d39d922..4fe079518 100644 --- a/meilisearch-http/src/index_controller/uuid_resolver.rs +++ b/meilisearch-http/src/index_controller/uuid_resolver.rs @@ -72,10 +72,16 @@ impl UuidResolverActor { } async fn handle_create(&self, name: String) -> Result { + if !is_index_uid_valid(&name) { + return Err(UuidError::BadlyFormatted(name)) + } self.store.create_uuid(name, true).await } async fn handle_get_or_create(&self, name: String) -> Result { + if !is_index_uid_valid(&name) { + return Err(UuidError::BadlyFormatted(name)) + } self.store.create_uuid(name, false).await } @@ -99,6 +105,10 @@ impl UuidResolverActor { } } +fn is_index_uid_valid(uid: &str) -> bool { + uid.chars().all(|x| x.is_ascii_alphanumeric() || x == '-' || x == '_') +} + #[derive(Clone)] pub struct UuidResolverHandle { sender: mpsc::Sender, @@ -171,6 +181,8 @@ pub enum UuidError { Heed(#[from] heed::Error), #[error("Uuid error: {0}")] Uuid(#[from] uuid::Error), + #[error("Badly formatted index uid: {0}")] + BadlyFormatted(String), } #[async_trait::async_trait]