Commit Graph

48 Commits

Author SHA1 Message Date
lhinds 2d2170273b Project Migration to PyCQA
This change rehomes the project to PyCQA[1] as reported to the
openstack-dev mailing list [1]

[0] https://github.com/PyCQA/bandit
[1] http://lists.openstack.org/pipermail/openstack-dev/2018-April/129386.html

Change-Id: I6aad329a60799ea24a3d9bc49e35c3c35ed9dc3b
2018-05-04 06:59:50 +02:00
Tin Lam 90f031c973 Fix infinite loop issue
Running bandit using relative paths inside a subdirectory when the current
directory contains __init__.py causes bandit to be stuck in an infinite
loop.

Co-Authored-By: Calvin Li
Closes-Bug: #1743042
Change-Id: I247108c1365847134ee561073ea0eb43c57b54cc
2018-02-01 13:10:16 -06:00
Zuul 8f09d8b208 Merge "Custom formatter" 2017-11-24 16:25:22 +00:00
Marek Cermak d159335700 Custom formatter
Implements: custom formatter

Custom formatter can be used to output a machine-readable, easily
parsable and customizable format using set of predefined tags
to suite various needs.

Output string is formatted using python string.format() standards
and therefore provides familiar usage.

Usage: bandit --format custom [--msg-template MSG-TEMPLATE] targets

See bandit --help for additional information and list of available tags

modified:   bandit/cli/main.py
modified:   bandit/core/manager.py
modified:   README.rst
modified:   setup.cfg
new file:   bandit/formatters/custom.py

Change-Id: I900c9689cddb048db58608c443305e05e7a4be14
Signed-off-by: Marek Cermak <macermak@redhat.com>
2017-11-13 13:53:40 +01:00
Rajath Agasthya a98519927b Plugin to flag insecure hash functions created using hashlib.new()
Currently, insecure hash function usage by calling hashlib.md5()
is flagged in B303. But these hash functions can also be obtained using
hashlib.new(), by passing 'md4' or 'md5' as an argument. This plugin
checks such usage.

Change-Id: I8d368aea287e1287e5f638b48c4297d355037839
Closes-Bug: #1708582
2017-09-28 21:50:27 -07:00
Eric Brown fbd4e83efe Yet Another Formatter (yaml)
This patch adds a yaml formatter to the output options of bandit.

Change-Id: Ibbe0cff062ce2c11138b746f95109f31de10f5b1
2017-02-27 16:23:17 -08:00
Eric Brown 0acf9f95db Fix up nits in the README and other files
* Consistently use single space after period, not double
* Keep line width at 80 where possible
* Replace Pythion 3.4 references with 3.5 since the gate no longer
  tests 3.4.

Change-Id: Ia6a1b9a5582f37e359b069b4a97f7c180e32ab3a
2017-01-05 15:12:11 -08:00
Eric Brown 7ec796970f Add missing Python 3.5 classifier
Python 3.5 support was added to the gate jobs. Since Bandit fully
passes those tests, we can now claim Python 3.5 support in the
classifier.

Change-Id: Ia733ec36ce2350b5273031e4ab2491b344fd2bd2
2016-07-05 18:57:03 -07:00
Christopher J Schaefer cac2f22dee Added try_except_continue plugin
Along with a 'try, except, pass' check, we should also check for the
similar existance of 'try, except, continue', which raises the same
type of security implications, given the similar type of functionality.
Using 'continue' in place of 'pass' (inside a loop) currently allows
code to bypass the 'try, except, pass' warning.

Change-Id: I3e7ce037518875c5f5e46e26e1d72ef878f78a2f
2016-03-24 12:09:12 -05:00
Tim Kelsey 24eba90cce Fixing documentation for hardcoded password tests
The docs for these tests were very out of date. This fixes them
and also removes the old wordlist, as its not used by anything.

