Skip to content

Commit 0d35086

Browse files
javajawaericwb
andauthored
Fix crash on pyproject.toml without bandit config (#1073)
* 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 <[email protected]>
1 parent 6b2e247 commit 0d35086

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

bandit/core/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def __init__(self, config_file=None):
5252

5353
try:
5454
with f:
55-
self._config = tomllib.load(f)["tool"]["bandit"]
55+
self._config = (
56+
tomllib.load(f).get("tool", {}).get("bandit", {})
57+
)
5658
except tomllib.TOMLDecodeError as err:
5759
LOG.error(err)
5860
raise utils.ConfigError("Error parsing file.", config_file)

0 commit comments

Comments
 (0)