From f2ec2be821b49ad565bdb92e44eabe9510cf5455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Wed, 3 Mar 2021 21:41:26 +0100 Subject: [PATCH] fix: don't always query aliases of appservices only do so if the alias matches the regex in the registration file --- src/client_server/alias.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/client_server/alias.rs b/src/client_server/alias.rs index b8c16d9..0a8ad08 100644 --- a/src/client_server/alias.rs +++ b/src/client_server/alias.rs @@ -1,5 +1,6 @@ use super::State; use crate::{ConduitResult, Database, Error, Ruma}; +use regex::Regex; use ruma::{ api::{ appservice, @@ -86,15 +87,23 @@ pub async fn get_alias_helper( Some(r) => room_id = Some(r), None => { for (_id, registration) in db.appservice.iter_all().filter_map(|r| r.ok()) { - if db - .sending - .send_appservice_request( - &db.globals, - registration, - appservice::query::query_room_alias::v1::Request { room_alias }, - ) - .await - .is_ok() + let aliases = registration + .get("namespaces") + .and_then(|ns| ns.get("aliases")) + .and_then(|users| users.get("regex")) + .and_then(|regex| regex.as_str()) + .and_then(|regex| Regex::new(regex).ok()); + + if aliases.map_or(false, |aliases| aliases.is_match(room_alias.as_str())) + && db + .sending + .send_appservice_request( + &db.globals, + registration, + appservice::query::query_room_alias::v1::Request { room_alias }, + ) + .await + .is_ok() { room_id = Some(db.rooms.id_from_alias(&room_alias)?.ok_or_else(|| { Error::bad_config("Appservice lied to us. Room does not exist.")