diff --git a/third_party/blink/renderer/core/xml/parser/xml_document_parser.cc b/third_party/blink/renderer/core/xml/parser/xml_document_parser.cc index aac93c5b62a19..ee5995d82a737 100644 --- a/third_party/blink/renderer/core/xml/parser/xml_document_parser.cc +++ b/third_party/blink/renderer/core/xml/parser/xml_document_parser.cc @@ -752,7 +752,7 @@ static void ErrorFunc(void*, const char*, ...) { // FIXME: It would be nice to display error messages somewhere. } -static void EnsureLibXMLInitialized() { +void EnsureLibXMLInitialized() { static bool did_init = false; if (did_init) return; diff --git a/third_party/blink/renderer/core/xml/parser/xml_document_parser.h b/third_party/blink/renderer/core/xml/parser/xml_document_parser.h index 8bac86e1cfb04..fad605cd859f0 100644 --- a/third_party/blink/renderer/core/xml/parser/xml_document_parser.h +++ b/third_party/blink/renderer/core/xml/parser/xml_document_parser.h @@ -238,6 +238,11 @@ class XMLDocumentParser final : public ScriptableDocumentParser, SegmentedString pending_src_; }; +// Registers Blink's libxml IO callbacks. Must be called before any libxml +// parse that may load external entities/DTDs, otherwise libxml's default +// xmlFdOpen()/open() handler is used (XXE / local file read). +void EnsureLibXMLInitialized(); + xmlDocPtr XmlDocPtrForString(Document*, const String& source, const String& url); diff --git a/third_party/blink/renderer/core/xml/xsl_style_sheet_libxslt.cc b/third_party/blink/renderer/core/xml/xsl_style_sheet_libxslt.cc index 4bc346b1186f6..ef55f4d6f42c2 100644 --- a/third_party/blink/renderer/core/xml/xsl_style_sheet_libxslt.cc +++ b/third_party/blink/renderer/core/xml/xsl_style_sheet_libxslt.cc @@ -29,6 +29,7 @@ #include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/loader/resource/xsl_style_sheet_resource.h" +#include "third_party/blink/renderer/core/xml/parser/xml_document_parser.h" #include "third_party/blink/renderer/core/xml/parser/xml_document_parser_scope.h" #include "third_party/blink/renderer/core/xml/parser/xml_parser_input.h" #include "third_party/blink/renderer/core/xml/xsl_style_sheet.h" @@ -120,6 +121,12 @@ void XSLStyleSheet::ClearDocuments() { } bool XSLStyleSheet::ParseString(const String& source) { + // Ensure Blink's libxml IO callbacks (MatchFunc/OpenFunc) are registered + // before parsing. Without this, if ParseString is the first libxml call in + // the process, libxml's default xmlFdOpen()/open() handler resolves external + // entities directly from the filesystem (XXE). + EnsureLibXMLInitialized(); + // Parse in a single chunk into an xmlDocPtr if (!stylesheet_doc_taken_) xmlFreeDoc(stylesheet_doc_);