From 99ad7ae5e6c1b2ac930bc0ec20cf028051fd9553 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 19 Nov 2016 18:28:59 +0100 Subject: mod_mam: Filter out spoofed XEP-0359 tags --- plugins/mod_mam/mod_mam.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'plugins') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 2606f861..cb7613b8 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -16,6 +16,7 @@ local prefs_to_stanza = module:require"mamprefsxml".tostanza; local prefs_from_stanza = module:require"mamprefsxml".fromstanza; local jid_bare = require "util.jid".bare; local jid_split = require "util.jid".split; +local jid_prepped_split = require "util.jid".prepped_split; local dataform = require "util.dataforms".new; local host = module.host; @@ -238,6 +239,17 @@ local function message_handler(event, c2s) -- And who are they chatting with? local with = jid_bare(c2s and orig_to or orig_from); + -- Filter out that claim to be from us + stanza:maptags(function (tag) + if tag.name == "stanza-id" and tag.attr.xmlns == "urn:xmpp:sid:0" then + local by_user, by_host, res = prepped_split(tag.attr.by); + if not res and by_host == module.host and by_user == store_user then + return nil; + end + end + return tag; + end); + -- We store chat messages or normal messages that have a body if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); -- cgit v1.2.3