fix: Use the requested device ID when an appservice creates a device

The appservice branch of update_device_route (MSC4190 device creation)
generated a random device ID instead of using the one from the request
path, and dropped the requested display name. The PUT returned 200, but
the device the appservice asked for never existed, so every subsequent
request masquerading as that device failed with M_FORBIDDEN and one
orphaned random-ID device was left behind per attempt.

This made encrypted mautrix (bridgev2) bridges unable to start on
OIDC-enabled servers, where MSC4190 is the only available device
creation mechanism: /keys/upload failed on first start and /keys/query
on every restart. Combined with the pre-1f5e178c3f behaviour (400
"Token conflicts with an existing appservice token"), MSC4190 device
creation has never worked end-to-end in any release.

Create the device under the requested ID and forward the requested
display name.
This commit is contained in:
Deniel9204 committed 2026-07-21 08:21:09 +02:00
1 parent bcd57b9598
commit 25264308ab
2 files changed
+11 -6

No files matched your search

+10 -6
View File
@@ -1,14 +1,14 @@
use axum::extract::State;
use conduwuit::{Err, Result, debug, err, utils};
use conduwuit::{Err, Result, debug, err};
use futures::StreamExt;
use ruma::{
MilliSecondsSinceUnixEpoch, OwnedDeviceId,
MilliSecondsSinceUnixEpoch,
api::client::device::{
self, delete_device, delete_devices, get_device, get_devices, update_device,
},
};
use crate::{Ruma, client::DEVICE_ID_LENGTH, client_ip::ClientIp};
use crate::{Ruma, client_ip::ClientIp};
/// # `GET /_matrix/client/r0/devices`
///
@@ -84,11 +84,15 @@ pub(crate) async fn update_device_route(
appservice.registration.id
);
let device_id = OwnedDeviceId::from(utils::random_string(DEVICE_ID_LENGTH));
services
.users
.create_device(sender_user, &device_id, None, None, Some(client.to_string()))
.create_device(
sender_user,
&body.device_id,
None,
body.display_name.clone(),
Some(client.to_string()),
)
.await?;
return Ok(update_device::v3::Response::new());