Changeset - c7728c5736fd
[Not reviewed]
stable
0 4 0
Thomas De Schampheleire - 7 years ago 2019-04-27 22:27:45
thomas.de_schampheleire@nokia.com
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.
4 files changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general)
kallithea/templates/admin/settings/settings_system.html
Show inline comments
 
@@ -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">
kallithea/templates/data_table/_dt_elements.html
Show inline comments
 
@@ -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>
 

	
kallithea/templates/files/files_browser.html
Show inline comments
 
@@ -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">
kallithea/templates/files/files_history_box.html
Show inline comments
 
<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)}
0 comments (0 inline, 0 general)