Comparison

plugins/mod_mam/mod_mam.lua @ 7845:eeb22f912577

mod_mam: Filter out spoofed XEP-0359 tags
author Kim Alvefur <zash@zash.se>
date Sat, 19 Nov 2016 18:28:59 +0100
parent 7844:316f5166eedb
child 7846:22275bc5744a
comparison
equal deleted inserted replaced
7844:316f5166eedb 7845:eeb22f912577
14 local set_prefs = module:require"mamprefs".set; 14 local set_prefs = module:require"mamprefs".set;
15 local prefs_to_stanza = module:require"mamprefsxml".tostanza; 15 local prefs_to_stanza = module:require"mamprefsxml".tostanza;
16 local prefs_from_stanza = module:require"mamprefsxml".fromstanza; 16 local prefs_from_stanza = module:require"mamprefsxml".fromstanza;
17 local jid_bare = require "util.jid".bare; 17 local jid_bare = require "util.jid".bare;
18 local jid_split = require "util.jid".split; 18 local jid_split = require "util.jid".split;
19 local jid_prepped_split = require "util.jid".prepped_split;
19 local dataform = require "util.dataforms".new; 20 local dataform = require "util.dataforms".new;
20 local host = module.host; 21 local host = module.host;
21 22
22 local rm_load_roster = require "core.rostermanager".load_roster; 23 local rm_load_roster = require "core.rostermanager".load_roster;
23 24
236 -- Whos storage do we put it in? 237 -- Whos storage do we put it in?
237 local store_user = c2s and origin.username or jid_split(orig_to); 238 local store_user = c2s and origin.username or jid_split(orig_to);
238 -- And who are they chatting with? 239 -- And who are they chatting with?
239 local with = jid_bare(c2s and orig_to or orig_from); 240 local with = jid_bare(c2s and orig_to or orig_from);
240 241
242 -- Filter out <stanza-id> that claim to be from us
243 stanza:maptags(function (tag)
244 if tag.name == "stanza-id" and tag.attr.xmlns == "urn:xmpp:sid:0" then
245 local by_user, by_host, res = prepped_split(tag.attr.by);
246 if not res and by_host == module.host and by_user == store_user then
247 return nil;
248 end
249 end
250 return tag;
251 end);
252
241 -- We store chat messages or normal messages that have a body 253 -- We store chat messages or normal messages that have a body
242 if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then 254 if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then
243 log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); 255 log("debug", "Not archiving stanza: %s (type)", stanza:top_tag());
244 return; 256 return;
245 end 257 end