Software /
code /
prosody
Diff
util/xml.lua @ 12203:320de3e4b579
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 20 Jan 2022 13:02:24 +0100 |
parent | 12180:53e0ae770917 |
parent | 12202:ebeb4d959fb3 |
child | 12270:c78639ee6ccb |
line wrap: on
line diff
--- a/util/xml.lua Wed Jan 19 10:28:09 2022 +0100 +++ b/util/xml.lua Thu Jan 20 13:02:24 2022 +0100 @@ -65,27 +65,19 @@ 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() + local function restricted_handler(parser) if not parser.stop or not parser:stop() then error("Failed to abort parsing"); end end - function handler:ProcessingInstruction() - 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();