Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d735219

Browse files
committed
BUG,SEC: html.escape(cell) to prevent XSS (astanin#25)
1 parent ae7e8b6 commit d735219

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tabulate.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def _is_file(f):
5555
except ImportError:
5656
wcwidth = None
5757

58+
try:
59+
from html import escape as htmlescape
60+
except ImportError:
61+
from cgi import escape as htmlescape
62+
5863

5964
__all__ = ["tabulate", "tabulate_formats", "simple_separated_format"]
6065
__version__ = "0.8.7"
@@ -185,7 +190,8 @@ def _html_row_with_attrs(celltag, cell_values, colwidths, colaligns):
185190
"decimal": ' style="text-align: right;"',
186191
}
187192
values_with_attrs = [
188-
"<{0}{1}>{2}</{0}>".format(celltag, alignment.get(a, ""), c)
193+
"<{0}{1}>{2}</{0}>".format(celltag, alignment.get(a, ""),
194+
htmlescape(c))
189195
for c, a in zip(cell_values, colaligns)
190196
]
191197
rowhtml = "<tr>" + "".join(values_with_attrs).rstrip() + "</tr>"

0 commit comments

Comments
 (0)