(fix branch) Potential user_may_invite callback logic?

This commit is contained in:
nexy7574 2025-05-09 23:22:43 +01:00
parent c0f46269b5
commit d8f1e948d9
No known key found for this signature in database
GPG key ID: 0FA334385D0B689F
3 changed files with 48 additions and 12 deletions

22
Cargo.lock generated
View file

@ -3758,7 +3758,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.10.1" 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 = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
@ -3778,7 +3778,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.10.0" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -3790,7 +3790,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.18.0" 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 = [ dependencies = [
"as_variant", "as_variant",
"assign", "assign",
@ -3813,7 +3813,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.13.0" 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 = [ dependencies = [
"as_variant", "as_variant",
"base64 0.22.1", "base64 0.22.1",
@ -3845,7 +3845,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.28.1" 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 = [ dependencies = [
"as_variant", "as_variant",
"indexmap 2.8.0", "indexmap 2.8.0",
@ -3870,7 +3870,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.9.0" 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 = [ dependencies = [
"bytes", "bytes",
"headers", "headers",
@ -3892,7 +3892,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.9.5" 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 = [ dependencies = [
"js_int", "js_int",
"thiserror 2.0.12", "thiserror 2.0.12",
@ -3901,7 +3901,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identity-service-api" name = "ruma-identity-service-api"
version = "0.9.0" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -3911,7 +3911,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-macros" name = "ruma-macros"
version = "0.13.0" 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 = [ dependencies = [
"cfg-if", "cfg-if",
"proc-macro-crate", "proc-macro-crate",
@ -3926,7 +3926,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-push-gateway-api" name = "ruma-push-gateway-api"
version = "0.9.0" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -3938,7 +3938,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.15.0" 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 = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"ed25519-dalek", "ed25519-dalek",

View file

@ -350,7 +350,7 @@ version = "0.1.2"
[workspace.dependencies.ruma] [workspace.dependencies.ruma]
git = "https://forgejo.ellis.link/continuwuation/ruwuma" git = "https://forgejo.ellis.link/continuwuation/ruwuma"
#branch = "conduwuit-changes" #branch = "conduwuit-changes"
rev = "d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" rev = "97048c0a535a2b895079518b7b9b20fcd144ad5f"
features = [ features = [
"compat", "compat",
"rand", "rand",

View file

@ -113,6 +113,42 @@ pub(crate) async fn create_invite_route(
invite_state.push(pdu.to_stripped_state_event()); 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 // 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 // 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 // record the invited state for client /sync through update_membership(), and