10000 [3.6] bpo-42988: Remove the pydoc getfile feature (GH-25015) by miss-islington · Pull Request #25067 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.6] bpo-42988: Remove the pydoc getfile feature (GH-25015) #25067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2312,9 +2312,6 @@ def page(self, title, contents):
%s</head><body bgcolor="#f0f0f8">%s<div style="clear:both;padding-top:.5em;">%s</div>
</body></html>''' % (title, css_link, html_navbar(), contents)

def filelink(self, url, path):
return '<a href="getfile?key=%s">%s</a>' % (url, path)


html = _HTMLDoc()

Expand Down Expand Up @@ -2400,19 +2397,6 @@ def bltinlink(name):
'key = %s' % key, '#ffffff', '#ee77aa', '<br>'.join(results))
return 'Search Results', contents

def html_getfile(path):
"""Get and display a source file listing safely."""
path = urllib.parse.unquote(path)
with tokenize.open(path) as fp:
lines = html.escape(fp.read())
body = '<pre>%s</pre>' % lines
heading = html.heading(
'<big><big><strong>File Listing</strong></big></big>',
'#ffffff', '#7799ee')
contents = heading + html.bigsection(
'File: %s' % path, '#ffffff', '#ee77aa', body)
return 'getfile %s' % path, contents

def html_topics():
"""Index of topic texts available."""

Expand Down Expand Up @@ -2504,8 +2488,6 @@ def get_html_page(url):
op, _, url = url.partition('=')
if op == "search?key":
title, content = html_search(url)
elif op == "getfile?key":
title, content = html_getfile(url)
elif op == "topic?key":
# try topics first, then objects.
try:
Expand Down
6 changes: 0 additions & 6 deletions Lib/test/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,18 +1052,12 @@ def test_url_requests(self):
("topic?key=def", "Pydoc: KEYWORD def"),
("topic?key=STRINGS", "Pydoc: TOPIC STRINGS"),
("foobar", "Pydoc: Error - foobar"),
("getfile?key=foobar", "Pydoc: Error - getfile?key=foobar"),
]

with self.restrict_walk_packages():
for url, title in requests:
self.call_url_handler(url, title)

path = string.__file__
title = "Pydoc: getfile " + path
url = "getfile?key=" + path
self.call_url_handler(url, title)


class TestHelper(unittest.TestCase):
def test_keywords(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CVE-2021-3426: Remove the ``getfile`` feature of the :mod:`pydoc` module which
could be abused to read arbitrary files on the disk (directory traversal
vulnerability). Moreover, even source code of Python modules can contain
sensitive data like passwords. Vulnerability reported by David Schwörer.
0