diff --git a/lib/ndr_import/file/xml.rb b/lib/ndr_import/file/xml.rb index 2c7c631..5dfd414 100644 --- a/lib/ndr_import/file/xml.rb +++ b/lib/ndr_import/file/xml.rb @@ -57,8 +57,9 @@ def stream_metadata_values def metadata_from_stream(xpath) cursor = Cursor.new(xpath, false) - # If markup isn't well-formed, try to work around it: - options = Nokogiri::XML::ParseOptions::RECOVER + # If markup isn't well-formed, try to work around it (but keep NONET, + # so external entities/DTDs can't trigger network requests): + options = Nokogiri::XML::ParseOptions::RECOVER | Nokogiri::XML::ParseOptions::NONET reader = Nokogiri::XML::Reader(@stream, nil, @encoding, options) reader.each do |node| diff --git a/lib/ndr_import/helpers/file/xml_streaming.rb b/lib/ndr_import/helpers/file/xml_streaming.rb index 4a7c929..709c7e9 100644 --- a/lib/ndr_import/helpers/file/xml_streaming.rb +++ b/lib/ndr_import/helpers/file/xml_streaming.rb @@ -183,8 +183,9 @@ def stream_xml_nodes(io, node_xpath, pattern_match_xpath, encoding = nil) # Track nesting as the cursor moves through the document: cursor = Cursor.new(node_xpath, pattern_match_xpath) - # If markup isn't well-formed, try to work around it: - options = Nokogiri::XML::ParseOptions::RECOVER + # If markup isn't well-formed, try to work around it (but keep NONET, + # so external entities/DTDs can't trigger network requests): + options = Nokogiri::XML::ParseOptions::RECOVER | Nokogiri::XML::ParseOptions::NONET reader = Nokogiri::XML::Reader(io, nil, encoding, options) reader.each do |node|