changeset 7648:c7728c5736fd stable

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 <html> code with %s data' % foobar) or h.literal('some <html> 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.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Sat, 27 Apr 2019 22:27:45 +0200
parents 4babc6e047d0
children 899f6accd979
files kallithea/templates/admin/settings/settings_system.html kallithea/templates/data_table/_dt_elements.html kallithea/templates/files/files_browser.html kallithea/templates/files/files_history_box.html
diffstat 4 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/templates/admin/settings/settings_system.html	Mon Apr 29 21:46:44 2019 +0200
+++ b/kallithea/templates/admin/settings/settings_system.html	Sat Apr 27 22:27:45 2019 +0200
@@ -4,13 +4,13 @@
 
 <%
  elems = [
-    (_('Kallithea version'), h.literal('%s <b><span id="check_for_update" style="display:none">%s</span></b>' % (c.kallithea_version, _('Check for updates'))), ''),
+    (_('Kallithea version'), h.literal('%s <b><span id="check_for_update" style="display:none">%s</span></b>') % (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 <br/><span class="text-muted">%s.</span>' % (c.update_url, _('Note: please make sure this server can access this URL'))), ''),
+    (_('Upgrade info endpoint'), h.literal('%s <br/><span class="text-muted">%s.</span>') % (c.update_url, _('Note: please make sure this server can access this URL')), ''),
  ]
 %>
 <dl class="dl-horizontal">
--- a/kallithea/templates/data_table/_dt_elements.html	Mon Apr 29 21:46:44 2019 +0200
+++ b/kallithea/templates/data_table/_dt_elements.html	Sat Apr 27 22:27:45 2019 +0200
@@ -131,7 +131,7 @@
 <%def name="repo_group_name(repo_group_name, children_groups)">
   <div class="text-nowrap">
   <a href="${h.url('repos_group_home',group_name=repo_group_name)}">
-    <i class="icon-folder" title="${_('Repository group')}"></i>${h.literal(' &raquo; '.join(children_groups))}</a>
+    <i class="icon-folder" title="${_('Repository group')}"></i>${h.literal(' &raquo; ').join(children_groups)}</a>
   </div>
 </%def>
 
--- a/kallithea/templates/files/files_browser.html	Mon Apr 29 21:46:44 2019 +0200
+++ b/kallithea/templates/files/files_browser.html	Sat Apr 27 22:27:45 2019 +0200
@@ -17,7 +17,7 @@
     %endif
 </%def>
 <%def name="_file_name(iconclass, name)">
-    <%return h.literal('<i class="%s"></i><span>%s</span>' % (iconclass, name))%>
+    <%return h.literal('<i class="%s"></i><span>%s</span>') % (iconclass, name)%>
 </%def>
 <%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)%>
 </%def>
 <div id="body" class="panel panel-default">
     <div class="panel-heading clearfix">
--- a/kallithea/templates/files/files_history_box.html	Mon Apr 29 21:46:44 2019 +0200
+++ b/kallithea/templates/files/files_history_box.html	Sat Apr 27 22:27:45 2019 +0200
@@ -1,5 +1,5 @@
 <div class="form-group">
-    <span>${h.HTML(ungettext(u'%s author',u'%s authors',len(c.authors))) % h.literal('<b>%s</b>' % len(c.authors)) }</span>
+    <span>${h.HTML(ungettext(u'%s author',u'%s authors',len(c.authors))) % (h.literal('<b>%s</b>') % len(c.authors)) }</span>
     %for email, user in c.authors:
       <span data-toggle="tooltip" title="${user}">
         ${h.gravatar_div(email, size=20)}