mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-17239: Disable external entities in SAX parser (GH-9217)
The SAX parser no longer processes general external entities by default to increase security. Before, the parser created network connections to fetch remote files or loaded local files from the file system for DTD and entities. Signed-off-by: Christian Heimes <christian@python.org> https://bugs.python.org/issue17239
This commit is contained in:
parent
9fb051f032
commit
17b1d5d4e3
9 changed files with 120 additions and 5 deletions
|
@ -91,6 +91,12 @@ ENTITY_XML = """\
|
|||
<document>&entity;</document>
|
||||
"""
|
||||
|
||||
EXTERNAL_ENTITY_XML = """\
|
||||
<!DOCTYPE points [
|
||||
<!ENTITY entity SYSTEM "file:///non-existing-file.xml">
|
||||
]>
|
||||
<document>&entity;</document>
|
||||
"""
|
||||
|
||||
def checkwarnings(*filters, quiet=False):
|
||||
def decorator(test):
|
||||
|
@ -861,6 +867,13 @@ class ElementTreeTest(unittest.TestCase):
|
|||
root = parser.close()
|
||||
self.serialize_check(root, '<document>text</document>')
|
||||
|
||||
# 4) external (SYSTEM) entity
|
||||
|
||||
with self.assertRaises(ET.ParseError) as cm:
|
||||
ET.XML(EXTERNAL_ENTITY_XML)
|
||||
self.assertEqual(str(cm.exception),
|
||||
'undefined entity &entity;: line 4, column 10')
|
||||
|
||||
def test_namespace(self):
|
||||
# Test namespace issues.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue