mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
bpo-35603: Escape table header of make_table output that can cause potential XSS. (GH-11341)
This commit is contained in:
parent
1f511e1af0
commit
78de01198b
3 changed files with 15 additions and 0 deletions
|
@ -2036,6 +2036,10 @@ class HtmlDiff(object):
|
||||||
s.append( fmt % (next_id[i],next_href[i],fromlist[i],
|
s.append( fmt % (next_id[i],next_href[i],fromlist[i],
|
||||||
next_href[i],tolist[i]))
|
next_href[i],tolist[i]))
|
||||||
if fromdesc or todesc:
|
if fromdesc or todesc:
|
||||||
|
fromdesc = fromdesc.replace("&", "&").replace(">", ">") \
|
||||||
|
.replace("<", "<")
|
||||||
|
todesc = todesc.replace("&", "&").replace(">", ">") \
|
||||||
|
.replace("<", "<")
|
||||||
header_row = '<thead><tr>%s%s%s%s</tr></thead>' % (
|
header_row = '<thead><tr>%s%s%s%s</tr></thead>' % (
|
||||||
'<th class="diff_next"><br /></th>',
|
'<th class="diff_next"><br /></th>',
|
||||||
'<th colspan="2" class="diff_header">%s</th>' % fromdesc,
|
'<th colspan="2" class="diff_header">%s</th>' % fromdesc,
|
||||||
|
|
|
@ -238,6 +238,15 @@ class TestSFpatches(unittest.TestCase):
|
||||||
with open(findfile('test_difflib_expect.html')) as fp:
|
with open(findfile('test_difflib_expect.html')) as fp:
|
||||||
self.assertEqual(actual, fp.read())
|
self.assertEqual(actual, fp.read())
|
||||||
|
|
||||||
|
def test_make_table_escape_table_header(self):
|
||||||
|
html_diff = difflib.HtmlDiff()
|
||||||
|
output = html_diff.make_table(patch914575_from1.splitlines(),
|
||||||
|
patch914575_to1.splitlines(),
|
||||||
|
fromdesc='<from>',
|
||||||
|
todesc='<to>')
|
||||||
|
self.assertIn('<from>', output)
|
||||||
|
self.assertIn('<to>', output)
|
||||||
|
|
||||||
def test_recursion_limit(self):
|
def test_recursion_limit(self):
|
||||||
# Check if the problem described in patch #1413711 exists.
|
# Check if the problem described in patch #1413711 exists.
|
||||||
limit = sys.getrecursionlimit()
|
limit = sys.getrecursionlimit()
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Escape table header output of :meth:`difflib.HtmlDiff.make_table`.
|
||||||
|
Patch by Karthikeyan Singaravelan.
|
Loading…
Add table
Add a link
Reference in a new issue