Change-Id: I28c047dfd0041824e08e28e1239ccbae8c7141a0
2016-03-23 16:28:56 +00:00
Tim Kelsey c71d430c0c Delete the config, we dont need it now and its also invalid
Change-Id: I595b5472128802acc0e87031276051afa47e2de3
2016-03-23 16:28:45 +00:00
Eric Brown 1a41a2e333 Use bdist_wheel instead of wheel
According to the wheel docs, [bdist_wheel] should be used. Apparently
[wheel] is the legacy, deprecated way.

https://goo.gl/B8tFgs

Change-Id: I7cf882175d724776f861fb82ffd7e0c8682b647e
2016-02-24 23:55:10 -08:00
Tim Kelsey a9839d4266 Breaking out blacklists
This change removes the old blacklist plugins and replaces them
with new built in functionality that loads blacklist item data
from a new plugin entry point. The new test also improve on the
old functionality that was broken in the following way:

import xml.sax # issue found OK
from xml import sax # no issue found, wrong

Finally, this patch removes the use of filename style wild cards
such as * from the import blacklist matching, as this was not being
used. Both this test and the old ones will alert on any import from
within the blacklisted namespace.

Change-Id: I98af6daf3c54561c0e4b399605ea615b42b7b283
2016-01-19 13:33:00 +00:00
Jenkins 1bcc08f23f Merge "Split yaml blacklist check into its own file" 2016-01-14 21:58:35 +00:00
mattvaldes b09c0e38c6 Split yaml blacklist check into its own file
Allow SafeLoader to be passed to the Loader parameter
Closes-bug: 1508490

Change-Id: I7459577e175b5f2a623316e22c63b2d42ba1db25
2016-01-14 15:46:04 -06:00
Ian Cordasco 0bd057bb9c Move cli modules into their own submodule
Change-Id: I953b3c4c17202c0738ec6b9dc17f65742126cbd0
2016-01-14 14:20:20 -06:00
Timothy Kelsey b6e0bcaa3a Adding new screen formatter
This work relates to efforts to remove the config file (see spec).
Here we are adding a new formatter plugin "screen" to produce the
VT100 colored output report that is dumped to a terminal. Before
this was done by some detection logic in the txt formatter. This
chnges the txt formatter so it now always dumps simple text output.

Work has also been done to move logic relating to specific formats
out of the manager class. Formatters are plugins and as such
should be entirely opaque to the manager.

Change-Id: Ifc76eace1f84e8808480a352f403eff757641e8f
2015-12-21 16:44:45 +00:00
Jenkins 353634ff7a Merge "Use sphinx autodoc to generate docs from docstring" 2015-12-16 04:03:09 +00:00
Eric Brown 222c0809b3 Use sphinx autodoc to generate docs from docstring
Rather than having separate rst documentation files, this patch auto
generates the docs from the docstrings in the modules. Should
make it easier to maintain.

Also renamed directory docs to doc to be consistent with all other
OpenStack projects.

Change-Id: Iaed77f8358ccb6edaf2627fbabdcc855272b4ea2
2015-12-15 16:57:57 -08:00
Travis McPeak 00d59dee2c Adding bandit-baseline tool
This commit adds a tool which will run Bandit against the parent
commit of a current branch, and then run Bandit in baseline mode
using the parent's results as the baseline.  Any options that are
supplied to the script will be passed as options to Bandit (for
example severity filters, targets, etc).

By including this tool we can allow projects to run Bandit
baseline as part of their existing tox jobs.

Change-Id: Iaa1314aa348c7c5ca03c5c8b7dcfee456f279e56
2015-12-10 15:50:49 -08:00
Cyril Roelandt 18bbfcc20e Add a configuration generator for bandit
This allows project developers to generate a valid configuration for their
project, that can easily be updated. Example of use:

$ cat oslo_messaging.yaml
profile_name: gate
exclude_checkers: [assert_used, try_except_pass]

$ bandit_config_generator.py \
    --out /tmp/bandit.yaml \
    bandit.yaml \
    oslo_messaging.yaml

