<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>Moderated Message Retraction</title>
  <abstract>This specification defines a method for groupchat moderators to retract messages of other users.</abstract>
  
<legal>
<copyright>This XMPP Extension Protocol is copyright © 1999 – 2024 by the <link url="https://xmpp.org/">XMPP Standards Foundation</link> (XSF).</copyright>
<permissions>Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.</permissions>
<warranty>## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. ##</warranty>
<liability>In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.</liability>
<conformance>This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at &lt;<link url="https://xmpp.org/about/xsf/ipr-policy">https://xmpp.org/about/xsf/ipr-policy</link>&gt; or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).</conformance>
</legal>
  <number>0425</number>
  <status>Experimental</status>
  <lastcall>2022-01-04</lastcall>
  <type>Standards Track</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XMPP IM</spec>
    <spec>XEP-0313</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>message-moderation</shortname>
  
  <author>
    <firstname>JC</firstname>
    <surname>Brand</surname>
    <email>jc@opkode.com</email>
    <jid>jc@opkode.com</jid>
  </author>

  <revision>
    <version>0.3.0</version>
    <date>2023-03-02</date>
    <initials>jcb</initials>
    <remark>
      <ul>
        <li>Remove the dependency on XEP-0422 Message Fastening</li>
        <li>Rename to 'Moderated Message Retraction' and focus only on the retraction use-case</li>
        <li>Ensure compatibility with clients that only implement XEP-0424</li>
        <li>Clarify the purpose of the &lt;reason/&gt; element</li>
      </ul>
    </remark>
  </revision>
  <revision>
    <version>0.2.1</version>
    <date>2020-01-28</date>
    <initials>vanitasvitae</initials>
    <remark>Typographical fix</remark>
  </revision>
  <revision>
    <version>0.2.0</version>
    <date>2019-11-11</date>
    <initials>jcb</initials>
    <remark>Replace the message contents with a tombstone (instead of replacing the message itself)</remark>
  </revision>
  <revision>
    <version>0.1.0</version>
    <date>2019-11-01</date>
    <initials>XEP Editor (jcb)</initials>
    <remark>Accepted by vote of Council on 2019-10-16.</remark>
  </revision>
   <revision>
    <version>0.0.1</version>
    <date>2019-09-25</date>
    <initials>jcb</initials>
    <remark><p>First draft</p></remark>
  </revision>
</header>
<section1 topic="Introduction" anchor="intro">
  <p>Occasionally, a <span class="ref"><link url="https://xmpp.org/extensions/xep-0045.html">Multi-User Chat (XEP-0045)</link></span> <note>XEP-0045: Multi-User Chat &lt;<link url="https://xmpp.org/extensions/xep-0045.html">https://xmpp.org/extensions/xep-0045.html</link>&gt;.</note> moderator might wish to moderate certain groupchat messages by, for example, retracting them from the groupchat history as part of an effort to address and remedy issues such as message spam, indecent language for the venue or exposing private third-party personal information.</p>
  <p>This XEP is designed in such a way to also allow other potential moderator actions, such as message editing, but these actions fall out of the scope of this XEP and we will only be considering message retractions.</p>
  <p>Due to the federated nature of XMPP and as with any content moderation tool, the moderation request can <strong>only be considered as a hint</strong> and clients which don't support message moderation are not obligated to enforce any such request.</p>
