1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-04-22 14:10:16 +03:00

fix: check that keys uploaded by clients are valid

clients uploading invalid keys can cause errors later when trying to add signatures
This commit is contained in:
Matthias Ahouansou 2025-02-27 00:38:21 +00:00
parent a3386f405e
commit be3187fda7
No known key found for this signature in database

View file

@ -36,6 +36,10 @@ pub async fn upload_keys_route(
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
for (key_key, key_value) in &body.one_time_keys {
key_value.deserialize().map_err(|_| {
Error::BadRequest(ErrorKind::BadJson, "Body contained invalid one-time key")
})?;
services()
.users
.add_one_time_key(sender_user, sender_device, key_key, key_value)?;
@ -49,6 +53,10 @@ pub async fn upload_keys_route(
.get_device_keys(sender_user, sender_device)?
.is_none()
{
device_keys.deserialize().map_err(|_| {
Error::BadRequest(ErrorKind::BadJson, "Body contained invalid device keys")
})?;
services()
.users
.add_device_keys(sender_user, sender_device, device_keys)?;