mirror of
https://abf.rosa.ru/djam/python38.git
synced 2025-02-23 15:22:50 +00:00
72 lines
3.1 KiB
Diff
72 lines
3.1 KiB
Diff
![]() |
From 1698cacfb924d1df452e78d11a4bf81ae7777389 Mon Sep 17 00:00:00 2001
|
||
|
From: Victor Stinner <vstinner@redhat.com>
|
||
|
Date: Sat, 28 Sep 2019 09:33:00 +0200
|
||
|
Subject: [PATCH] bpo-38243, xmlrpc.server: Escape the server_title (GH-16373)
|
||
|
(GH-16441)
|
||
|
|
||
|
Escape the server title of xmlrpc.server.DocXMLRPCServer
|
||
|
when rendering the document page as HTML.
|
||
|
|
||
|
(cherry picked from commit e8650a4f8c7fb76f570d4ca9c1fbe44e91c8dfaa)
|
||
|
---
|
||
|
Lib/test/test_docxmlrpc.py | 16 ++++++++++++++++
|
||
|
Lib/xmlrpc/server.py | 3 ++-
|
||
|
.../2019-09-25-13-21-09.bpo-38243.1pfz24.rst | 3 +++
|
||
|
3 files changed, 21 insertions(+), 1 deletion(-)
|
||
|
create mode 100644 Misc/NEWS.d/next/Security/2019-09-25-13-21-09.bpo-38243.1pfz24.rst
|
||
|
|
||
|
Index: python3.5-3.5.2/Lib/test/test_docxmlrpc.py
|
||
|
===================================================================
|
||
|
--- python3.5-3.5.2.orig/Lib/test/test_docxmlrpc.py 2019-10-07 09:02:07.977389134 -0400
|
||
|
+++ python3.5-3.5.2/Lib/test/test_docxmlrpc.py 2019-10-07 09:02:07.969389105 -0400
|
||
|
@@ -1,5 +1,6 @@
|
||
|
from xmlrpc.server import DocXMLRPCServer
|
||
|
import http.client
|
||
|
+import re
|
||
|
import sys
|
||
|
from test import support
|
||
|
threading = support.import_module('threading')
|
||
|
@@ -212,6 +213,21 @@ class DocXMLRPCHTTPGETServer(unittest.Te
|
||
|
b'method_annotation</strong></a>(x: bytes)</dt></dl>'),
|
||
|
response.read())
|
||
|
|
||
|
+ def test_server_title_escape(self):
|
||
|
+ # bpo-38243: Ensure that the server title and documentation
|
||
|
+ # are escaped for HTML.
|
||
|
+ self.serv.set_server_title('test_title<script>')
|
||
|
+ self.serv.set_server_documentation('test_documentation<script>')
|
||
|
+ self.assertEqual('test_title<script>', self.serv.server_title)
|
||
|
+ self.assertEqual('test_documentation<script>',
|
||
|
+ self.serv.server_documentation)
|
||
|
+
|
||
|
+ generated = self.serv.generate_html_documentation()
|
||
|
+ title = re.search(r'<title>(.+?)</title>', generated).group()
|
||
|
+ documentation = re.search(r'<p><tt>(.+?)</tt></p>', generated).group()
|
||
|
+ self.assertEqual('<title>Python: test_title<script></title>', title)
|
||
|
+ self.assertEqual('<p><tt>test_documentation<script></tt></p>', documentation)
|
||
|
+
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
unittest.main()
|
||
|
Index: python3.5-3.5.2/Lib/xmlrpc/server.py
|
||
|
===================================================================
|
||
|
--- python3.5-3.5.2.orig/Lib/xmlrpc/server.py 2019-10-07 09:02:07.977389134 -0400
|
||
|
+++ python3.5-3.5.2/Lib/xmlrpc/server.py 2019-10-07 09:02:07.969389105 -0400
|
||
|
@@ -106,6 +106,7 @@ server.handle_request()
|
||
|
|
||
|
from xmlrpc.client import Fault, dumps, loads, gzip_encode, gzip_decode
|
||
|
from http.server import BaseHTTPRequestHandler
|
||
|
+import html
|
||
|
import http.server
|
||
|
import socketserver
|
||
|
import sys
|
||
|
@@ -887,7 +888,7 @@ class XMLRPCDocGenerator:
|
||
|
methods
|
||
|
)
|
||
|
|
||
|
- return documenter.page(self.server_title, documentation)
|
||
|
+ return documenter.page(html.escape(self.server_title), documentation)
|
||
|
|
||
|
class DocXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||
|
"""XML-RPC and documentation request handler class.
|