# HG changeset patch # User Thomas De Schampheleire # Date 2019-04-27 22:27:45 # Node ID c7728c5736fd20c1c8aac22a0dd0280fe975c7a2 # Parent 4babc6e047d08b949c0ae50a105edcfa87bb4eef templates: narrow down scope of webhelpers.html.literal for HTML injection When using webhelpers.html.literal to inject some explicit HTML code with some variable data, there are two approaches: h.literal('some code with %s data' % foobar) or h.literal('some code with %s data') % foobar In the first case, the literal also applies to the contents of variable 'foobar' which may be influenceable by users and thus potentially malicious. In the second case, this term will be escaped by webhelpers. See also the documentation: https://docs.pylonsproject.org/projects/webhelpers/en/latest/modules/html/builder.html#webhelpers.html.builder.literal "Also, if you add another string to this string, the other string will be quoted and you will get back another literal object. Also literal(...) % obj will quote any value(s) from obj." In files_browser.html, the correction of this scope of literal() also means that explicit escaping of node.name can be removed. The escaping is now done automatically by webhelpers as mentioned above. diff --git a/kallithea/templates/admin/settings/settings_system.html b/kallithea/templates/admin/settings/settings_system.html --- a/kallithea/templates/admin/settings/settings_system.html +++ b/kallithea/templates/admin/settings/settings_system.html @@ -4,13 +4,13 @@ <% elems = [ - (_('Kallithea version'), h.literal('%s ' % (c.kallithea_version, _('Check for updates'))), ''), + (_('Kallithea version'), h.literal('%s ') % (c.kallithea_version, _('Check for updates')), ''), (_('Kallithea configuration file'), c.ini['__file__'], ''), (_('Python version'), c.py_version, ''), (_('Platform'), c.platform, ''), (_('Git version'), c.git_version, ''), (_('Git path'), c.ini.get('git_path'), ''), - (_('Upgrade info endpoint'), h.literal('%s
%s.' % (c.update_url, _('Note: please make sure this server can access this URL'))), ''), + (_('Upgrade info endpoint'), h.literal('%s
%s.') % (c.update_url, _('Note: please make sure this server can access this URL')), ''), ] %>
diff --git a/kallithea/templates/data_table/_dt_elements.html b/kallithea/templates/data_table/_dt_elements.html --- a/kallithea/templates/data_table/_dt_elements.html +++ b/kallithea/templates/data_table/_dt_elements.html @@ -131,7 +131,7 @@ <%def name="repo_group_name(repo_group_name, children_groups)">
- ${h.literal(' » '.join(children_groups))} + ${h.literal(' » ').join(children_groups)}
diff --git a/kallithea/templates/files/files_browser.html b/kallithea/templates/files/files_browser.html --- a/kallithea/templates/files/files_browser.html +++ b/kallithea/templates/files/files_browser.html @@ -17,7 +17,7 @@ %endif <%def name="_file_name(iconclass, name)"> - <%return h.literal('%s' % (iconclass, name))%> + <%return h.literal('%s') % (iconclass, name)%> <%def name="file_name(node)"> <% @@ -27,7 +27,7 @@ elif node.is_submodule(): c = "icon-file-submodule" %> - <%return _file_name(c, h.escape(node.name))%> + <%return _file_name(c, node.name)%>
diff --git a/kallithea/templates/files/files_history_box.html b/kallithea/templates/files/files_history_box.html --- a/kallithea/templates/files/files_history_box.html +++ b/kallithea/templates/files/files_history_box.html @@ -1,5 +1,5 @@
- ${h.HTML(ungettext(u'%s author',u'%s authors',len(c.authors))) % h.literal('%s' % len(c.authors)) } + ${h.HTML(ungettext(u'%s author',u'%s authors',len(c.authors))) % (h.literal('%s') % len(c.authors)) } %for email, user in c.authors: ${h.gravatar_div(email, size=20)}