diff --git a/Cargo.lock b/Cargo.lock index 18375234..c7624b67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3758,7 +3758,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.10.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=97048c0a535a2b895079518b7b9b20fcd144ad5f#97048c0a535a2b895079518b7b9b20fcd144ad5f" dependencies = [ "assign", "js_int", @@ -3778,7 +3778,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=97048c0a535a2b895079518b7b9b20fcd144ad5f#97048c0a535a2b895079518b7b9b20fcd144ad5f" dependencies = [ "js_int", "ruma-common", @@ -3790,7 +3790,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=97048c0a535a2b895079518b7b9b20fcd144ad5f#97048c0a535a2b895079518b7b9b20fcd144ad5f" dependencies = [ "as_variant", "assign", @@ -3813,7 +3813,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=97048c0a535a2b895079518b7b9b20fcd144ad5f#97048c0a535a2b895079518b7b9b20fcd144ad5f" dependencies = [ "as_variant", "base64 0.22.1", @@ -3845,7 +3845,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=97048c0a535a2b895079518b7b9b20fcd144ad5f#97048c0a535a2b895079518b7b9b20fcd144ad5f" dependencies = [ "as_variant", "indexmap 2.8.0", @@ -3870,7 +3870,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=97048c0a535a2b895079518b7b9b20fcd144ad5f#97048c0a535a2b895079518b7b9b20fcd144ad5f" dependencies = [ "bytes", "headers", @@ -3892,7 +3892,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=97048c0a535a2b895079518b7b9b20fcd144ad5f#97048c0a535a2b895079518b7b9b20fcd144ad5f" dependencies = [ "js_int", "thiserror 2.0.12", @@ -3901,7 +3901,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=97048c0a535a2b895079518b7b9b20fcd144ad5f#97048c0a535a2b895079518b7b9b20fcd144ad5f" dependencies = [ "js_int", "ruma-common", @@ -3911,7 +3911,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=97048c0a535a2b895079518b7b9b20fcd144ad5f#97048c0a535a2b895079518b7b9b20fcd144ad5f" dependencies = [ "cfg-if", "proc-macro-crate", @@ -3926,7 +3926,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=97048c0a535a2b895079518b7b9b20fcd144ad5f#97048c0a535a2b895079518b7b9b20fcd144ad5f" dependencies = [ "js_int", "ruma-common", @@ -3938,7 +3938,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=97048c0a535a2b895079518b7b9b20fcd144ad5f#97048c0a535a2b895079518b7b9b20fcd144ad5f" dependencies = [ "base64 0.22.1", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index 43cd3f4f..36a11998 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -350,7 +350,7 @@ version = "0.1.2" [workspace.dependencies.ruma] git = "https://forgejo.ellis.link/continuwuation/ruwuma" #branch = "conduwuit-changes" -rev = "d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +rev = "97048c0a535a2b895079518b7b9b20fcd144ad5f" features = [ "compat", "rand", diff --git a/src/api/server/invite.rs b/src/api/server/invite.rs index f53e1a15..b649311e 100644 --- a/src/api/server/invite.rs +++ b/src/api/server/invite.rs @@ -113,6 +113,42 @@ pub(crate) async fn create_invite_route( invite_state.push(pdu.to_stripped_state_event()); + // Check the invite against any user_may_invite callbacks + for appservice in services.appservice.read().await.values() { + if let Some(callbacks) = &appservice.registration.callbacks { + if callbacks.user_may_invite.is_some() { + let resp = services + .sending + .send_appservice_request( + appservice.registration.clone(), + ruma::api::appservice::callback::user_may_invite::unstable::Request::new( + sender.to_owned(), + invited_user.clone(), + body.room_id.clone(), + ), + ) + .await?; + let as_id = &appservice.registration.id; + match resp { + | None => { + warn!( + "Failed to contact appservice {as_id} for user_may_invite callback." + ); + return Err!(Request(Forbidden("User may not invite."))); + }, + | Some(r) => { + if !r.ok { + let reason = r.reason.unwrap_or_else(|| "No reason".to_string()); + warn!("Appservice {as_id} denied user_may_invite callback: {reason}"); + return Err!(Request(Forbidden("User may not invite: {reason}"))); + } + // Otherwise, continue + }, + } + } + } + } + // If we are active in the room, the remote server will notify us about the // join/invite through /send. If we are not in the room, we need to manually // record the invited state for client /sync through update_membership(), and