Blame SOURCES/00360-CVE-2021-3426.patch

4d7d43
From 5b1e50256b6532667b6d31debc350f6c7d3f30aa Mon Sep 17 00:00:00 2001
4d7d43
From: "Miss Islington (bot)"
4d7d43
 <31488909+miss-islington@users.noreply.github.com>
4d7d43
Date: Mon, 29 Mar 2021 08:40:53 -0700
4d7d43
Subject: [PATCH] bpo-42988: Remove the pydoc getfile feature (GH-25015)
4d7d43
 (GH-25067)
4d7d43
MIME-Version: 1.0
4d7d43
Content-Type: text/plain; charset=UTF-8
4d7d43
Content-Transfer-Encoding: 8bit
4d7d43
4d7d43
CVE-2021-3426: Remove the "getfile" feature of the pydoc module which
4d7d43
could be abused to read arbitrary files on the disk (directory
4d7d43
traversal vulnerability). Moreover, even source code of Python
4d7d43
modules can contain sensitive data like passwords. Vulnerability
4d7d43
reported by David Schwörer.
4d7d43
(cherry picked from commit 9b999479c0022edfc9835a8a1f06e046f3881048)
4d7d43
4d7d43
Co-authored-by: Victor Stinner <vstinner@python.org>
4d7d43
---
4d7d43
 Lib/pydoc.py                                   | 18 ------------------
4d7d43
 Lib/test/test_pydoc.py                         |  6 ------
4d7d43
 .../2021-03-24-14-16-56.bpo-42988.P2aNco.rst   |  4 ++++
4d7d43
 3 files changed, 4 insertions(+), 24 deletions(-)
4d7d43
 create mode 100644 Misc/NEWS.d/next/Security/2021-03-24-14-16-56.bpo-42988.P2aNco.rst
4d7d43
4d7d43
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
4d7d43
index b521a5504728c4..5247ef9ea27aa1 100644
4d7d43
--- a/Lib/pydoc.py
4d7d43
+++ b/Lib/pydoc.py
4d7d43
@@ -2312,9 +2312,6 @@ def page(self, title, contents):
4d7d43
 %s</head><body bgcolor="#f0f0f8">%s
%s
4d7d43
 </body></html>''' % (title, css_link, html_navbar(), contents)
4d7d43
 
4d7d43
-        def filelink(self, url, path):
4d7d43
-            return '%s' % (url, path)
4d7d43
-
4d7d43
 
4d7d43
     html = _HTMLDoc()
4d7d43
 
4d7d43
@@ -2400,19 +2397,6 @@ def bltinlink(name):
4d7d43
             'key = %s' % key, '#ffffff', '#ee77aa', '
'.join(results))
4d7d43
         return 'Search Results', contents
4d7d43
 
4d7d43
-    def html_getfile(path):
4d7d43
-        """Get and display a source file listing safely."""
4d7d43
-        path = urllib.parse.unquote(path)
4d7d43
-        with tokenize.open(path) as fp:
4d7d43
-            lines = html.escape(fp.read())
4d7d43
-        body = '
%s
' % lines
4d7d43
-        heading = html.heading(
4d7d43
-            '<big><big>File Listing</big></big>',
4d7d43
-            '#ffffff', '#7799ee')
4d7d43
-        contents = heading + html.bigsection(
4d7d43
-            'File: %s' % path, '#ffffff', '#ee77aa', body)
4d7d43
-        return 'getfile %s' % path, contents
4d7d43
-
4d7d43
     def html_topics():
4d7d43
         """Index of topic texts available."""
4d7d43
 
4d7d43
@@ -2504,8 +2488,6 @@ def get_html_page(url):
4d7d43
                 op, _, url = url.partition('=')
4d7d43
                 if op == "search?key":
4d7d43
                     title, content = html_search(url)
4d7d43
-                elif op == "getfile?key":
4d7d43
-                    title, content = html_getfile(url)
4d7d43
                 elif op == "topic?key":
4d7d43
                     # try topics first, then objects.
4d7d43
                     try:
4d7d43
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
4d7d43
index 00803d3305cb53..49bc3eb164b19c 100644
4d7d43
--- a/Lib/test/test_pydoc.py
4d7d43
+++ b/Lib/test/test_pydoc.py
4d7d43
@@ -1052,18 +1052,12 @@ def test_url_requests(self):
4d7d43
             ("topic?key=def", "Pydoc: KEYWORD def"),
4d7d43
             ("topic?key=STRINGS", "Pydoc: TOPIC STRINGS"),
4d7d43
             ("foobar", "Pydoc: Error - foobar"),
4d7d43
-            ("getfile?key=foobar", "Pydoc: Error - getfile?key=foobar"),
4d7d43
             ]
4d7d43
 
4d7d43
         with self.restrict_walk_packages():
4d7d43
             for url, title in requests:
4d7d43
                 self.call_url_handler(url, title)
4d7d43
 
4d7d43
-            path = string.__file__
4d7d43
-            title = "Pydoc: getfile " + path
4d7d43
-            url = "getfile?key=" + path
4d7d43
-            self.call_url_handler(url, title)
4d7d43
-
4d7d43
 
4d7d43
 class TestHelper(unittest.TestCase):
4d7d43
     def test_keywords(self):
4d7d43
diff --git a/Misc/NEWS.d/next/Security/2021-03-24-14-16-56.bpo-42988.P2aNco.rst b/Misc/NEWS.d/next/Security/2021-03-24-14-16-56.bpo-42988.P2aNco.rst
4d7d43
new file mode 100644
4d7d43
index 00000000000000..4b42dd05305a83
4d7d43
--- /dev/null
4d7d43
+++ b/Misc/NEWS.d/next/Security/2021-03-24-14-16-56.bpo-42988.P2aNco.rst
4d7d43
@@ -0,0 +1,4 @@
4d7d43
+CVE-2021-3426: Remove the ``getfile`` feature of the :mod:`pydoc` module which
4d7d43
+could be abused to read arbitrary files on the disk (directory traversal
4d7d43
+vulnerability). Moreover, even source code of Python modules can contain
4d7d43
+sensitive data like passwords. Vulnerability reported by David Schwörer.