plugin XEP-0313: check message origin:

Check that "from" attribute of the forwarded message is coming from the service.
This commit is contained in:
Goffi 2026-08-18 18:44:19 +02:00
commit 14dbca530b

View file

@ -407,6 +407,26 @@ class XEP_0313:
f"{mess_elt.toXml()}"
)
raise exceptions.DataError("Invalid element")
if service is not None:
# the forwarded message must come from the queried service, else a
# malicious service could inject messages from arbitrary JIDs in its
# archive (e.g., in a MUC archive, "from" MUST be the sender's occupant
# JID)
try:
fwd_from_jid = jid.JID(fwd_message_elt["from"])
except (KeyError, jid.InvalidFormat):
log.warning(
f'MAM message from {service_jid} has an invalid "from", '
f"hack attempt?\n{mess_elt.toXml()}"
)
raise exceptions.DataError("Invalid element")
if fwd_from_jid.userhostJID() != service_jid:
log.warning(
f'MAM message from {service_jid} has a "from" which is not from '
f"the service ({fwd_from_jid.full()}), hack attempt?\n"
f"{mess_elt.toXml()}"
)
raise exceptions.DataError("Invalid element")
stanza_id = self._sid.get_stanza_id(fwd_message_elt, service_jid)
if stanza_id is None:
# not stanza-id element is present, we add one so message