</section1>
<section1 topic="Discovering support" anchor="disco">
  <p>If a groupchat supports moderated message retraction, it MUST specify the 'urn:xmpp:message-moderate:1' feature in its service discovery information features as specified in <span class="ref"><link url="https://xmpp.org/extensions/xep-0030.html">Service Discovery (XEP-0030)</link></span> <note>XEP-0030: Service Discovery &lt;<link url="https://xmpp.org/extensions/xep-0030.html">https://xmpp.org/extensions/xep-0030.html</link>&gt;.</note> and the Entity Capabilities profile specified in <span class="ref"><link url="https://xmpp.org/extensions/xep-0115.html">Entity Capabilities (XEP-0115)</link></span> <note>XEP-0115: Entity Capabilities &lt;<link url="https://xmpp.org/extensions/xep-0115.html">https://xmpp.org/extensions/xep-0115.html</link>&gt;.</note>.</p>
    <example caption="Client requests information from a Multi-User Chat (MUC)"><![CDATA[
<iq type='get'
    from='romeo@montague.example/orchard'
    to='room@muc.example.com'
    id='info1'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>]]></example>
    <example caption="The MUC advertises support for moderation"><![CDATA[
<iq type='result'
    to='romeo@montague.example/home'
    from='room@muc.example.com'
    id='info1'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
...
    <feature var='urn:xmpp:message-moderate:1'/>
...
  </query>
</iq>]]></example>
</section1>
<section1 topic="Use Case" anchor="usecase">
  <p>Consider a situation where a user sends a message that may be deemed inappropriate by a groupchat moderator. The MUC will append a <span class="ref"><link url="https://xmpp.org/extensions/xep-0359.html">Unique and Stable Stanza IDs (XEP-0359)</link></span> <note>XEP-0359: Unique and Stable Stanza IDs &lt;<link url="https://xmpp.org/extensions/xep-0359.html">https://xmpp.org/extensions/xep-0359.html</link>&gt;.</note> stanza ID to the message before relaying it to all participants.</p>
  <example caption="The user's client sends a message and the MUC adds a stanza id."><![CDATA[
  <message type="groupchat" from="room@muc.example.com/oldhag" to='room@muc.example.com/macbeth' id='inappropriate-1'>
  <body>DM me for free magic potions!</body>
  <stanza-id xmlns='urn:xmpp:sid:0' id='stanza-id-1' by='room@muc.example.com'/>
</message>]]></example>

  <p>The moderator sees the message and indicates to their client that the message should be retracted. The client then sends an IQ stanza to the MUC service, requesting that the message be retracted.</p>
  <p>An optional &lt;reason/&gt; element may be included inside the &lt;moderate/&gt; element, to provide a human-readable explanation why the message was retracted.</p>

  <example caption="The moderator's client sends an IQ stanza to the MUC service"><![CDATA[
<iq type='set' to='room@muc.example.com' id='retract-request-1'>
  <moderate id="stanza-id-1" xmlns='urn:xmpp:message-moderate:1'>
    <retract xmlns='urn:xmpp:message-retract:1'/>
    <reason>This message contains inappropriate content for this forum</reason>
  </moderate>
</iq>]]></example>

  <section2 topic="Success case" anchor="usecase-success">

  <p>If the moderator is allowed to moderate the message, the MUC will send a message stanza to all participants (including the moderator), indicating that the message has been retracted and by whom.</p>
  <p>This message will use <span class="ref"><link url="https://xmpp.org/extensions/xep-0424.html">Message Retraction (XEP-0424)</link></span> <note>XEP-0424: Message Retraction &lt;<link url="https://xmpp.org/extensions/xep-0424.html">https://xmpp.org/extensions/xep-0424.html</link>&gt;.</note> to indicate that it is a retraction, and will refer to the retracted message by its XEP-0359 Stanza ID. Care must be taken to use the stanza ID that was added by the MUC, i.e. which has a "by" attribute set to the MUC JID, and not some other stanza ID. The client MUST check that the correct stanza ID was used and ignore the stanza if not.</p>
  <p>Inside the &lt;retract/&gt; element is a &lt;moderated/&gt; element indicating that the retraction was a moderator action, as well as an optional reason.</p>

<example caption="The MUC sends a moderation message to all participants"><![CDATA[
<message type="groupchat" id='retraction-id-1' from='room@muc.example.com' to="room@muc.example.com/macbeth">
  <retract id="stanza-id-1" xmlns='urn:xmpp:message-retract:1'>
    <moderated by='room@muc.example.com/macbeth' xmlns='urn:xmpp:message-moderate:1'>
      <occupant-id xmlns="urn:xmpp:occupant-id:0" id="dd72603deec90a38ba552f7c68cbcc61bca202cd" />
    </moderated>
    <reason>This message contains inappropriate content for this forum</reason>
  </retract>
</message>]]></example>

  <p>The MUC also responds with an IQ "result" stanza.</p>

  <example caption="The MUC responds to the IQ stanza"><![CDATA[
<iq type='result' to='juliet@montague.example/home' id='retract-request-1'></iq>]]></example>
  </section2>

  <section2 topic="Error case" anchor="usecase-error">
    <p>In case the message could for some reason not be retracted, the MUC responds with an IQ stanza of type error.</p>
  <example caption="The MUC responds with an error stanza"><![CDATA[
<iq type='error' to='room@muc.example.com/macbeth' id='retract-request-1'>
<error type='modify'>
  <forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  <text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>
    Only moderators are allowed to moderate other participants' messages
  </text>
</error>
</iq>]]></example>
  </section2>
</section1>

