aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2022-01-20 13:02:24 +0100
committerKim Alvefur <zash@zash.se>2022-01-20 13:02:24 +0100
commit991e6531ab3085b1265c0cf91ea84459da606291 (patch)
treed7a516c64c433e7d2529df23a86008cc8046588a
parent41e0ddd7910240fba9feec42c205d7a2506ac971 (diff)
parent785d3273084026d308cfa92edf8832e24ec4193e (diff)
downloadprosody-991e6531ab3085b1265c0cf91ea84459da606291.tar.gz
prosody-991e6531ab3085b1265c0cf91ea84459da606291.zip
Merge 0.11->trunk
-rw-r--r--util/xml.lua18
1 files changed, 5 insertions, 13 deletions
diff --git a/util/xml.lua b/util/xml.lua
index 549ab104..9322f3ad 100644
--- a/util/xml.lua
+++ b/util/xml.lua
@@ -65,27 +65,19 @@ local parse_xml = (function()
function handler:EndElement()
stanza:up();
end
- local parser;
-- SECURITY: These two handlers, especially the Doctype one, are required to prevent exploits such as Billion Laughs.
- function handler:StartDoctypeDecl()
- if not parser.stop or not parser:stop() then
- error("Failed to abort parsing");
- end
- end
- function handler:ProcessingInstruction()
+ local function restricted_handler(parser)
if not parser.stop or not parser:stop() then
error("Failed to abort parsing");
end
end
+ handler.StartDoctypeDecl = restricted_handler;
+ handler.ProcessingInstruction = restricted_handler;
if not options or not options.allow_comments then
-- NOTE: comments are generally harmless and can be useful when parsing configuration files or other data, even user-provided data
- function handler:Comment()
- if not parser.stop or not parser:stop() then
- error("Failed to abort parsing");
- end
- end
+ handler.Comment = restricted_handler;
end
- parser = lxp.new(handler, ns_separator);
+ local parser = lxp.new(handler, ns_separator);
local ok, err, line, col = parser:parse(xml);
if ok then ok, err, line, col = parser:parse(); end
--parser:close();