From 85bc3896abcb21041bd89c7fefd96927dcfe2ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Mon, 30 Jul 2018 21:58:22 +0200 Subject: [PATCH] Handle messages without 'to' correctly --- gajim/common/modules/carbons.py | 2 +- gajim/common/modules/message.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gajim/common/modules/carbons.py b/gajim/common/modules/carbons.py index 0d9d67822..221f92e20 100644 --- a/gajim/common/modules/carbons.py +++ b/gajim/common/modules/carbons.py @@ -73,7 +73,7 @@ def parse_carbon(con, stanza): type_ = carbon.getName() to = message.getTo() frm = message.getFrom() - log.info('Received type: %s, from: %s, to: %s', type_, to, frm) + log.info('Received type: %s, from: %s', type_, frm) if type_ == 'received': sent = False diff --git a/gajim/common/modules/message.py b/gajim/common/modules/message.py index d3805a052..086a47c55 100644 --- a/gajim/common/modules/message.py +++ b/gajim/common/modules/message.py @@ -58,6 +58,23 @@ class Message: nbxmpp.NS_IBB]) def _message_received(self, con, stanza): + # https://tools.ietf.org/html/rfc6120#section-8.1.1.1 + # If the stanza does not include a 'to' address then the client MUST + # treat it as if the 'to' address were included with a value of the + # client's full JID. + # + # Implementation Note: However, if the client does + # check the 'to' address then it is suggested to check at most the + # bare JID portion (not the full JID) + + own_jid = self._con.get_own_jid().getStripped() + to = stanza.getTo() + if to is None: + stanza.setTo(own_jid) + elif not to.bareMatch(own_jid): + log.warning('Message addressed to someone else: %s', stanza) + raise nbxmpp.NodeProcessed + # Check if a child of the message contains any # namespaces that we handle in other modules. # nbxmpp executes less common handlers last @@ -118,7 +135,7 @@ class Message: if type_ == 'groupchat': archive_jid = stanza.getFrom().getStripped() else: - archive_jid = self._con.get_own_jid().getStripped() + archive_jid = own_jid if app.logger.find_stanza_id(self._account, archive_jid, stanza_id,