From 0381547c52fbe44744d5d16d95672fa29342b902 Mon Sep 17 00:00:00 2001 From: dasha_uwu Date: Fri, 20 Feb 2026 00:27:29 +0500 Subject: [PATCH] Fix canonical alias event check The old version was checking all aliases instead of only the newly added ones that prevented modifying the event if one of current aliases became invalid --- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 2 +- src/api/client/state.rs | 24 ++++++++++++++++++------ 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c0e653a..1fd4cd71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3754,7 +3754,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.13.0" -source = "git+https://github.com/matrix-construct/ruma?rev=2f53677f4d621cb4560119c5938888c9ce983e56#2f53677f4d621cb4560119c5938888c9ce983e56" +source = "git+https://github.com/matrix-construct/ruma?rev=3cb939f5c8a67197433cbb3dc7e256f0ddaee978#3cb939f5c8a67197433cbb3dc7e256f0ddaee978" dependencies = [ "assign", "js_int", @@ -3773,7 +3773,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.13.0" -source = "git+https://github.com/matrix-construct/ruma?rev=2f53677f4d621cb4560119c5938888c9ce983e56#2f53677f4d621cb4560119c5938888c9ce983e56" +source = "git+https://github.com/matrix-construct/ruma?rev=3cb939f5c8a67197433cbb3dc7e256f0ddaee978#3cb939f5c8a67197433cbb3dc7e256f0ddaee978" dependencies = [ "js_int", "ruma-common", @@ -3785,7 +3785,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.21.0" -source = "git+https://github.com/matrix-construct/ruma?rev=2f53677f4d621cb4560119c5938888c9ce983e56#2f53677f4d621cb4560119c5938888c9ce983e56" +source = "git+https://github.com/matrix-construct/ruma?rev=3cb939f5c8a67197433cbb3dc7e256f0ddaee978#3cb939f5c8a67197433cbb3dc7e256f0ddaee978" dependencies = [ "as_variant", "assign", @@ -3810,7 +3810,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.16.0" -source = "git+https://github.com/matrix-construct/ruma?rev=2f53677f4d621cb4560119c5938888c9ce983e56#2f53677f4d621cb4560119c5938888c9ce983e56" +source = "git+https://github.com/matrix-construct/ruma?rev=3cb939f5c8a67197433cbb3dc7e256f0ddaee978#3cb939f5c8a67197433cbb3dc7e256f0ddaee978" dependencies = [ "as_variant", "base64", @@ -3844,7 +3844,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.31.0" -source = "git+https://github.com/matrix-construct/ruma?rev=2f53677f4d621cb4560119c5938888c9ce983e56#2f53677f4d621cb4560119c5938888c9ce983e56" +source = "git+https://github.com/matrix-construct/ruma?rev=3cb939f5c8a67197433cbb3dc7e256f0ddaee978#3cb939f5c8a67197433cbb3dc7e256f0ddaee978" dependencies = [ "as_variant", "indexmap", @@ -3871,7 +3871,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.12.0" -source = "git+https://github.com/matrix-construct/ruma?rev=2f53677f4d621cb4560119c5938888c9ce983e56#2f53677f4d621cb4560119c5938888c9ce983e56" +source = "git+https://github.com/matrix-construct/ruma?rev=3cb939f5c8a67197433cbb3dc7e256f0ddaee978#3cb939f5c8a67197433cbb3dc7e256f0ddaee978" dependencies = [ "bytes", "headers", @@ -3894,7 +3894,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.11.0" -source = "git+https://github.com/matrix-construct/ruma?rev=2f53677f4d621cb4560119c5938888c9ce983e56#2f53677f4d621cb4560119c5938888c9ce983e56" +source = "git+https://github.com/matrix-construct/ruma?rev=3cb939f5c8a67197433cbb3dc7e256f0ddaee978#3cb939f5c8a67197433cbb3dc7e256f0ddaee978" dependencies = [ "js_int", "thiserror 2.0.18", @@ -3903,7 +3903,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.16.0" -source = "git+https://github.com/matrix-construct/ruma?rev=2f53677f4d621cb4560119c5938888c9ce983e56#2f53677f4d621cb4560119c5938888c9ce983e56" +source = "git+https://github.com/matrix-construct/ruma?rev=3cb939f5c8a67197433cbb3dc7e256f0ddaee978#3cb939f5c8a67197433cbb3dc7e256f0ddaee978" dependencies = [ "cfg-if", "proc-macro-crate", @@ -3918,7 +3918,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.12.0" -source = "git+https://github.com/matrix-construct/ruma?rev=2f53677f4d621cb4560119c5938888c9ce983e56#2f53677f4d621cb4560119c5938888c9ce983e56" +source = "git+https://github.com/matrix-construct/ruma?rev=3cb939f5c8a67197433cbb3dc7e256f0ddaee978#3cb939f5c8a67197433cbb3dc7e256f0ddaee978" dependencies = [ "js_int", "ruma-common", @@ -3930,7 +3930,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.18.0" -source = "git+https://github.com/matrix-construct/ruma?rev=2f53677f4d621cb4560119c5938888c9ce983e56#2f53677f4d621cb4560119c5938888c9ce983e56" +source = "git+https://github.com/matrix-construct/ruma?rev=3cb939f5c8a67197433cbb3dc7e256f0ddaee978#3cb939f5c8a67197433cbb3dc7e256f0ddaee978" dependencies = [ "base64", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index 9a5f321f..c4969e65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -320,7 +320,7 @@ default-features = false [workspace.dependencies.ruma] git = "https://github.com/matrix-construct/ruma" -rev = "2f53677f4d621cb4560119c5938888c9ce983e56" +rev = "3cb939f5c8a67197433cbb3dc7e256f0ddaee978" features = [ "__compat", "appservice-api-c", diff --git a/src/api/client/state.rs b/src/api/client/state.rs index cb135ec1..52f225fe 100644 --- a/src/api/client/state.rs +++ b/src/api/client/state.rs @@ -1,7 +1,7 @@ use axum::extract::State; use futures::{FutureExt, TryFutureExt, TryStreamExt}; use ruma::{ - OwnedEventId, RoomId, UserId, + OwnedEventId, OwnedRoomAliasId, RoomId, UserId, api::client::state::{get_state_event_for_key, get_state_events, send_state_event}, events::{ AnyStateEventContent, StateEventType, @@ -320,16 +320,28 @@ async fn allowed_to_send_state_event( | StateEventType::RoomCanonicalAlias => { match json.deserialize_as_unchecked::() { | Ok(canonical_alias_content) => { - let mut aliases = canonical_alias_content.alt_aliases.clone(); + let current_event = services + .state_accessor + .room_state_get_content::( + room_id, + &StateEventType::RoomCanonicalAlias, + "", + ) + .await + .ok(); - if let Some(alias) = canonical_alias_content.alias { - aliases.push(alias); - } + let current_aliases: Vec = current_event + .map(|content| content.aliases().cloned().collect()) + .unwrap_or_default(); + + let aliases = canonical_alias_content + .aliases() + .filter(|alias| !current_aliases.contains(alias)); for alias in aliases { let (alias_room_id, _servers) = services .alias - .resolve_alias(&alias) + .resolve_alias(alias) .await .map_err(|e| { err!(Request(BadAlias("Failed resolving alias \"{alias}\": {e}")))