Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame^] | 1 | From c25abd43e8877b4a7098f79eaacb248710731c2b Mon Sep 17 00:00:00 2001 |
| 2 | From: Dong-hee Na <donghee.na92@gmail.com> |
| 3 | Date: Sat, 28 Sep 2019 04:59:37 +0900 |
| 4 | Subject: [PATCH] bpo-38243, xmlrpc.server: Escape the server_title (GH-16373) |
| 5 | |
| 6 | Escape the server title of xmlrpc.server.DocXMLRPCServer |
| 7 | when rendering the document page as HTML. |
| 8 | |
| 9 | CVE: CVE-2019-16935 |
| 10 | |
| 11 | Upstream-Status: Backport [https://github.com/python/cpython/commit/e8650a4f8c7fb76f570d4ca9c1fbe44e91c8dfaa] |
| 12 | |
| 13 | Signed-off-by: Chen Qi <Qi.Chen@windriver.com> |
| 14 | --- |
| 15 | Lib/test/test_docxmlrpc.py | 16 ++++++++++++++++ |
| 16 | Lib/xmlrpc/server.py | 3 ++- |
| 17 | .../2019-09-25-13-21-09.bpo-38243.1pfz24.rst | 3 +++ |
| 18 | 3 files changed, 21 insertions(+), 1 deletion(-) |
| 19 | create mode 100644 Misc/NEWS.d/next/Security/2019-09-25-13-21-09.bpo-38243.1pfz24.rst |
| 20 | |
| 21 | diff --git a/Lib/test/test_docxmlrpc.py b/Lib/test/test_docxmlrpc.py |
| 22 | index f077f05f5b..38215659b6 100644 |
| 23 | --- a/Lib/test/test_docxmlrpc.py |
| 24 | +++ b/Lib/test/test_docxmlrpc.py |
| 25 | @@ -1,5 +1,6 @@ |
| 26 | from xmlrpc.server import DocXMLRPCServer |
| 27 | import http.client |
| 28 | +import re |
| 29 | import sys |
| 30 | import threading |
| 31 | from test import support |
| 32 | @@ -193,6 +194,21 @@ class DocXMLRPCHTTPGETServer(unittest.TestCase): |
| 33 | b'method_annotation</strong></a>(x: bytes)</dt></dl>'), |
| 34 | response.read()) |
| 35 | |
| 36 | + def test_server_title_escape(self): |
| 37 | + # bpo-38243: Ensure that the server title and documentation |
| 38 | + # are escaped for HTML. |
| 39 | + self.serv.set_server_title('test_title<script>') |
| 40 | + self.serv.set_server_documentation('test_documentation<script>') |
| 41 | + self.assertEqual('test_title<script>', self.serv.server_title) |
| 42 | + self.assertEqual('test_documentation<script>', |
| 43 | + self.serv.server_documentation) |
| 44 | + |
| 45 | + generated = self.serv.generate_html_documentation() |
| 46 | + title = re.search(r'<title>(.+?)</title>', generated).group() |
| 47 | + documentation = re.search(r'<p><tt>(.+?)</tt></p>', generated).group() |
| 48 | + self.assertEqual('<title>Python: test_title<script></title>', title) |
| 49 | + self.assertEqual('<p><tt>test_documentation<script></tt></p>', documentation) |
| 50 | + |
| 51 | |
| 52 | if __name__ == '__main__': |
| 53 | unittest.main() |
| 54 | diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py |
| 55 | index f1c467eb1b..32aba4df4c 100644 |
| 56 | --- a/Lib/xmlrpc/server.py |
| 57 | +++ b/Lib/xmlrpc/server.py |
| 58 | @@ -108,6 +108,7 @@ from xmlrpc.client import Fault, dumps, loads, gzip_encode, gzip_decode |
| 59 | from http.server import BaseHTTPRequestHandler |
| 60 | from functools import partial |
| 61 | from inspect import signature |
| 62 | +import html |
| 63 | import http.server |
| 64 | import socketserver |
| 65 | import sys |
| 66 | @@ -894,7 +895,7 @@ class XMLRPCDocGenerator: |
| 67 | methods |
| 68 | ) |
| 69 | |
| 70 | - return documenter.page(self.server_title, documentation) |
| 71 | + return documenter.page(html.escape(self.server_title), documentation) |
| 72 | |
| 73 | class DocXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): |
| 74 | """XML-RPC and documentation request handler class. |
| 75 | diff --git a/Misc/NEWS.d/next/Security/2019-09-25-13-21-09.bpo-38243.1pfz24.rst b/Misc/NEWS.d/next/Security/2019-09-25-13-21-09.bpo-38243.1pfz24.rst |
| 76 | new file mode 100644 |
| 77 | index 0000000000..98d7be1295 |
| 78 | --- /dev/null |
| 79 | +++ b/Misc/NEWS.d/next/Security/2019-09-25-13-21-09.bpo-38243.1pfz24.rst |
| 80 | @@ -0,0 +1,3 @@ |
| 81 | +Escape the server title of :class:`xmlrpc.server.DocXMLRPCServer` |
| 82 | +when rendering the document page as HTML. |
| 83 | +(Contributed by Dong-hee Na in :issue:`38243`.) |
| 84 | -- |
| 85 | 2.17.1 |
| 86 | |