Comparison

plugins/mod_dialback.lua @ 4836:bda0593d3f73

mod_dialback: add better safe then sorry nameprepping to the from attribute.
author Marco Cirillo <maranda@lightwitch.org>
date Wed, 09 May 2012 11:25:22 +0000
parent 4835:751510cd558d
child 4837:9f1fb34cd7f8
comparison
equal deleted inserted replaced
4835:751510cd558d 4836:bda0593d3f73
13 13
14 local log = module._log; 14 local log = module._log;
15 15
16 local st = require "util.stanza"; 16 local st = require "util.stanza";
17 local sha256_hash = require "util.hashes".sha256; 17 local sha256_hash = require "util.hashes".sha256;
18 local nameprep = require "util.encodings".stringprep.nameprep;
18 19
19 local xmlns_stream = "http://etherx.jabber.org/streams"; 20 local xmlns_stream = "http://etherx.jabber.org/streams";
20 21
21 local dialback_requests = setmetatable({}, { __mode = 'v' }); 22 local dialback_requests = setmetatable({}, { __mode = 'v' });
22 23
75 76
76 dialback_requests[attr.from.."/"..origin.streamid] = origin; 77 dialback_requests[attr.from.."/"..origin.streamid] = origin;
77 78
78 if not origin.from_host then 79 if not origin.from_host then
79 -- Just used for friendlier logging 80 -- Just used for friendlier logging
80 origin.from_host = attr.from; 81 origin.from_host = nameprep(attr.from);
81 -- COMPAT: Fix ejabberd chopness by resetting the send function 82 -- COMPAT: Fix ejabberd chopness by resetting the send function
82 origin.log("debug", "Remote server didn't specify a from attr, resetting session.send now that we know where to knock to."); 83 if not origin.from_host then
83 origin.send = function(stanza) hosts[attr.to].events.fire_event("route/remote", { from_host = origin.to_host, to_host = origin.from_host, stanza = stanza}); end 84 origin.log("debug", "We need to know where to connect but remote server blindly refuses to tell us and to comply to specs, closing connection.");
85 origin:close("invalid-from");
86 else
87 origin.log("debug", "Remote server didn't specify a from attr, resetting session.send now that we know where to knock to.");
88 origin.send = function(stanza) hosts[attr.to].events.fire_event("route/remote", { from_host = origin.to_host, to_host = origin.from_host, stanza = stanza}); end
89 end
84 end 90 end
85 if not origin.to_host then 91 if not origin.to_host then
86 -- Just used for friendlier logging 92 -- Just used for friendlier logging
87 origin.to_host = attr.to; 93 origin.to_host = attr.to;
88 end 94 end