From 14ff018b9f7386f8c5f433c0f1d7a31bf9b11445 Mon Sep 17 00:00:00 2001 From: timedout Date: Thu, 30 Jul 2026 18:33:47 +0100 Subject: [PATCH] fix: Don't soft-fail valid redactions --- .../event_handler/upgrade_outlier_pdu.rs | 24 ++++++++++++------- src/service/rooms/state_accessor/user_can.rs | 5 +++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/service/rooms/event_handler/upgrade_outlier_pdu.rs b/src/service/rooms/event_handler/upgrade_outlier_pdu.rs index 09aa9e41e..30a90dfed 100644 --- a/src/service/rooms/event_handler/upgrade_outlier_pdu.rs +++ b/src/service/rooms/event_handler/upgrade_outlier_pdu.rs @@ -104,24 +104,24 @@ impl super::Service { // Determine whether this PDU should be soft-failed. // If the auth check failed, invariably yes. Otherwise, only if the user isn't // allowed to redact the target event (if any). - let mut should_soft_fail = - match (passes_current_state, incoming_pdu.redacts_id(&room_version_rules)) { - | (false, _) => true, - | (true, None) => false, - | (true, Some(redact_id)) => self - .services + let redaction_permitted = + if let Some(redacted_id) = incoming_pdu.redacts_id(&room_version_rules) { + self.services .state_accessor - .user_can_redact(&redact_id, incoming_pdu.sender(), room_id, true) + .user_can_redact(&redacted_id, incoming_pdu.sender(), room_id, true) .await - .is_ok_and(is_true!()), + .is_ok_and(is_true!()) + } else { + true }; + let mut should_soft_fail = !redaction_permitted || !passes_current_state; if !should_soft_fail { // Now we can perform check 7, which is ensuring the event passes policy server // checks. // We explicitly only do this if we aren't already going to soft-fail the event, // since the policy server refusing this event also soft-fails it. - debug!(event_id = %incoming_pdu.event_id, "Checking policy server for event"); + debug!("Checking policy server for event"); should_soft_fail = !self .policy_server_check_7(&incoming_pdu, &mut val, &room_version_rules) .await @@ -153,6 +153,12 @@ impl super::Service { should_soft_fail = true; } } + } else { + debug!( + %redaction_permitted, + %passes_current_state, + "Intending to soft-fail event (skipping further PDU checks)" + ); } // The PDU has now passed all checks! We can now promote it (or soft-fail it if diff --git a/src/service/rooms/state_accessor/user_can.rs b/src/service/rooms/state_accessor/user_can.rs index b27a57304..ffeb7cdcf 100644 --- a/src/service/rooms/state_accessor/user_can.rs +++ b/src/service/rooms/state_accessor/user_can.rs @@ -1,4 +1,4 @@ -use conduwuit::{Err, Result, matrix::Event, pdu::PartialPdu}; +use conduwuit::{Err, Result, matrix::Event, pdu::PartialPdu, trace}; use ruma::{ EventId, RoomId, UserId, events::{ @@ -46,6 +46,7 @@ impl super::Service { let power_levels = self.get_room_power_levels(room_id).await; if power_levels.user_can_redact_event_of_other(sender) { + trace!(%sender, "Sender is allowed to redact other users' events"); return Ok(true); } @@ -59,10 +60,12 @@ impl super::Service { }, | _ => false, }; + trace!(%is_own_event, "User can redact own event"); return Ok(is_own_event); } + trace!("User is not permitted to redact their own event nor others' events"); Ok(false) }