File CVE-2022-48565-plistlib-XML-vulns.patch of Package python (Revision 381d91ea0ab10fc5235c75951d42564a)
Currently displaying revision 381d91ea0ab10fc5235c75951d42564a , Show latest
81
1
From 4d8f9e2e4461de92bd1e0c92ed433480d761670f Mon Sep 17 00:00:00 2001
2
From: Ned Deily <nad@python.org>
3
Date: Mon, 19 Oct 2020 22:36:27 -0400
4
Subject: [PATCH] bpo-42051: Reject XML entity declarations in plist files
5
(GH-22760) (GH-22801)
6
7
Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
8
(cherry picked from commit e512bc799e3864fe3b1351757261762d63471efc)
9
10
Co-authored-by: Ned Deily <nad@python.org>
11
---
12
Lib/plistlib.py | 10 +++++
13
Lib/test/test_plistlib.py | 19 ++++++++++
14
Misc/NEWS.d/next/Security/2020-10-19-10-56-27.bpo-42051.EU_B7u.rst | 3 +
15
3 files changed, 32 insertions(+)
16
create mode 100644 Misc/NEWS.d/next/Security/2020-10-19-10-56-27.bpo-42051.EU_B7u.rst
17
18
--- a/Lib/plistlib.py
19
+++ b/Lib/plistlib.py
20
21
parser.StartElementHandler = self.handleBeginElement
22
parser.EndElementHandler = self.handleEndElement
23
parser.CharacterDataHandler = self.handleData
24
+ parser.EntityDeclHandler = self.handle_entity_decl
25
parser.ParseFile(fileobj)
26
return self.root
27
28
+ def handle_entity_decl(self, entity_name, is_parameter_entity, value,
29
+ base, system_id, public_id, notation_name):
30
+ # Reject plist files with entity declarations to avoid XML
31
+ # vulnerabilies in expat. Regular plist files don't contain
32
+ # those declerations, and Apple's plutil tool does not accept
33
+ # them either.
34
+ raise ValueError(
35
+ "XML entity declarations are not supported in plist files")
36
+
37
def handleBeginElement(self, element, attrs):
38
self.data = []
39
handler = getattr(self, "begin_" + element, None)
40
--- a/Lib/test/test_plistlib.py
41
+++ b/Lib/test/test_plistlib.py
42
43
</plist>
44
""".replace(" " * 8, "\t") # Apple as well as plistlib.py output hard tabs
45
46
+XML_PLIST_WITH_ENTITY=b'''\
47
+<?xml version="1.0" encoding="UTF-8"?>
48
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd" [
49
+ <!ENTITY entity "replacement text">
50
+ ]>
51
+<plist version="1.0">
52
+ <dict>
53
+ <key>A</key>
54
+ <string>&entity;</string>
55
+ </dict>
56
+</plist>
57
+'''
58
+
59
60
class TestPlistlib(unittest.TestCase):
61
62
63
self.assertEqual(test1, result1)
64
self.assertEqual(test2, result2)
65
66
+ def test_xml_plist_with_entity_decl(self):
67
+ with self.assertRaisesRegexp(ValueError,
68
+ "XML entity declarations are not supported"):
69
+ plistlib.readPlistFromString(XML_PLIST_WITH_ENTITY)
70
+
71
+
72
73
def test_main():
74
test_support.run_unittest(TestPlistlib)
75
--- /dev/null
76
+++ b/Misc/NEWS.d/next/Security/2020-10-19-10-56-27.bpo-42051.EU_B7u.rst
77
78
+The :mod:`plistlib` module no longer accepts entity declarations in XML
79
+plist files to avoid XML vulnerabilities. This should not affect users as
80
+entity declarations are not used in regular plist files.
81