Change-Id: I0b678b26ffa7dbe6034bdc7b35862e15c61c3670
Blueprint: bandit-conf-generator
2015-11-16 10:56:32 +01:00
Jamie Finnigan 517ab2f7ab Add check for Flask app debug=True usage
When executed with debug=True, Flask applications expose the Werkzeug
debugger which includes an abritrary code execution function.

This check looks for a combination of the flask module being imported,
a .run() call, and a named argument debug=True.

Setting it up in plugins/app_debug.py so we can add checks for Django
and perhaps other frameworks in future.

Change-Id: If49e53d0807dfc2fccad6433edc5ef43f5464f22
Implements: blueprint detect-werkzeug-debug-enabled
2015-10-13 13:56:35 -04:00
Tim Kelsey 604ca79759 Improved tests for hardcoded passwords
This replaces the existing hardcoded password test with a number of
smarter tests. None of the new tests utilize a word dictionary, we
now trigger the warnings based on matching variable names and the
like against a list of candidate names:

 - "password"
 - "pass"
 - "passwd"
 - "pwd"
 - "secret"
 - "token"

hardcoded_password_string looks for:
 candidate = "some_string_literal"
 dict[candidate] = "some_string_literal"
 candidate == "some_string_literal"

hardcoded_password_funcarg looks for:
 func_call(candidate="some_string_literal")

hardcoded_password_default looks for:
 def func_def(candidate="some_string_literal"):

All issues are reported as MEDIUM confidence, LOW severity

Closes-bug: #1502348
Closes-bug: #1502343
Closes-bug: #1432887

Change-Id: I36d97ee838a7f08234b759c352649721d07e8ab0
2015-10-06 15:43:33 +01:00
Charles Neill 21514e8d4d Adding HTML formatter
This patch adds the ability to output results in HTML format. It
currently doesn't support syntax highlighting due to fact that the Pygments
library is not in OpenStack's list of blessed requirements.

Change-Id: Ia9087a01856c1c743abba9fe4492130403b0f0d4
2015-09-10 11:48:09 -05:00
Eric Brown f8c22f8b64 Split each formatter into separate modules
As we increase the number of formatters, it doesn't make sense to
cram each into a single module.  This patch splits them up by
output format type.

Any new formatter should also be implemented as a separate module.

Change-Id: Ibbd0edb9af06a52bef28804a6619a07f323931e6
2015-09-08 15:31:20 -07:00
Jenkins 08404174f6 Merge "Merge the two weak_cryptographic_key checks" 2015-09-07 08:31:22 +00:00
Eric Brown 1f021719ff Merge the two weak_cryptographic_key checks
We don't need two separate checks:
    weak_crypto_key_size_cryptography_io
    weak_crypto_key_size_pycrypto

This patch combines them into a single check:
    weak_cryptographic_key

Change-Id: I9626341a6f00a52fcc0eb11621c261fbc3f656e5
2015-09-04 10:38:58 -07:00
Brant Knudson 49d98a3112 Generate module docs
The module docs will now be generated.

Change-Id: Ifdaf1058ff90a23be509bc0518c6e4142eda64b6
2015-09-03 14:50:58 -05:00
Eric Brown f0dd2e152a Add a new check for weak RSA and DSA key sizes
This patch adds a new check to bandit that scans for key sizes of
RSA and DSA algorithms when using the pycrypto or cryptography.io
modules.

Change-Id: I7d740eccc73a49f7ee133d90177d19d5ef7b02ba
2015-09-02 17:13:30 -07:00
Dave Walker (Daviey) 80c7798e51 Actually default to /etc/ rather than just claim
Previously, we were claiming to default to
/etc/bandit/bandit.yaml for config location, but we were
neither installing a config there, nor trying to use it at
run time.

This makes use of appdirs for locations to use platform
declared config locations.  This also tries to install
the bandit.yaml in /etc/bandit.yaml. (Or on a local
pip install: /usr/local/etc/bandit/bandit.yaml)

The searched paths are also added to the README to help
avoid ambiguity.

