Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reading initial values from .bandit #722

Merged
merged 2 commits into from Nov 11, 2021
Merged

fix reading initial values from .bandit #722

merged 2 commits into from Nov 11, 2021

Conversation

alipqb
Copy link
Contributor

@alipqb alipqb commented Jul 10, 2021

How to fix reading .bandit initial values:

Previously bandit was not able to read initialization values from the .bandit file
like the exclude keyword. This has caused a lot of CI pipelines that were using
bandit to fail. In this pull, I have tried to fix this problem.

What was the main problem that was causing this bug?

The CLI of bandit is written with python's popular library argparse .
The main problem was with the handling of default arguments' values
of the bandit command-line program. The program was not able to
distinguish between manually passed arguments and default arguments
values. Before In the first line of _log_option_source function in
bandit.cli.main.py, the function only checked whether arg_val exists
or not. At first glance, it seems that this is a correct action, but the truth is
that this function fails when the default value of an argument is a string
like --exclude. When we didn't pass an argument to --exclude, the value
of arg_val would be equal to default value of the argument and passed
the if condition and will neglect the initial value in the .bandit file.

Resolves: #499, #595

@sigmavirus24 sigmavirus24 merged commit a83c53f into PyCQA:master Nov 11, 2021
kevinoid added a commit to kevinoid/python-project-template that referenced this pull request Mar 17, 2023
Move the list of excluded files from --exclude in tox.ini to
exclude_dirs in pyproject.toml to centralize configuration in
pyproject.toml and make it accessible to tools and bandit invocations
outside of tox.

- Remove the comment that exclude is ignored by bandit 1.6.3+, which was
  fixed by PyCQA/bandit#722 in bandit 1.7.1.
- Change exclude (which only works for INI files) to exclude_dirs (which
  only works for TOML and YAML files), as described in
  PyCQA/bandit#876
- Add /.git/ and /__pycache__/ to exclude_dirs to match --exclude.
- Remove --exclude from invocation in tox.ini

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude paths in config file ignored if passing specific files to Bandit CLI
2 participants