Skip to content

Commit

Permalink
Fix crash on pyproject.toml without bandit config (#1073)
Browse files Browse the repository at this point in the history
* Fix crash on pyproject.toml without bandit config

This is a naive fix for bandit crashing when it encounters a
`pyproject.toml` which does not contain any specific bandit
configuration.

This resolves the common failure mode that is seen, but does not cause
bandit to fall back to another configuration source if the
`pyproject.toml` does not contain any `tool.bandit` block.

Resolves #1027

* Update bandit/core/config.py

---------

Co-authored-by: Eric Brown <ericwb@users.noreply.github.com>
  • Loading branch information
javajawa and ericwb committed Dec 8, 2023
1 parent 6b2e247 commit 0d35086
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bandit/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def __init__(self, config_file=None):

try:
with f:
self._config = tomllib.load(f)["tool"]["bandit"]
self._config = (
tomllib.load(f).get("tool", {}).get("bandit", {})
)
except tomllib.TOMLDecodeError as err:
LOG.error(err)
raise utils.ConfigError("Error parsing file.", config_file)
Expand Down

0 comments on commit 0d35086

Please sign in to comment.