<section1 topic="Tombstones" anchor="tombstones">
  <p>A <span class="ref"><link url="https://xmpp.org/extensions/xep-0313.html">Message Archive Management (XEP-0313)</link></span> <note>XEP-0313: Message Archive Management &lt;<link url="https://xmpp.org/extensions/xep-0313.html">https://xmpp.org/extensions/xep-0313.html</link>&gt;.</note> service MAY replace the contents of a message, that was retracted due to moderation, with a 'tombstone' similar to the one described in <span class="ref"><link url="https://xmpp.org/extensions/xep-0424.html">Message Retraction (XEP-0424)</link></span> <note>XEP-0424: Message Retraction &lt;<link url="https://xmpp.org/extensions/xep-0424.html">https://xmpp.org/extensions/xep-0424.html</link>&gt;.</note>.</p>
  <p>The archiving service replaces the message contents (i.e. the &lt;body/&gt; and any related elements which might leak information about the original message) with a &lt;retracted/&gt; element which in turn contains a &lt;moderated/&gt; element.</p>
  <p>Note the past tense in the element names, e.g. "retracted" instead of just "retract", to indicate that the retraction has already been executed and that this is therefore a tombstone and not an action that should be applied.</p>
  <p>The &lt;moderated/&gt; element SHOULD have a 'by' attribute specifying the JID of the moderating entity. There might however be cases where it's preferable to not specify which JID was responsible for the moderation, for example when the moderation happens in an automated manner.</p>
  <p>If the message was sent in a semi-anonymous MUC, the occupant id from <span class="ref"><link url="https://xmpp.org/extensions/xep-0421.html">Anonymous unique occupant identifiers for MUCs (XEP-0421)</link></span> <note>XEP-0421: Anonymous unique occupant identifiers for MUCs &lt;<link url="https://xmpp.org/extensions/xep-0421.html">https://xmpp.org/extensions/xep-0421.html</link>&gt;.</note> SHOULD be included for the moderator in the &lt;moderated/&gt; element and for the original (retracted) message author in the &lt;message/&gt; element.</p>

  <example caption="Retracted groupchat message tombstone in a MAM result"><![CDATA[
<message id='aeb213' to='room@muc.example.com/macbeth'>
  <result xmlns='urn:xmpp:mam:2' queryid='f28' id='stanza-id-1'>
    <forwarded xmlns='urn:xmpp:forward:0'>
      <delay xmlns='urn:xmpp:delay' stamp='2019-09-20T23:18:41Z'/>
      <message type="groupchat" from="room@muc.example.com/oldhag" to="room@muc.example.com/macbeth" id="message-id-1">
        <occupant-id xmlns="urn:xmpp:occupant-id:0" id="ef73b09de9c90a38ba552f7c68cbeef1dca24429" />
        <retracted stamp='2019-09-20T23:19:12Z' xmlns='urn:xmpp:message-retract:1'>
          <moderated by="witch@shakespeare.example" xmlns="urn:xmpp:message-moderate:1">
            <occupant-id xmlns="urn:xmpp:occupant-id:0" id="dd72603deec90a38ba552f7c68cbcc61bca202cd" />
          </moderated>
          <reason>This message contains inappropriate content for this forum</reason>
        </retracted>
      </message>
    </forwarded>
  </result>
</message>]]></example>
</section1>

<section1 topic="Business Rules" anchor="rules">
  <p>A moderator MUST NOT send a moderation request for a message with non-messaging payloads. For example, a moderator MUST NOT moderate a roster item exchange request or a file transfer part.</p>
  <p>In MUCs, only moderation messages (not tombstones, but messages containing the &lt;moderate/&gt; element) received from the MUC service itself are legitimate, all other such messages MUST be discarded.</p>
  <p>The MUC or other service that supports message retraction SHOULD prevent further distribution of a moderated retracted message and the archiving service MAY replace the retracted message with a tombstone.</p>
</section1>
<section1 topic="Security Considerations" anchor="security">
  <p>There can never be a guarantee that a moderated message will appear as such in all clients. Clients should therefore, when possible, inform users that no such guarantee exists.</p>
  <p>To prevent message spoofing, it's very important to check that the moderation message comes from the MUC service (as explained in the  <link url="#rules">Business Rules</link> section).</p>
</section1>
<section1 topic="IANA Considerations" anchor="iana">
  <p>None.</p>
</section1>
<section1 topic="XMPP Registrar Considerations" anchor="registrar">
  <section2 topic="Protocol Namespaces" anchor="ns">
    <p>The <span class="ref"><link url="https://xmpp.org/registrar/">XMPP Registrar</link></span> <note>The XMPP Registrar maintains a list of reserved protocol namespaces as well as registries of parameters used in the context of XMPP extension protocols approved by the XMPP Standards Foundation. For further information, see &lt;<link url="https://xmpp.org/registrar/">https://xmpp.org/registrar/</link>&gt;.</note> includes 'urn:xmpp:message-moderate:1' in its registry of protocol namespaces (see &lt;<link url="https://xmpp.org/registrar/namespaces.html">https://xmpp.org/registrar/namespaces.html</link>&gt;).</p>
    <ul>
      <li>urn:xmpp:message-moderate:1</li>
    </ul>
  </section2>
  <section2 topic="Protocol Versioning" anchor="registrar-versioning">
    <p>If the protocol defined in this specification undergoes a revision that is not fully backwards-compatible with an older version, the XMPP Registrar shall increment the protocol version number found at the end of the XML namespaces defined herein, as described in Section 4 of <cite>XEP-0053</cite>.</p>
  </section2>
</section1>
<section1 topic="XML Schema" anchor="schema">
  <code><![CDATA[
<?xml version='1.0' encoding='UTF-8'?>

<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='urn:xmpp:message-moderate:1'
    xmlns='urn:xmpp:message-moderate:1'
    elementFormDefault='qualified'>

  <xs:element name='moderate'>
    <xs:attribute name='id' type='xs:string' use='required'/>
  </xs:element>

  <xs:element name='moderated'>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base='xs:string'>
          <xs:attribute name='by' type='xs:string'/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>

</xs:schema>
    ]]></code>
</section1>
</xep>
