Skip to content

Commit 31fdfbf

Browse files
icanhasmathronaldoussorenned-deily
committed
bpo-42051: Reject XML entity declarations in plist files (python#22760) (GC-22801)
Co-authored-by: Ronald Oussoren <[email protected]> Co-authored-by: Ned Deily <[email protected]>
1 parent 3d29963 commit 31fdfbf

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

Lib/plistlib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,16 @@ def parse(self, fileobj):
403403
parser.StartElementHandler = self.handleBeginElement
404404
parser.EndElementHandler = self.handleEndElement
405405
parser.CharacterDataHandler = self.handleData
406+
parser.EntityDeclHandler = self.handle_entity_decl
406407
parser.ParseFile(fileobj)
407408
return self.root
408409

410+
def handle_entity_decl(self, entity_name, is_parameter_entity, value, base, system_id, public_id, notation_name):
411+
# Reject plist files with entity declarations to avoid XML vulnerabilies in expat.
412+
# Regular plist files don't contain those declerations, and Apple's plutil tool does not
413+
# accept them either.
414+
raise InvalidFileException("XML entity declarations are not supported in plist files")
415+
409416
def handleBeginElement(self, element, attrs):
410417
self.data = []
411418
handler = getattr(self, "begin_" + element, None)

Lib/test/test_plistlib.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@
8686
</plist>
8787
""".replace(" " * 8, "\t") # Apple as well as plistlib.py output hard tabs
8888

89+
XML_PLIST_WITH_ENTITY=b'''\
90+
<?xml version="1.0" encoding="UTF-8"?>
91+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd" [
92+
<!ENTITY entity "replacement text">
93+
]>
94+
<plist version="1.0">
95+
<dict>
96+
<key>A</key>
97+
<string>&entity;</string>
98+
</dict>
99+
</plist>
100+
'''
101+
89102

90103
class TestPlistlib(unittest.TestCase):
91104

@@ -195,6 +208,10 @@ def test_nondictroot(self):
195208
self.assertEqual(test1, result1)
196209
self.assertEqual(test2, result2)
197210

211+
def test_xml_plist_with_entity_decl(self):
212+
with self.assertRaisesRegex(plistlib.InvalidFileException,
213+
"XML entity declarations are not supported"):
214+
plistlib.loads(XML_PLIST_WITH_ENTITY, fmt=plistlib.FMT_XML)
198215

199216
def test_main():
200217
test_support.run_unittest(TestPlistlib)

Misc/NEWS.d/2.7.18.8.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,13 @@ A flaw was found in Python, specifically within the urllib.parse module. This mo
4444
CVE-2021-4189
4545

4646
A flaw was found in Python, specifically in the FTP (File Transfer Protocol) client library in PASV (passive) mode. The issue is how the FTP client trusts the host from the PASV response by default. This flaw allows an attacker to set up a malicious FTP server that can trick FTP clients into connecting back to a given IP address and port. This vulnerability could lead to FTP client scanning ports, which otherwise would not have been possible.
47+
48+
.. bpo: 42051
49+
.. date: 2024-03-12
50+
.. nonce:
51+
.. release date: 2024-03-12
52+
.. section: Core and Builtins
53+
54+
CVE-2022-48565
55+
56+
An XML External Entity (XXE) issue was discovered in Python through 3.9.1. The plistlib module no longer accepts entity declarations in XML plist files to avoid XML vulnerabilities.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The :mod: module no longer accepts entity declarations in XML
2+
plist files to avoid XML vulnerabilities. This should not affect users as
3+
entity declarations are not used in regular plist files.

0 commit comments

Comments
 (0)