mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
feat(appservices): MSC3202 Device masquerading for appservices
This commit is contained in:
+26
-2
@@ -14,7 +14,8 @@ use futures::{
|
|||||||
pin_mut,
|
pin_mut,
|
||||||
};
|
};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonObject, CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId, UserId,
|
CanonicalJsonObject, CanonicalJsonValue, DeviceId, OwnedDeviceId, OwnedServerName,
|
||||||
|
OwnedUserId, UserId,
|
||||||
api::{
|
api::{
|
||||||
AuthScheme, IncomingRequest, Metadata,
|
AuthScheme, IncomingRequest, Metadata,
|
||||||
client::{
|
client::{
|
||||||
@@ -234,10 +235,33 @@ async fn auth_appservice(
|
|||||||
return Err!(Request(Exclusive("User is not in namespace.")));
|
return Err!(Request(Exclusive("User is not in namespace.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MSC3202/MSC4190: Handle device_id masquerading for appservices.
|
||||||
|
// The device_id can be provided via `device_id` or
|
||||||
|
// `org.matrix.msc3202.device_id` query parameter.
|
||||||
|
let sender_device = if let Some(ref device_id_str) = request.query.device_id {
|
||||||
|
let device_id: &DeviceId = device_id_str.as_str().into();
|
||||||
|
|
||||||
|
// Verify the device exists for this user
|
||||||
|
if services
|
||||||
|
.users
|
||||||
|
.get_device_metadata(&user_id, device_id)
|
||||||
|
.await
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
return Err!(Request(Forbidden(
|
||||||
|
"Device does not exist for user or appservice cannot masquerade as this device."
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(device_id.to_owned())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Auth {
|
Ok(Auth {
|
||||||
origin: None,
|
origin: None,
|
||||||
sender_user: Some(user_id),
|
sender_user: Some(user_id),
|
||||||
sender_device: None,
|
sender_device,
|
||||||
appservice_info: Some(*info),
|
appservice_info: Some(*info),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ use service::Services;
|
|||||||
pub(super) struct QueryParams {
|
pub(super) struct QueryParams {
|
||||||
pub(super) access_token: Option<String>,
|
pub(super) access_token: Option<String>,
|
||||||
pub(super) user_id: Option<String>,
|
pub(super) user_id: Option<String>,
|
||||||
|
/// Device ID for appservice device masquerading (MSC3202/MSC4190).
|
||||||
|
/// Can be provided as `device_id` or `org.matrix.msc3202.device_id`.
|
||||||
|
#[serde(alias = "org.matrix.msc3202.device_id")]
|
||||||
|
pub(super) device_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct Request {
|
pub(super) struct Request {
|
||||||
|
|||||||
Reference in New Issue
Block a user