Empty or scalar YAML config crashes before type validation
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
Research direction
Start with BanditConfig.validate() in bandit/core/config.py and the existing dictionary check that currently runs after validation. Read the configuration tests and add malformed-root cases for empty, null, boolean, numeric, string, and sequence YAML values, keeping {} valid. Done means invalid roots use the ConfigError/CLI error path without a traceback.
Written by the indexing model from the issue text.
Description
Describe the bug
At main commit 48ef27bd1bbc32f4e585c92310f7a574e87f6b04, an empty YAML config raises TypeError in BanditConfig.validate(). The existing dictionary check runs after validation, too late to reject the parsed value. Scalar roots and a sequence containing profiles have the same ordering problem.
This resembles the symptom in historical #139, but the current failure is in legacy-profile validation, before the existing non-dictionary check.
Reproduction steps
printf '' > /tmp/bandit-empty.yaml
printf 'x = 1\n' > /tmp/bandit-clean.py
bandit -c /tmp/bandit-empty.yaml /tmp/bandit-clean.py
# Traceback: bandit/core/config.py line 252, in validate
# if "profiles" in self._config:
# TypeError: argument of type 'NoneType' is not iterable
Expected behavior
Reject invalid configuration through the existing ConfigError/CLI error path, without a traceback. An empty dictionary ({}) should remain valid.
Bandit version
1.9.1 (Default)
Python version
3.12
Additional context
Tested source checkout: 48ef27bd1bbc32f4e585c92310f7a574e87f6b04, Python 3.12.14 on Linux. The editable install reports version 0.0.0; the required Bandit version dropdown has no source-checkout option, so its default is not the tested release version.
Tested patch: https://github.com/arin30/bandit/commit/f769648f3c7be0a7d2adfc13a3095f809ac94137
The fix moves the existing dictionary check ahead of self.validate(config_file). Added malformed-root coverage for empty, null, boolean, numeric, string and sequence values, plus a valid empty-mapping control.
The new malformed-root regression fails on the base. With the patch, all 181 unit tests pass, including 28 configuration tests. Seven actual CLI checks confirm invalid roots exit 2 without a traceback and {} scans successfully. Black 25.12.0 with repository settings, Flake8 on both changed files, and git diff --check pass.
I couldn't open a PR because the repository currently limits PR creation to collaborators. The patch is available above for review. No detection rules change.
- Dominant language
- Python
- Stars
- 8.4k
- Forks
- 893
- Avg merge
- 6h 52m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PyCQA/bandit
-
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Turn off progress bar in CIPossibly taken @silvatechf claimed this 28 days ago. Openenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
`bandit -ii -ll -ii -ll` raises an `IndexError`Possibly taken @botbikamordehai2-sketch claimed this 181 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
NatLabRockies/openstudio-mcp#286 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
intersystems/ipm#1338 ·
Maintainers usually reply within 1 day
-
separate_packages splits imports from the same explicitly configured packagePossibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
The v0-through-v1 path derives ShutdownDuration its own way, silently overriding a user's definitionOpenv1
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day