summaryrefslogtreecommitdiff
path: root/bandit.yaml
blob: bb46478af480a8281cc42bd967cfa1ba6eaccf72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# optional: after how many files to update progress
#show_progress_every: 100

# optional: plugins directory name
#plugins_dir: 'plugins'

# optional: plugins discovery name pattern
plugin_name_pattern: '*.py'

# optional: terminal escape sequences to display colors
#output_colors:
#    DEFAULT: '\033[0m'
#    HEADER: '\033[95m'
#    LOW: '\033[94m'
#    MEDIUM: '\033[93m'
#    HIGH: '\033[91m'

# optional: log format string
#log_format: "[%(module)s]\t%(levelname)s\t%(message)s"

# globs of files which should be analyzed
include:
    - '*.py'
    - '*.pyw'

# a list of strings, which if found in the path will cause files to be excluded
# for example /tests/ - to remove all all files in tests directory
exclude_dirs:
    - '/tests/'

profiles:
    All:
        include:
            - any_other_function_with_shell_equals_true
            - assert_used
            - blacklist_calls
            - blacklist_import_func
            - blacklist_imports
            - exec_used
            - execute_with_run_as_root_equals_true
            - hardcoded_bind_all_interfaces
            - hardcoded_password
            - hardcoded_sql_expressions
            - hardcoded_tmp_directory
            - jinja2_autoescape_false
            - linux_commands_wildcard_injection
            - paramiko_calls
            - password_config_option_not_marked_secret
            - request_with_no_cert_validation
            - set_bad_file_permissions
            - subprocess_popen_with_shell_equals_true
            - subprocess_without_shell_equals_true
            - start_process_with_a_shell
            - start_process_with_no_shell
            - start_process_with_partial_path
            - ssl_with_bad_defaults
            - ssl_with_bad_version
            - ssl_with_no_version
            - try_except_pass
            - use_of_mako_templates

    XSS:
        include:
            - jinja2_autoescape_false
            - use_of_mako_templates

    ShellInjection:
        include:
            - subprocess_popen_with_shell_equals_true
            - subprocess_without_shell_equals_true
            - any_other_function_with_shell_equals_true
            - start_process_with_a_shell
            - start_process_with_no_shell
            - start_process_with_partial_path
        exclude:

    SqlInjection:
        include:
            - hardcoded_sql_expressions

blacklist_calls:
    bad_name_sets:
        - pickle:
            qualnames: [pickle.loads, pickle.load, pickle.Unpickler,
                        cPickle.loads, cPickle.load, cPickle.Unpickler]
            message: "Pickle library appears to be in use, possible security issue."
        - marshal:
            qualnames: [marshal.load, marshal.loads]
            message: "Deserialization with the marshal module is possibly dangerous."
        - md5:
            qualnames: [hashlib.md5, Crypto.Hash.MD2.new, Crypto.Hash.MD4.new, Crypto.Hash.MD5.new, cryptography.hazmat.primitives.hashes.MD5]
            message: "Use of insecure MD2, MD4, or MD5 hash function."
        - mktemp_q:
            qualnames: [tempfile.mktemp]
            message: "Use of insecure and deprecated function (mktemp)."
        - eval:
            qualnames: [eval]
            message: "Use of possibly insecure function - consider using safer ast.literal_eval."
        - mark_safe:
            names: [mark_safe]
            message: "Use of mark_safe() may expose cross-site scripting vulnerabilities and should be reviewed."
        - httpsconnection:
            qualnames: [httplib.HTTPSConnection]
            message: "Use of HTTPSConnection does not provide security, see https://wiki.openstack.org/wiki/OSSN/OSSN-0033"
        - yaml_load:
            qualnames: [yaml.load]
            message: "Use of unsafe yaml load. Allows instantiation of arbitrary objects. Consider yaml.safe_load()."
        - urllib_urlopen:
            qualnames: [urllib.urlopen, urllib.urlretrieve, urllib.URLopener, urllib.FancyURLopener, urllib2.urlopen, urllib2.Request]
            message: "Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected."
        - random:
            qualnames: [random.random, random.randrange, random.randint, random.choice, random.uniform, random.triangular]
            message: "Standard pseudo-random generators are not suitable for security/cryptographic purposes."
            level: "LOW"

        # Most of this is based off of Christian Heimes' work on defusedxml:
        #   https://pypi.python.org/pypi/defusedxml/#defusedxml-sax

        - xml_bad_cElementTree:
            qualnames: [xml.etree.cElementTree.parse,
                        xml.etree.cElementTree.iterparse,
                        xml.etree.cElementTree.fromstring,
                        xml.etree.cElementTree.XMLParser]
            message: "Using {func} to parse untrusted XML data is known to be vulnerable to XML attacks. Replace {func} with it's defusedxml equivilent function."
        - xml_bad_ElementTree:
            qualnames: [xml.etree.ElementTree.parse,
                        xml.etree.ElementTree.iterparse,
                        xml.etree.ElementTree.fromstring,
                        xml.etree.ElementTree.XMLParser]
            message: "Using {func} to parse untrusted XML data is known to be vulnerable to XML attacks. Replace {func} with it's defusedxml equivilent function."
        - xml_bad_expatreader:
            qualnames: [xml.sax.expatreader.create_parser]
            message: "Using {func} to parse untrusted XML data is known to be vulnerable to XML attacks. Replace {func} with it's defusedxml equivilent function."
        - xml_bad_expatbuilder:
            qualnames: [xml.dom.expatbuilder.parse,
                        xml.dom.expatbuilder.parseString]
            message: "Using {func} to parse untrusted XML data is known to be vulnerable to XML attacks. Replace {func} with it's defusedxml equivilent function."
        - xml_bad_sax:
            qualnames: [xml.sax.parse,
                        xml.sax.parseString,
                        xml.sax.make_parser]
            message: "Using {func} to parse untrusted XML data is known to be vulnerable to XML attacks. Replace {func} with it's defusedxml equivilent function."
        - xml_bad_minidom:
            qualnames: [xml.dom.minidom.parse,
                        xml.dom.minidom.parseString]
            message: "Using {func} to parse untrusted XML data is known to be vulnerable to XML attacks. Replace {func} with it's defusedxml equivilent function."
        - xml_bad_pulldom:
            qualnames: [xml.dom.pulldom.parse,
                        xml.dom.pulldom.parseString]
            message: "Using {func} to parse untrusted XML data is known to be vulnerable to XML attacks. Replace {func} with it's defusedxml equivilent function."
        - xml_bad_etree:
            qualnames: [lxml.etree.parse,
                        lxml.etree.fromstring,
                        lxml.etree.RestrictedElement,
                        lxml.etree.GlobalParserTLS,
                        lxml.etree.getDefaultParser,
                        lxml.etree.check_docinfo]
            message: "Using {func} to parse untrusted XML data is known to be vulnerable to XML attacks. Replace {func} with it's defusedxml equivilent function."


