~ubuntu-branches/ubuntu/wily/bandit/wily-proposed

« back to all changes in this revision

Viewing changes to bandit/plugins/mako_templates.py

  • Committer: Package Import Robot
  • Author(s): Dave Walker (Daviey)
  • Date: 2015-07-22 09:01:39 UTC
  • Revision ID: package-import@ubuntu.com-20150722090139-fl0nluy0x8m9ctx4
Tags: upstream-0.12.0
ImportĀ upstreamĀ versionĀ 0.12.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding:utf-8 -*-
 
2
#
 
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
4
# not use this file except in compliance with the License. You may obtain
 
5
# a copy of the License at
 
6
#
 
7
#      http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
# Unless required by applicable law or agreed to in writing, software
 
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
12
# License for the specific language governing permissions and limitations
 
13
# under the License.
 
14
 
 
15
import bandit
 
16
from bandit.core.test_properties import *
 
17
 
 
18
 
 
19
@checks('Call')
 
20
def use_of_mako_templates(context):
 
21
    # check type just to be safe
 
22
    if type(context.call_function_name_qual) == str:
 
23
        qualname_list = context.call_function_name_qual.split('.')
 
24
        func = qualname_list[-1]
 
25
        if 'mako' in qualname_list and func == 'Template':
 
26
            # unlike Jinja2, mako does not have a template wide autoescape
 
27
            # feature and thus each variable must be carefully sanitized.
 
28
            return bandit.Issue(
 
29
                severity=bandit.MEDIUM,
 
30
                confidence=bandit.HIGH,
 
31
                text="Mako templates allow HTML/JS rendering by default and "
 
32
                     "are inherently open to XSS attacks. Ensure variables "
 
33
                     "in all templates are properly sanitized via the 'n', "
 
34
                     "'h' or 'x' flags (depending on context). For example, "
 
35
                     "to HTML escape the variable 'data' do ${ data |h }."
 
36
            )