From a671cff96413f6900cf3217e630ba78422d8e18a Mon Sep 17 00:00:00 2001 From: John Hernandez <129467592+H3rnand3zzz@users.noreply.github.com> Date: Mon, 6 Nov 2023 20:54:58 +0100 Subject: [PATCH] Improve XEP-0308 compliance Disallow correcting historical MUC messages, as the XEP-308 requires. Previous changes introduce problem with "Illicit LMC attempt from conference@server/user for message from user" During investigation it was revealed that XEP does not recommend support of historical MUC messages correction. ``` When used in a Multi-User Chat (XEP-0045) context, corrections must not be allowed (by the receiver) for messages received before the sender joined the room - particularly a full JID leaving the room then rejoining and correcting a message SHOULD be disallowed, as the entity behind the full JID in the MUC may have changed. ``` https://xmpp.org/extensions/xep-0308.html#rules XEP details mentioned by @jubalh Bug discovered and solution improved by @jaeckel --- src/xmpp/message.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 6a592646..dbfe78b1 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -1101,14 +1101,6 @@ _handle_groupchat(xmpp_stanza_t* const stanza) } } - xmpp_stanza_t* replace_id_stanza = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_LAST_MESSAGE_CORRECTION); - if (replace_id_stanza) { - const char* replace_id = xmpp_stanza_get_id(replace_id_stanza); - if (replace_id) { - message->replace_id = strdup(replace_id); - } - } - message->body = xmpp_message_get_body(stanza); // check omemo encryption @@ -1153,6 +1145,14 @@ _handle_groupchat(xmpp_stanza_t* const stanza) if (is_muc_history) { sv_ev_room_history(message); } else { + // XEP-0308 states: `corrections must not be allowed (by the receiver) for messages received before the sender joined the room` + xmpp_stanza_t* replace_id_stanza = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_LAST_MESSAGE_CORRECTION); + if (replace_id_stanza) { + const char* replace_id = xmpp_stanza_get_id(replace_id_stanza); + if (replace_id) { + message->replace_id = strdup(replace_id); + } + } sv_ev_room_message(message); }