You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
3.0 KiB

  1. From 39a0c7555530e31c6941a78da19b6a5b61170687 Mon Sep 17 00:00:00 2001
  2. From: "Miss Islington (bot)"
  3. <31488909+miss-islington@users.noreply.github.com>
  4. Date: Fri, 27 Sep 2019 13:18:14 -0700
  5. Subject: [PATCH] bpo-38243, xmlrpc.server: Escape the server_title (GH-16373)
  6. Escape the server title of xmlrpc.server.DocXMLRPCServer
  7. when rendering the document page as HTML.
  8. (cherry picked from commit e8650a4f8c7fb76f570d4ca9c1fbe44e91c8dfaa)
  9. Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
  10. ---
  11. Lib/test/test_docxmlrpc.py | 16 ++++++++++++++++
  12. Lib/xmlrpc/server.py | 3 ++-
  13. .../2019-09-25-13-21-09.bpo-38243.1pfz24.rst | 3 +++
  14. 3 files changed, 21 insertions(+), 1 deletion(-)
  15. create mode 100644 Misc/NEWS.d/next/Security/2019-09-25-13-21-09.bpo-38243.1pfz24.rst
  16. --- a/Lib/test/test_docxmlrpc.py
  17. +++ b/Lib/test/test_docxmlrpc.py
  18. @@ -1,5 +1,6 @@
  19. from xmlrpc.server import DocXMLRPCServer
  20. import http.client
  21. +import re
  22. import sys
  23. import threading
  24. from test import support
  25. @@ -193,6 +194,21 @@ class DocXMLRPCHTTPGETServer(unittest.Te
  26. b'method_annotation</strong></a>(x: bytes)</dt></dl>'),
  27. response.read())
  28. + def test_server_title_escape(self):
  29. + # bpo-38243: Ensure that the server title and documentation
  30. + # are escaped for HTML.
  31. + self.serv.set_server_title('test_title<script>')
  32. + self.serv.set_server_documentation('test_documentation<script>')
  33. + self.assertEqual('test_title<script>', self.serv.server_title)
  34. + self.assertEqual('test_documentation<script>',
  35. + self.serv.server_documentation)
  36. +
  37. + generated = self.serv.generate_html_documentation()
  38. + title = re.search(r'<title>(.+?)</title>', generated).group()
  39. + documentation = re.search(r'<p><tt>(.+?)</tt></p>', generated).group()
  40. + self.assertEqual('<title>Python: test_title&lt;script&gt;</title>', title)
  41. + self.assertEqual('<p><tt>test_documentation&lt;script&gt;</tt></p>', documentation)
  42. +
  43. if __name__ == '__main__':
  44. unittest.main()
  45. --- a/Lib/xmlrpc/server.py
  46. +++ b/Lib/xmlrpc/server.py
  47. @@ -108,6 +108,7 @@ from xmlrpc.client import Fault, dumps,
  48. from http.server import BaseHTTPRequestHandler
  49. from functools import partial
  50. from inspect import signature
  51. +import html
  52. import http.server
  53. import socketserver
  54. import sys
  55. @@ -894,7 +895,7 @@ class XMLRPCDocGenerator:
  56. methods
  57. )
  58. - return documenter.page(self.server_title, documentation)
  59. + return documenter.page(html.escape(self.server_title), documentation)
  60. class DocXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
  61. """XML-RPC and documentation request handler class.
  62. --- /dev/null
  63. +++ b/Misc/NEWS.d/next/Security/2019-09-25-13-21-09.bpo-38243.1pfz24.rst
  64. @@ -0,0 +1,3 @@
  65. +Escape the server title of :class:`xmlrpc.server.DocXMLRPCServer`
  66. +when rendering the document page as HTML.
  67. +(Contributed by Dong-hee Na in :issue:`38243`.)