Change-Id: I29a9ff738ebb402a069b9750d26e4c94f85e861a
Closes-Bug: #1475510
Signed-off-by: Dave Walker (Daviey) <email@daviey.com>
2015-08-05 18:54:56 +01:00
Ian Cordasco fa9c14e243 Build universal wheels for PyPI
Change-Id: Icd5ab5df801d7cff28deea23c569e1c4ba4b618a
2015-08-05 09:13:11 -05:00
Brant Knudson 0052cd7476 Convert README to rst
PyPI showed the README.md without any formatting so it didn't
look good. Convert it to rst.

Change-Id: If5829f90059751146be85d3ed980df38fe865e0f
2015-08-04 09:34:55 -05:00
Eric Brown 9dc80a59cf NIT: Fix missing python 3 in classifier
Python 3.4 was added, but not Python 3.

TrivialFix

Change-Id: Ie84021f55785deadd1064f58a2d085b6bc5477ec
2015-08-03 22:31:29 -07:00
Jenkins f6bb6a836b Merge "Adding documentation framework" 2015-07-29 15:27:04 +00:00
Tim Kelsey 4b03e062f1 Revised XML tests
The XML test plugins were all checking for a specific function call
or a specific module import. This functionality exists in a generic
form via blacklist_imports and blacklist_calls. This changes removes
the specific XML tests and replaces the functionality using these
blacklist checks.

Closes-bug: 1477542
Change-Id: I7bcd5a9c2d9343e6306285afca59012579ab0a9a
2015-07-24 15:59:42 +01:00
Tim Kelsey 42f3e2961a Adding documentation framework
This adds documentation framework for Bandit. To build the new
documentation you can use the new tox target:

  tox -e docs

This will spit out various formatted output into the docs/build
folder.

Change-Id: I3497e26052021900ad55ecdd2517198b22e82f0e
Partial-Bug: 1474796
2015-07-24 13:20:16 +01:00
Dave Walker (Daviey) 20c12cde76 Register plugins included as entry-points
Previously, we tried to load the default plugins by using the path to
bandit to import them dynamically and load them. This is unreliable on
systems where the default path and the actual path are different
depending on how bandit is installed. By using entry-points, we can
completely side-step this problem.

 _______
< FIXED >
 -------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Closes-Bug: #1475681
Co-Authored-By: Ian Cordasco <graffatcolmingov@gmail.com>
Signed-off-by: Dave Walker (Daviey) <email@daviey.com>
Change-Id: I19eed3b312c921e98bdabfb346cddd406186d963
2015-07-17 14:42:07 -05:00
Dave Walker (Daviey) 78643c5b21 Install word_list, raise exception if cannot find
Previously, the default bandit.yaml config file had an entry
for a relative word-list which is only really useful if
running bandit from git, as the path is both relative but
also the default word-list is not installed by the bandit
python package.

If the word-list from the config cannot be found, the
current behavior is to silently continue with an empty set,
meaning that this test does not function at all - giving a
false sense of assurance.

This change installs the default word_list to:
  - /usr/local/share/bandit/wordlist/default-passwords

The config file now supports "(site_data_dir)" for
substitution, which is replaced by distro standard site_data
locations (including /usr/local and /usr).

The first substitution attempted is still relative to the
pwd, to allow the current working tree (and unit tests) to
function).

Crucially, this change now raises an exception if the
declared word-list cannot be found.

Closes-Bug: #1451575
Signed-off-by: Dave Walker (Daviey) <email@daviey.com>
Change-Id: Ia090ee6b16866d374191c03de55529fbd6a10c99
2015-07-14 22:13:12 +01:00
Ian Cordasco 1c4d8dfd40 Add extension entry-points and loading
This allows Bandit to be extended by third-party packages with both
plugins and formatters. It also updates Bandit's existing in-tree
formatters to be loaded by the plugin manager. When running

    $ bandit -h

The loaded plugins will be displayed to the user if any are installed.

