From 5870c029330076b79d504f1e87bbc2ccd5bb9d39 Mon Sep 17 00:00:00 2001 From: Gnuxie <50846879+Gnuxie@users.noreply.github.com> Date: Sun, 29 Mar 2026 16:30:55 +0100 Subject: [PATCH] Stop MemberBanSynchronisation banning for all recommendations. (#1062) Originally contributed in https://github.com/Gnuxie/matrix-protection-suite/pull/102. Co-authored-by: nexy7574 --- .changeset/famous-aliens-smash.md | 8 +++++ .../MemberBanSynchronisation.ts | 30 +++++++++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 .changeset/famous-aliens-smash.md diff --git a/.changeset/famous-aliens-smash.md b/.changeset/famous-aliens-smash.md new file mode 100644 index 00000000..53af7aaf --- /dev/null +++ b/.changeset/famous-aliens-smash.md @@ -0,0 +1,8 @@ +--- +"@the-draupnir-project/matrix-protection-suite": patch +"draupnir": patch +--- + +Fixed a bug where User policies of any recommendation would result in the +MemberBanSynchronisationProtection banning users. This is was a particularly +important issue for compatibility with Meowlnir. diff --git a/packages/matrix-protection-suite/src/Protection/StandardProtections/MemberBanSynchronisation/MemberBanSynchronisation.ts b/packages/matrix-protection-suite/src/Protection/StandardProtections/MemberBanSynchronisation/MemberBanSynchronisation.ts index 43ad19f1..464f4db3 100644 --- a/packages/matrix-protection-suite/src/Protection/StandardProtections/MemberBanSynchronisation/MemberBanSynchronisation.ts +++ b/packages/matrix-protection-suite/src/Protection/StandardProtections/MemberBanSynchronisation/MemberBanSynchronisation.ts @@ -27,7 +27,7 @@ import { import { RoomMembershipRevision } from "../../../Membership/MembershipRevision"; import { ProtectedRoomsSet } from "../../ProtectedRoomsSet"; import { PolicyRuleType } from "../../../MatrixTypes/PolicyEvents"; -import { Recommendation } from "../../../PolicyList/PolicyRule"; +import { PolicyRule, Recommendation } from "../../../PolicyList/PolicyRule"; import { MultipleErrors } from "../../../Interface/MultipleErrors"; import { UserConsequences } from "../../Capability/StandardCapability/UserConsequences"; import "../../Capability/StandardCapability/UserConsequences"; // need this to load the interface. @@ -45,14 +45,26 @@ import { StandardMemberBanIntentProjection, } from "./MemberBanIntentProjection"; -function revisionMatchesWithUserRules( +function isRecommendationWorthBanning(policyRule: PolicyRule) { + return ( + policyRule.recommendation === Recommendation.Ban || + policyRule.recommendation === Recommendation.Takedown + ); +} + +function revisionMatchesWithUserBans( revision: SetMembershipPolicyRevision ): MemberPolicyMatches[] { - return revision - .allMembersWithRules() - .filter((match) => - match.policies.some((policy) => policy.kind === PolicyRuleType.User) - ); + return revision.allMembersWithRules().filter((match) => + match.policies.some( + (policy) => + // We only ban for user policies and not server ones at the time being, + // As this keeps ACL non-disruptive when it is necessary to temporarily + // ban a server. + policy.kind === PolicyRuleType.User && + isRecommendationWorthBanning(policy) + ) + ); } export type MemberBanSynchronisationProtectionDescription = @@ -148,7 +160,7 @@ export class MemberBanSynchronisationProtection revision: SetMembershipPolicyRevision ): Promise> { const result = await this.userConsequences.consequenceForUsersInRoomSet( - revisionMatchesWithUserRules(revision) + revisionMatchesWithUserBans(revision) ); if (isError(result)) { return result; @@ -162,7 +174,7 @@ export class MemberBanSynchronisationProtection (async () => { await this.userConsequences.consequenceForUsersInRoom( room.toRoomIDOrAlias(), - revisionMatchesWithUserRules( + revisionMatchesWithUserBans( this.protectedRoomsSet.setPoliciesMatchingMembership.currentRevision ) );