bandit icon indicating copy to clipboard operation
bandit copied to clipboard

Bandit 1.6.3 does not respect excluded paths from .bandit file

Open budgester opened this issue 4 years ago • 16 comments

With a .bandit file with the contents

[bandit]
exclude: ./.tox,./tests

1.6.2 gives

$ bandit -r -ll -ii .
[main]	INFO	Found project level .bandit file: ./.bandit
[main]	INFO	Using ini file for excluded paths
[main]	INFO	Using command line arg for selected targets
[main]	INFO	profile include tests: None
[main]	INFO	profile exclude tests: None
[main]	INFO	cli include tests: None
[main]	INFO	cli exclude tests: None
[main]	INFO	running on Python 3.7.5
114 [0.. 50.. 100.. ]

1.6.3 ignores the exluded paths

$ bandit -r -ll -ii .
[main]	INFO	Found project level .bandit file: ./.bandit
[main]	INFO	Using command line arg for excluded paths
[main]	INFO	Using command line arg for selected targets
[main]	INFO	Using command line arg for recursive scan
[main]	INFO	Using command line arg for aggregate output type
[main]	INFO	Using command line arg for max code lines output for issue
[main]	INFO	Using command line arg for severity level
[main]	INFO	Using command line arg for confidence level
[main]	INFO	Using command line arg for output format
[main]	INFO	Using command line arg for output file
[main]	INFO	profile include tests: None
[main]	INFO	profile exclude tests: None
[main]	INFO	cli include tests: None
[main]	INFO	cli exclude tests: None
[main]	INFO	running on Python 3.7.5
549 [0.. 50.. 100.. 150.. 200.. 250.. 300.. 350.. 400.. 450.. 500.. ]

budgester avatar Dec 07 '20 12:12 budgester

To perhaps save a maintainer a couple minutes of searching, it looks to me like this commit most likely causes the breaking behavior.

Edit: Also, the documentation for that command line parameter appears to be wrong: it says it should act in addition to the setting in the config file, whereas it actually overrides the setting in the config file.

rjb3977 avatar Dec 07 '20 20:12 rjb3977

I can also reproduce this regression.

xuhdev avatar Dec 07 '20 22:12 xuhdev

Still broken in 1.7.0 :-(

sirkonst avatar Dec 14 '20 07:12 sirkonst

We also ran into this issue when upgrading from 1.6.2 to 1.7.0

what could be a proposed fix? I don't know the codebase (yet), but could help

syphar avatar Dec 14 '20 12:12 syphar

I believe this commit has broken things: https://github.com/PyCQA/bandit/commit/ca6d28356947d2c1ccb5eb92ec77fc8e3fcab515

What's interesting though, skips works just fine, thought it seems implemented the same way.

codingjoe avatar Dec 15 '20 10:12 codingjoe

I believe this commit has broken things: ca6d283

What's interesting though, skips works just fine, thought it seems implemented the same way.

I'm still pretty sure that 5ac8b8bf0a364a5222080db7c7e1951c0901e7a2 is the culprit. It added a default value for the excluded paths command line argument. That argument overrides the configuration file's excluded paths, rather than merging with it, like the documentation / help message suggests. So now, the excluded paths in the configuration file are always overridden.

rjb3977 avatar Dec 15 '20 15:12 rjb3977

Yes, you are right, the default seems to be the problem. It needs to be added at a later point.

codingjoe avatar Dec 15 '20 15:12 codingjoe

Yes, you are right, the default seems to be the problem. It needs to be added at a later point.

Or it could be made so that the command line argument does in fact merge with the config file's exclusions. The help text for that argument says "note that these are in addition to the excluded paths provided in the config file", which is incorrect.

rjb3977 avatar Dec 15 '20 16:12 rjb3977

Yes, you are right, the default seems to be the problem. It needs to be added at a later point.

Or it could be made so that the command line argument does in fact merge with the config file's exclusions. The help text for that argument says "note that these are in addition to the excluded paths provided in the config file", which is incorrect.

No, I wouldn't do that. That would be backwards incompatible, and we won't see a fix released until kingdom come.

codingjoe avatar Dec 15 '20 19:12 codingjoe

Is there a conclusion to this issue?

xuhdev avatar Jun 16 '21 23:06 xuhdev

running into this issue as well - has there been a fix?

iflament avatar Feb 01 '22 03:02 iflament

Release 1.7.4 - not resolved (

shtalinberg avatar Sep 05 '22 09:09 shtalinberg

I confirm, last version doesn't fix the problem, it still scans the .venv directory.

bandit -r -x "$(pwd)/.venv/" .

Edit:

With this command that works good :

bandit -r . -x */.venv/*

oijkn avatar Jan 02 '23 17:01 oijkn

Looks like Release 1.7.5 - resolved it!? works fine for me

shtalinberg avatar Mar 15 '23 10:03 shtalinberg

If I run the following script:

echo 'assert 2 > 1' >assert.py
cat >.bandit <<BANDIT
[bandit]
exclude: assert.py
BANDIT
bandit -r .

The test fails with "Issue: [B101:assert_used]..." on 1.7.0 and passes with "No issues identified." in 1.7.1. Bisecting shows that this was fixed by #722.

kevinoid avatar Mar 17 '23 20:03 kevinoid