Change-Id: I102277dcd9481f2573028a436e910eda10011d91
2015-06-19 19:59:35 -05:00
Ian Cordasco ddf75663ce Add Python 3.4 compatibility to bandit
This includes a number of changes to make this happen:

- We handle the fact that in Python 3.3 and later, ast.TryExcept and
  ast.TryFinally were replaced by ast.Try

- We handle the fact that ast.NameConstant is now the node type for
  True/False

- We handle the cases where map and range need to return lists

- We remove a property from the result store to prevent errors assigning
  to the underlying attribute

- We check for exec conditionally based on the version of Python

- We use proper octal notation, e.g., 0o755

Change-Id: I71c0bb61c9ee0bf1b751a719a4eb95bf7a0b4943
2015-06-03 11:19:03 -05:00
Travis McPeak f11e9b8ace Update the README file
The readme file has been updated to:
 - Be more concise up front about the purpose of Bandit
 - Reflect new install methods (from PyPI)
 - Update configuration section
 - Convert to markdown format (we had this anyway, it was just
called .rst for some reason)

Change-Id: Ibb39e9fe64760323240c1180d4df8c8e21349ecb
2015-05-06 16:45:15 -04:00
Travis McPeak ac19bb5e95 Changing config file search paths
This commit changes the location that the Bandit config file,
bandit.yaml, is stored and how it is packaged.  Previously, the
config file was listed as a data_file which is supposed to be
outside of the Bandit installed package.  This meant that
depending on the system it might be installed in different places
(/etc, or /usr/lcoal/etc, for example).  When Bandit was installed
in a virutal environment the installed location would change once
again.  Another disadvantage to this approach is that installing
Bandit might require sudo, and Bandit might not clean up its
config properly.

This commit changes the packaging so that bandit.yaml is always
installed in bandit/config/bandit.yaml.  If there is a bandit
config file in the current directory or the user's home directory,
these are still preferred.

Change-Id: I5f971aa208dd2599f852b5253b4401990201cc8f
2015-05-06 12:18:22 -04:00
Eric Brown cc461d17b8 Update email to openstack-dev
Change-Id: I1447af2503080d3f392fbebe4f2f0294a027feb7
2015-03-27 12:12:54 -07:00
Tim Kelsey 5cc8b761f1 fixing bandits config settings
This will now look for a 'bandit.yaml' file in the local folder
before falling back to ${HOME}/.config/bandit/bandit.yaml and
finally /etc/bandit/bandit.yaml. If -c is used to explicitly
specifiy a config file this will override all other behaviour.
If the specified file is not found then an error is reported.

Change-Id: Ie49a98f970ab31e9709e93ce06687f6457f03dce
2015-03-24 18:57:06 +00:00
David Wyde 0d791cd524 Remove Python 2.6 from setup.cfg
Bandit uses `collections.OrderedDict`, which Python 2.6 lacks.

Change-Id: I3fcd4f204d4f558204cab734d738c69aa7c0325a
2015-03-13 12:34:22 -05:00
Jamie Finnigan 24f59f64a2 Correct supported Python versions in setup.cfg
Remove claims of Python 3 support until we get around to implementing
Python 3 support.

Change-Id: I8b1aba541879ce6dbd7af7d7da47dd3a2bf32366
2015-03-12 15:20:02 -07:00
Eric Brown 592174db8b Rename README.md to README.rst
PyPi expects README.rst.

Change-Id: I6c20a260499640e04b6d96506e1c223111955e12
2015-02-17 12:51:35 -08:00
Tim Kelsey 8e6697b063 Making Bandit into an installable package and adding tox tests
This large change makes bandit into an installable packahge, needed
for tox testing. I have added the tox testing scaffolding but no
real tests, they will come in a later change. I have also disabled
all failing PEP8 test (lots) since I have changed enough stuff for
one patch. I'll start re-enabling and fixing PEP8 stuff soon.

Change-Id: I774ed9149f285e4e2bceacda0484a7e2a934a3aa
2014-10-22 10:15:28 +01:00