shell_injection:
    # Start a process using the subprocess module, or one of its wrappers.
    subprocess: [subprocess.Popen, subprocess.call, subprocess.check_call,
                 subprocess.check_output, utils.execute, utils.execute_with_timeout]
    # Start a process with a function vulnerable to shell injection.
    shell: [os.system, os.popen, os.popen2, os.popen3, os.popen4,
            popen2.popen2, popen2.popen3, popen2.popen4, popen2.Popen3,
            popen2.Popen4, commands.getoutput, commands.getstatusoutput]
    # Start a process with a function that is not vulnerable to shell injection.
    no_shell: [os.execl, os.execle, os.execlp, os.execlpe, os.execv,os.execve,
               os.execvp, os.execvpe, os.spawnl, os.spawnle, os.spawnlp,
               os.spawnlpe, os.spawnv, os.spawnve, os.spawnvp, os.spawnvpe,
               os.startfile]

blacklist_imports:
    bad_import_sets:
        - telnet:
            imports: [telnetlib]
            level: HIGH
            message: "Telnet is considered insecure. Use SSH or some other encrypted protocol."
        - info_libs:
            imports: [pickle, cPickle, subprocess, Crypto]
            level: LOW
            message: "Consider possible security implications associated with {module} module."

        # Most of this is based off of Christian Heimes' work on defusedxml:
        #   https://pypi.python.org/pypi/defusedxml/#defusedxml-sax

        - xml_libs:
            imports: [xml.etree.cElementTree,
                      xml.etree.ElementTree,
                      xml.sax.expatreader,
                      xml.sax,
                      xml.dom.expatbuilder,
                      xml.dom.minidom,
                      xml.dom.pulldom,
                      lxml.etree,
                      lxml]
            message: "Using {module} to parse untrusted XML data is known to be vulnerable to XML attacks. Replace {module} with the equivilent defusedxml package."
            level: LOW
        - xml_libs_high:
            imports: [xmlrpclib]
            message: "Using {module} to parse untrusted XML data is known to be vulnerable to XML attacks. Use defused.xmlrpc.monkey_patch() function to monkey-patch xmlrpclib and mitigate XML vulnerabilities."
            level: HIGH

hardcoded_tmp_directory:
    tmp_dirs:  ['/tmp', '/var/tmp', '/dev/shm']

hardcoded_password:
    # Support for full path, relative path and special "%(site_data_dir)s"
    # substitution (/usr/{local}/share)
    word_list: "%(site_data_dir)s/wordlist/default-passwords"

ssl_with_bad_version:
    bad_protocol_versions:
        - 'PROTOCOL_SSLv2'
        - 'SSLv2_METHOD'
        - 'SSLv23_METHOD'
        - 'PROTOCOL_SSLv3'  # strict option
        - 'PROTOCOL_TLSv1'  # strict option
        - 'SSLv3_METHOD'    # strict option
        - 'TLSv1_METHOD'    # strict option

password_config_option_not_marked_secret:
    function_names:
        - oslo.config.cfg.StrOpt
        - oslo_config.cfg.StrOpt

execute_with_run_as_root_equals_true:
    function_names:
        - ceilometer.utils.execute
        - cinder.utils.execute
        - neutron.agent.linux.utils.execute
        - nova.utils.execute
        - nova.utils.trycmd

try_except_pass:
  check_typed_exception: True