2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2016-11-20 10:09:20 -05:00
|
|
|
require_relative "xml_mini_engine_test"
|
2009-03-15 06:32:29 -04:00
|
|
|
|
2016-11-20 10:09:20 -05:00
|
|
|
XMLMiniEngineTest.run_with_platform("java") do
|
|
|
|
class JDOMEngineTest < XMLMiniEngineTest
|
2017-05-15 10:17:28 -04:00
|
|
|
FILES_DIR = File.expand_path("../fixtures/xml", __dir__)
|
2013-02-07 21:48:22 -05:00
|
|
|
|
|
|
|
def test_not_allowed_to_expand_entities_to_files
|
|
|
|
attack_xml = <<-EOT
|
|
|
|
<!DOCTYPE member [
|
|
|
|
<!ENTITY a SYSTEM "file://#{FILES_DIR}/jdom_include.txt">
|
|
|
|
]>
|
|
|
|
<member>x&a;</member>
|
|
|
|
EOT
|
2016-08-06 12:03:25 -04:00
|
|
|
assert_equal "x", Hash.from_xml(attack_xml)["member"]
|
2013-02-07 21:48:22 -05:00
|
|
|
end
|
|
|
|
|
2013-03-19 07:52:20 -04:00
|
|
|
def test_not_allowed_to_expand_parameter_entities_to_files
|
2013-02-07 21:48:22 -05:00
|
|
|
attack_xml = <<-EOT
|
|
|
|
<!DOCTYPE member [
|
|
|
|
<!ENTITY % b SYSTEM "file://#{FILES_DIR}/jdom_entities.txt">
|
|
|
|
%b;
|
|
|
|
]>
|
|
|
|
<member>x&a;</member>
|
|
|
|
EOT
|
|
|
|
assert_raise Java::OrgXmlSax::SAXParseException do
|
2016-08-06 12:03:25 -04:00
|
|
|
assert_equal "x", Hash.from_xml(attack_xml)["member"]
|
2013-02-07 21:48:22 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_not_allowed_to_load_external_doctypes
|
|
|
|
attack_xml = <<-EOT
|
|
|
|
<!DOCTYPE member SYSTEM "file://#{FILES_DIR}/jdom_doctype.dtd">
|
|
|
|
<member>x&a;</member>
|
|
|
|
EOT
|
2016-08-06 12:03:25 -04:00
|
|
|
assert_equal "x", Hash.from_xml(attack_xml)["member"]
|
2013-02-07 21:48:22 -05:00
|
|
|
end
|
|
|
|
|
2016-11-19 10:59:24 -05:00
|
|
|
private
|
2016-11-20 09:06:17 -05:00
|
|
|
def engine
|
|
|
|
"JDOM"
|
|
|
|
end
|
2009-03-15 06:32:29 -04:00
|
|
|
|
2016-11-20 09:06:17 -05:00
|
|
|
def expansion_attack_error
|
|
|
|
Java::OrgXmlSax::SAXParseException
|
|
|
|
end
|
|
|
|
|
|
|
|
def extended_engine?
|
|
|
|
false
|
|
|
|
end
|
2009-03-15 06:32:29 -04:00
|
|
|
end
|
|
|
|
end
|