Compare commits

..
Author SHA1 Message Date
Renovate Bot af3e7f442e chore(deps): update ruma digest to decdf3f 2026-11-23 05:05:19 +00:00
9 changed files with 19 additions and 131 deletions

No files matched your search

+1 -1
View File
@@ -43,7 +43,7 @@ jobs:
name: Renovate
runs-on: ubuntu-latest
container:
image: ghcr.io/renovatebot/renovate:44.257.9@sha256:578179439fceea89646662dd583b27efdad8d1429e0cbd90681c40dde068589e
image: ghcr.io/renovatebot/renovate:44.241.0@sha256:22d22b4ca7d768b5b469309d34379783bf91cd94a58faecf1cd0f4528a65d21c
options: --tmpfs /tmp:exec
steps:
- name: Checkout
+1 -1
View File
@@ -357,7 +357,7 @@ version = "1.1.1"
# Used for matrix spec type definitions and helpers
[workspace.dependencies.ruma]
git = "https://github.com/ruma/ruma.git"
rev = "472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
rev = "decdf3f6c5160e1db595d4edb4d65d5de935e13c"
features = [
"appservice-api-c",
"client-api",
-1
View File
@@ -1 +0,0 @@
Network issues while refreshing an access token will no longer cause OAuth-compatible clients to be forcibly logged out. Contributed by @ginger.
+6 -22
View File
@@ -319,19 +319,6 @@ async fn check_access_token(
));
}
let session_info = services
.oauth
.get_session_info_for_device(&sender_user, &sender_device)
.await;
if let Some(session_info) = &session_info {
services.oauth.clear_previous_refresh_token(
&sender_user,
&sender_device,
session_info,
);
}
// Locked users can only use /logout and /logout/all
if services
.users
@@ -346,6 +333,12 @@ async fn check_access_token(
}
}
let session_info = services
.oauth
.get_session_info_for_device(&sender_user, &sender_device)
.await
.map(Box::new);
// Make sure the user has the right scopes to use the route
let mut user_scopes = if let Some(session_info) = &session_info {
session_info.scopes()
@@ -423,15 +416,6 @@ async fn check_access_token(
sender_device,
appservice_info: Box::new(appservice_info),
})
} else if services.users.is_previous_token(token).await {
// Return a soft-logout for previous tokens. This is necessary
// to make token refreshing idempotent.
Err(Error::Request(
ErrorKind::UnknownToken(assign!(UnknownTokenErrorData::new(), { soft_logout: true })),
"This token has expired".into(),
StatusCode::UNAUTHORIZED,
))
} else {
Err(Error::Request(
ErrorKind::UnknownToken(UnknownTokenErrorData::new()),
-4
View File
@@ -407,10 +407,6 @@ pub(super) static MAPS: &[Descriptor] = &[
name: "userdeviceid_token",
..descriptor::RANDOM_SMALL
},
Descriptor {
name: "userdeviceid_previoustoken",
..descriptor::RANDOM_SMALL
},
Descriptor {
name: "userdevicesessionid_uiaainfo",
..descriptor::RANDOM_SMALL
+10 -77
View File
@@ -1,6 +1,5 @@
use std::{
collections::{BTreeSet, HashMap},
fmt::Write,
sync::Arc,
time::{Duration, SystemTime},
};
@@ -56,7 +55,7 @@ struct Services {
config: Dep<config::Service>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct SessionInfo {
pub client_id: String,
#[serde(deserialize_with = "client_metadata::btreeset_skip_err")]
@@ -65,8 +64,6 @@ pub struct SessionInfo {
temporary_scopes: BTreeSet<OAuthClientScope>,
#[serde(default)]
current_refresh_token: String,
#[serde(default)]
previous_refresh_token: Option<String>,
}
impl SessionInfo {
@@ -74,15 +71,6 @@ impl SessionInfo {
pub fn scopes(&self) -> BTreeSet<OAuthClientScope> {
self.scopes.union(&self.temporary_scopes).cloned().collect()
}
#[must_use]
pub fn scope_string(&self, device_id: &DeviceId) -> String {
let mut scopes = self.scopes().iter().join(" ");
let _ = write!(scopes, " urn:matrix:client:device:{device_id}");
scopes
}
}
#[derive(Debug, Deserialize, Serialize)]
@@ -258,24 +246,6 @@ impl Service {
.ok()
}
/// Clear a session's previous refresh token, if it has one.
pub fn clear_previous_refresh_token(
&self,
user_id: &UserId,
device_id: &DeviceId,
session_info: &SessionInfo,
) {
if session_info.previous_refresh_token.is_some() {
let mut session_info = session_info.clone();
session_info.previous_refresh_token = None;
self.db
.userdeviceid_oauthsessioninfo
.put((user_id, device_id), Json(session_info));
}
}
pub async fn request_authorization_code(
&self,
authorizing_user: OwnedUserId,
@@ -675,7 +645,6 @@ impl Service {
SessionInfo {
client_id: client_id.clone(),
current_refresh_token: Self::generate_token(),
previous_refresh_token: None,
scopes: requested_scopes.scopes,
temporary_scopes: BTreeSet::new(),
}
@@ -733,53 +702,15 @@ impl Service {
assert_eq!(&client_id, &session_info.client_id, "session info client id mismatch");
let new_refresh_token = Self::generate_token();
if refresh_token == session_info.current_refresh_token {
// The client is refreshing with their current refresh token.
// We need to generate a new refresh token and save this token as
// the previous one.
session_info
.current_refresh_token
.clone_from(&new_refresh_token);
// Remove the old previous token if it's set. This can only happen
// if the client decides to refresh twice in a row without using its
// new access token, since we'll also do this when the new access
// token is used for the first time.
if let Some(previous_refresh_token) = session_info.previous_refresh_token {
self.db
.refreshtoken_refreshtokeninfo
.remove(&previous_refresh_token);
}
session_info.previous_refresh_token = Some(refresh_token);
} else if Some(&refresh_token) == session_info.previous_refresh_token.as_ref() {
// The client is refreshing with their previous refresh token,
// probably because they didn't get the new one we made for them. We
// need to make a second new one, but we don't touch the existing
// previous one in case they don't get the second new one either.
// Wipe the current token, we're going to make a new one.
self.db
.refreshtoken_refreshtokeninfo
.remove(&session_info.current_refresh_token);
session_info
.current_refresh_token
.clone_from(&new_refresh_token);
} else {
// The client is trying to use a refresh token that isn't their
// current or previous one, but still has information in the
// database. This is definitely not a legal state, so we need to
// bail out.
panic!("refresh token is not current or previous for its session");
}
let scope = session_info.scope_string(&refresh_token_info.device_id);
// TODO: this doesn't include the device ID "scope", do any clients rely
// on that?
let scope = session_info.scopes.iter().join(" ");
let new_access_token = DeviceToken::new_random().with_max_age(Self::ACCESS_TOKEN_MAX_AGE);
let new_refresh_token = Self::generate_token();
session_info
.current_refresh_token
.clone_from(&new_refresh_token);
self.services
.users
@@ -798,6 +729,8 @@ impl Service {
Json(session_info),
);
self.db.refreshtoken_refreshtokeninfo.remove(&refresh_token);
drop(refresh_token);
self.db
.refreshtoken_refreshtokeninfo
.raw_put(&new_refresh_token, Json(refresh_token_info));
-6
View File
@@ -632,12 +632,6 @@ impl super::Service {
}
}
// Discard this device's previous token entry if the current token
// isn't expired.
self.db
.userdeviceid_previoustoken
.del((&user_id, &device_id));
Some((user_id, device_id, AccessTokenStatus::Valid))
}
+1 -17
View File
@@ -184,13 +184,8 @@ impl super::Service {
// Remove old token
if let Ok(old_token) = self.db.userdeviceid_token.qry(&key).await {
self.db.token_userdeviceid.remove(&old_token);
self.db.userdeviceid_tokenexpires.remove(&old_token);
// It will be removed from userdeviceid_token by the insert later
// Save the previous token only if we don't already have one saved
// for this device.
if !self.db.userdeviceid_previoustoken.contains(&key).await {
self.db.userdeviceid_previoustoken.put_raw(key, &old_token);
}
}
// Assign token to user device combination
@@ -212,17 +207,6 @@ impl super::Service {
Ok(())
}
/// Returns whether the provided token was previously used by a device
/// before a token refresh, and therefore should cause a soft-logout.
pub async fn is_previous_token(&self, token: &str) -> bool {
self.db
.userdeviceid_previoustoken
.stream::<Ignore, String>()
.ignore_err()
.ready_any(|(_, previous_token)| previous_token == token)
.await
}
/// Pushes a new to-device event into a device's inbox.
pub async fn add_to_device_event(
&self,
-2
View File
@@ -83,7 +83,6 @@ struct Data {
userdeviceid_tokenexpires: Arc<Map>,
userdeviceid_metadata: Arc<Map>,
userdeviceid_token: Arc<Map>,
userdeviceid_previoustoken: Arc<Map>,
userfilterid_filter: Arc<Map>,
userid_avatarurl: Arc<Map>,
userid_deactivated: Arc<Map>,
@@ -135,7 +134,6 @@ impl crate::Service for Service {
remoteuserid_remoteuser: args.db["remoteuserid_remoteuser"].clone(),
userdeviceid_metadata: args.db["userdeviceid_metadata"].clone(),
userdeviceid_token: args.db["userdeviceid_token"].clone(),
userdeviceid_previoustoken: args.db["userdeviceid_previoustoken"].clone(),
userfilterid_filter: args.db["userfilterid_filter"].clone(),
userid_avatarurl: args.db["userid_avatarurl"].clone(),
userid_deactivated: args.db["userid_deactivated"].clone(),