bandit: Bandit 1.6.0 no longer respects excluded directories
Describe the bug Prior to the bandit 1.6.0 release, I was using bandit like so:
bandit -r . -x ./mymodule1/tests/,./mymodule2/tests/
However, with bandit 1.6.0 the ./mymodule1/tests/ and ./mymodule2/tests/ directories are included in the results. I have confirmed that you can exclude individual files still, just not directories.
To Reproduce Steps to reproduce the behavior:
- Create a directory with a vulnerability in it somewhere
- Run
bandir -r . -x ./your-new-dir/ - See vulnerability results that should be excluded
Expected behavior
Bandit should be excluding the directories entirely that are passed as args to the -x flag.
Bandit version
bandit 1.6.0
python version = 3.6.5 (default, Jun 17 2018, 12:13:06) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)]
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 32
- Comments: 25 (4 by maintainers)
Commits related to this issue
- pin Python developer requirement bandit to version 1.5.1 https://github.com/PyCQA/bandit/issues/488 — committed to bsdci/libioc by gronke 5 years ago
- pin Python developer requirement bandit to version 1.5.1 https://github.com/PyCQA/bandit/issues/488 — committed to bsdci/libioc by gronke 5 years ago
- pin Python developer requirement bandit to version 1.5.1 https://github.com/PyCQA/bandit/issues/488 — committed to bsdci/libioc by gronke 5 years ago
- tests: temporarily force bandit < 1.6.0 * Due to a bug upstream bandit 1.6.0 doesn't honor the excluded directories, causing the failure of the bandit tox environments. See https://github.com/PyC... — committed to wikimedia/operations-software-spicerack by volans- 5 years ago
- Add more specific exlcude paths for bandit Workaround for bug reported here: https://github.com/PyCQA/bandit/issues/488 Signed-off-by: Ryan Beck-Buysse <rbuysse@bitwise.io> — committed to rbuysse/sawtooth-poet by rbuysse 5 years ago
- Add more specific exclude paths for bandit Workaround for bug reported here: https://github.com/PyCQA/bandit/issues/488 Signed-off-by: Ryan Beck-Buysse <rbuysse@bitwise.io> — committed to rbuysse/sawtooth-poet by rbuysse 5 years ago
- Add more specific exclude paths for bandit Workaround for bug reported here: https://github.com/PyCQA/bandit/issues/488 Signed-off-by: Ryan Beck-Buysse <rbuysse@bitwise.io> — committed to Cargill/sawtooth-core by rbuysse 5 years ago
- Blacklist Bandit 1.6.0 due to directory exclusion bug Bandit 1.6.0 introduces a regression[0] with the -x option, a fix is expected to be included in 1.6.1 soon. [0] https://github.com/PyCQA/bandit/... — committed to openstack/python-openstackclient by deleted user 5 years ago
- Update git submodules * Update python-openstackclient from branch 'master' - Blacklist Bandit 1.6.0 due to directory exclusion bug Bandit 1.6.0 introduces a regression[0] with the -x optio... — committed to openstack/openstack by deleted user 5 years ago
- Blacklist bandit 1.6.0 due to directory exclusion bug Bandit 1.6.0 introduces a regression[0] with the -x option, a fix is expected to be included in 1.6.1 soon. [0] https://github.com/PyCQA/bandit/... — committed to openstack/neutron by deleted user 5 years ago
- Update git submodules * Update neutron from branch 'master' - Blacklist bandit 1.6.0 due to directory exclusion bug Bandit 1.6.0 introduces a regression[0] with the -x option, a fix is... — committed to openstack/openstack by deleted user 5 years ago
- Blacklist bandit 1.6.0 due to directory exclusion bug Bandit 1.6.0 introduces a regression[0] with the -x option, a fix is expected to be included in 1.6.1 soon. [0] https://github.com/PyCQA/bandit/... — committed to openstack/neutron-lib by deleted user 5 years ago
- Update git submodules * Update neutron-lib from branch 'master' - Blacklist bandit 1.6.0 due to directory exclusion bug Bandit 1.6.0 introduces a regression[0] with the -x option, a fi... — committed to openstack/openstack by deleted user 5 years ago
- Blacklist bandit 1.6.0 There's a regression[0] in bandit 1.6.0 which causes bandit to stop respecting excluded directories, and our tests throw a bunch of violations. Blacklist this version, but allo... — committed to openstack/keystone by jimrollenhagen 5 years ago
- Update git submodules * Update keystone from branch 'master' - Blacklist bandit 1.6.0 There's a regression[0] in bandit 1.6.0 which causes bandit to stop respecting excluded directorie... — committed to openstack/openstack by jimrollenhagen 5 years ago
- Blacklist bandit 1.6.0 There's a regression[0] in bandit 1.6.0 which causes bandit to stop respecting excluded directories, and our tests throw a bunch of violations. Blacklist this version, but allo... — committed to openstack/keystone by jimrollenhagen 5 years ago
- Blacklist bandit 1.6.0 There's a regression[0] in bandit 1.6.0 which causes bandit to stop respecting excluded directories, and our tests throw a bunch of violations. Blacklist this version, but allo... — committed to openstack/keystone by jimrollenhagen 5 years ago
- Blacklist bandit 1.6.0 There's a regression[0] in bandit 1.6.0 which causes bandit to stop respecting excluded directories, and our tests throw a bunch of violations. Blacklist this version, but allo... — committed to openstack/keystone by jimrollenhagen 5 years ago
- Blacklist bandit 1.6.0 There's a regression[0] in bandit 1.6.0 which causes bandit to stop respecting excluded directories, and our tests throw a bunch of violations. Blacklist this version, but allo... — committed to openstack/keystone by jimrollenhagen 5 years ago
- Blacklist bandit 1.6.0 There's a regression[0] in bandit 1.6.0 which causes bandit to stop respecting excluded directories, and our tests throw a bunch of violations. Blacklist this version, but allo... — committed to openstack/keystone by jimrollenhagen 5 years ago
This issue still exists nearly one year later on Bandit 1.6.2. Unclear why it is closed.
While it makes very little sense,
-xor--excludeseems to require a./-prefaced relative path.E.g. if you have a
venvin your current directory:will work as intended whereas
Will attempt to scan all of
venv/.The current arg is:
Which gets passed to
discover_files():https://github.com/PyCQA/bandit/blob/c6b1302e7b1ab1ad78799264d8ca7222f2c3d428/bandit/cli/main.py#L457
Independent of this issue, it might be sensible to add
venvtoconstants.EXCLUDE.@ericwb please reopen based on ample evidence above.
The help output says that it excludes
.toxby default, but my tox-dir is still scanned which is quite useless.This is certainly not resolved and needs to be reopened.
I am trying to use bandit 1.6.2 and excluded directories are not respected. This issue does not appear to be fixed.
Interestingly, specifying an absolute target path combined with absolute exclusion paths seems to work:
tox.iniAlso, specifying all absolute paths in a Tox target, a section in
tox.ini, “fixes” the issue:Looks like there is still some hidden issue that needs fixing.
I’ve faced just the same issue on 1.7. This command is hanging for several minutes:
as well as this one:
but this one works just as expected:
Still having this issue in 1.7.0, pinning to 1.5.1 doesn’t help. For gitlab reasons I had to include the virtualenv inside the project_root and bandit ignores all attempts to ignore that folder… Command:
bandit --exclude .pipenv/* -r -ll .Can confirm here than it still doesn’t work when I add exclude tests to
pyproject.tomlJust confirming that this issue still persists in 1.7
@zelenyjan There are a few interesting facts about the information your share:
exclude_dirsoption from? It’s neither in the documentation (which says,exclude) nor in the CLI help screen, Only from the code this can be seen. Which suggests that we have a bug in the docs.exclude_dirsoption covers not only directories: You can specify a path to a single file, which then also gets excluded, specifically. (The naming seems a bit misleading.)exclude, which is consistent with the docs but inconsistent with what is considered from a TOML (or YAML) file.Can you share your complete Bandit (and Tox) configuration, please?
Also, can you try to run against
.instead ofsrc(which will likely walk directories like.git,.toxand.venvif they are not ignored effectively)?Related: #528
And yes, the implementation of the config parsing is super-complicated and probably warrants a complete rewrite. 😟
Coming back here include my workaround.
Using absolute paths has worked, but since that wasn’t an option for gitlab i found that
bandit --exclude ./.pipenv/* -r -ll .seems to respect the excluded folder.
@LefterisJP I’m using bandit 1.6.2 and it works, however it depends on how you specify all paths. I’m using all full relative paths (eg.
bandit -x './tests' -r .). If I omit./at the beginning of the exclude directory, that directory is not considered in the exclusion. It seems also that this behavior is the same with the full path, as stated by @bittner . There is definitively an issue on path handlingI tried to play a little with exclude directory in
1.6.0.After changing
bandit -r anitya/ anitya_schema/anitya_schema/ -x anitya/db/migrations -lltobandit -r anitya/ anitya_schema/anitya_schema/ -x anitya/db/migrations/* -ll, the excluded folders are no longer ignored.So before
1.6.1is out, you could use the above.