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
 
<div id="update_notice" style="display: none">
 
    <div>${_('Checking for updates...')}</div>
 
</div>
 

	
 
<%
 
 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">
 
%for dt, dd, tt in elems:
 
  <dt title="${dt}">${dt}:</dt>
 
  <dd title="${tt}">${dd}</dd>
 
%endfor
 
</dl>
 

	
 
<h4>${_('Python Packages')}</h4>
 
<table class="table">
 
  <tbody>
 
      %for key, value in c.modules:
 
          <tr>
 
              <td>${key}</td>
 
              <td>${value}</td>
 
          </tr>
 
      %endfor
 
  </tbody>
 
</table>
 

	
 
<script>
 
    $('#check_for_update').click(function(e){
 
        var $update_notice = $('#update_notice');
kallithea/templates/data_table/_dt_elements.html
Show inline comments
 
@@ -110,34 +110,34 @@
 
    <i class="icon-folder"></i>
 
    <a href="${h.url('repos_group_home',group_name=group_name)}">${name}</a>
 
  </div>
 
</%def>
 

	
 
<%def name="repo_group_actions(repo_group_id, repo_group_name, gr_count)">
 
    <a href="${h.url('edit_repo_group',group_name=repo_group_name)}" title="${_('Edit')}" class="btn btn-default btn-xs">
 
      <i class="icon-pencil"></i>${_('Edit')}
 
    </a>
 
    ${h.form(h.url('delete_repo_group', group_name=repo_group_name))}
 
      <button id="${'remove_%s' % repo_group_name}" name="${'remove_%s' % repo_group_name}" class="btn btn-default btn-xs" title="${_('Delete')}"
 
          onclick="return confirm('${ungettext('Confirm to delete this group: %s with %s repository','Confirm to delete this group: %s with %s repositories',gr_count) % (repo_group_name, gr_count)}')">
 
        <i class="icon-trashcan"></i>${_('Delete')}
 
      </button>
 
    ${h.end_form()}
 
</%def>
 

	
 
<%def name="user_name(user_id, username)">
 
    ${h.link_to(username,h.url('edit_user', id=user_id))}
 
</%def>
 

	
 
<%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>
 

	
 
<%def name="user_group_name(user_group_id, user_group_name)">
 
  <div class="text-nowrap">
 
  <a href="${h.url('edit_users_group', id=user_group_id)}">
 
    <i class="icon-users" title="${_('User group')}"></i>${user_group_name}</a>
 
  </div>
 
</%def>
kallithea/templates/files/files_browser.html
Show inline comments
 
<%namespace name="base" file="/base/base.html"/>
 

	
 
<%def name="file_class(node)">
 
    %if node.is_file():
 
        <%return "browser-file" %>
 
    %elif node.is_submodule():
 
        <%return "submodule-dir"%>
 
    %else:
 
        <%return "browser-dir"%>
 
    %endif
 
</%def>
 
<%def name="file_url(node, c)">
 
    %if node.is_submodule():
 
        <%return node.url or '#'%>
 
    %else:
 
        <%return h.url('files_home', repo_name=c.repo_name, revision=c.changeset.raw_id, f_path=h.safe_unicode(node.path))%>
 
    %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)">
 
    <%
 
        c = "icon-folder-open"
 
        if node.is_file():
 
            c = "icon-doc"
 
        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">
 
        ${base.parent_child_navigation()}
 
    </div>
 

	
 
    <div class="panel-body">
 
        ${h.form(h.url.current())}
 
        <div id="search_activate_id" class="search_activate">
 
            <a class="btn btn-default btn-xs" id="filter_activate" href="#">${_('Search File List')}</a>
 
        </div>
 
        ${h.end_form()}
 
        <div class="browser-search form-inline">
 
            <div>
 
                <div id="node_filter_box_loading" style="display:none">${_('Loading file list...')}</div>
 
                <div id="node_filter_box" style="display:none">
 
                ${h.files_breadcrumbs(c.repo_name,c.changeset.raw_id,c.file.path)}/<input class="init" type="text" value="type to search..." name="filter" size="25" id="node_filter">
 
                </div>
 
            </div>
 
        </div>
 
        <table class="table code-browser">
 
            <thead>
 
                <tr>
 
                    <th>${_('Name')}</th>
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)}
 
      </span>
 
    %endfor
 
</div>
0 comments (0 inline, 0 general)