Comparison

util/xmppstream.lua @ 4275:5305a665bdd4

util.xmppstream: Reject XML comments, processing instructions and (if supported by LuaExpat) DTDs. If not supported, log a warning.
author Matthew Wild <mwild1@gmail.com>
date Wed, 01 Jun 2011 23:02:10 +0100
parent 4012:a4f8e226bc4a
child 4278:67ce42aa7419
comparison
equal deleted inserted replaced
4260:403aba5e49d5 4275:5305a665bdd4
13 local tostring = tostring; 13 local tostring = tostring;
14 local t_insert = table.insert; 14 local t_insert = table.insert;
15 local t_concat = table.concat; 15 local t_concat = table.concat;
16 16
17 local default_log = require "util.logger".init("xmppstream"); 17 local default_log = require "util.logger".init("xmppstream");
18
19 -- COMPAT: w/LuaExpat 1.1.0
20 local lxp_supports_doctype = pcall(lxp.new, { StartDoctypeDecl = false });
21
22 if not lxp_supports_doctype then
23 default_log("warn", "The version of LuaExpat on your system leaves Prosody "
24 .."vulnerable to denial-of-service attacks. You should upgrade to "
25 .."LuaExpat 1.1.1 or higher as soon as possible. See "
26 .."http://prosody.im/doc/depends#luaexpat for more information.");
27 end
18 28
19 local error = error; 29 local error = error;
20 30
21 module "xmppstream" 31 module "xmppstream"
22 32
147 cb_error(session, "parse-error", "unexpected-element-close", name); 157 cb_error(session, "parse-error", "unexpected-element-close", name);
148 end 158 end
149 stanza, chardata = nil, {}; 159 stanza, chardata = nil, {};
150 end 160 end
151 end 161 end
162
163 local function restricted_handler()
164 cb_error(session, "parse-error", "restricted-xml", "Restricted XML, see RFC 6120 section 11.1.");
165 end
166
167 if lxp_supports_doctype then
168 xml_handlers.StartDoctypeDecl = restricted_handler;
169 end
170 xml_handlers.Comment = restricted_handler;
171 xml_handlers.StartCdataSection = restricted_handler;
172 xml_handlers.ProcessingInstruction = restricted_handler;
152 173
153 local function reset() 174 local function reset()
154 stanza, chardata = nil, {}; 175 stanza, chardata = nil, {};
155 end 176 end
156 177