fix: Work around MSC4484 lockout when disabled

This commit is contained in:
timedout authored and Ellis Git committed 2026-11-19 18:44:07 +00:00
1 parent 62fc507798
commit 49207a42f8
4 files changed
+16 -21

No files matched your search

+10 -10
View File
@@ -340,19 +340,19 @@ async fn check_access_token(
.map(Box::new);
// Make sure the user has the right scopes to use the route
let user_scopes = if let Some(session_info) = &session_info {
let mut user_scopes = if let Some(session_info) = &session_info {
session_info.scopes()
} else {
let mut scopes = BTreeSet::from_iter([OAuthClientScope::ApiFullAccess]);
if services.config.experiments.msc4484.is_enabled()
&& services.admin.user_is_admin(&sender_user).await
{
scopes.insert(OAuthClientScope::ServerAdministration);
}
scopes
BTreeSet::from_iter([OAuthClientScope::ApiFullAccess])
};
if (!services.config.experiments.msc4484.is_enabled() || session_info.is_none())
&& services.admin.user_is_admin(&sender_user).await
{
// This is required to make sure admin APIs still work when msc4484
// is disabled.
// https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2533#issuecomment-40042
user_scopes.insert(OAuthClientScope::ServerAdministration);
}
if !required_scopes
.iter()
+2 -2
View File
@@ -107,7 +107,7 @@ pub struct RawScopes(String);
impl RawScopes {
#[allow(clippy::trivial_regex)]
pub fn to_scopes(&self, msc4484: bool) -> Result<RequestedScopes, String> {
pub fn to_scopes(&self) -> Result<RequestedScopes, String> {
let client_api_token_regex =
regex!(r"urn:matrix:(client|org.matrix.msc2967.client):api:\*");
let device_token_regex =
@@ -121,7 +121,7 @@ impl RawScopes {
let scope_was_new = {
if client_api_token_regex.is_match(token) {
scopes.scopes.insert(OAuthClientScope::ApiFullAccess)
} else if msc4484 && server_administration_regex.is_match(token) {
} else if server_administration_regex.is_match(token) {
scopes.scopes.insert(OAuthClientScope::ServerAdministration)
} else if let Some(captures) = device_token_regex.captures(token) {
scopes
+2 -4
View File
@@ -286,9 +286,7 @@ impl Service {
}
}
let requested_scopes = query
.scope
.to_scopes(self.services.config.experiments.msc4484.is_enabled())?;
let requested_scopes = query.scope.to_scopes()?;
let redirect_uri_query_separator = match query.response_mode {
| ResponseMode::Fragment => '#',
@@ -347,7 +345,7 @@ impl Service {
let requested_scopes = query
.scope
.to_scopes(self.services.config.experiments.msc4484.is_enabled())
.to_scopes()
.map_err(|err| OAuthError::new(ErrorCode::InvalidGrant, err))?;
let device_code = Self::generate_token();
+2 -5
View File
@@ -4,7 +4,6 @@ use axum::{
response::Redirect,
routing::on,
};
use conduwuit_core::config::experiments::ToggledExperiment;
use conduwuit_service::oauth::{
SessionInfo,
client_metadata::ClientMetadata,
@@ -105,10 +104,8 @@ async fn route_authorization_code(
return Err(WebError::BadRequest("Invalid client ID".to_owned()));
};
let RequestedScopes { device_id, mut scopes } = query
.scope
.to_scopes(services.config.experiments.msc4484.is_enabled())
.map_err(WebError::BadRequest)?;
let RequestedScopes { device_id, mut scopes } =
query.scope.to_scopes().map_err(WebError::BadRequest)?;
let existing_session_info = if let Some(device_id) = &device_id {
services