Baseline matching ignores line number and uses set membership, not count
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 75/100
Research direction
Start by reading Issue.eq in bandit/core/issue.py and _compare_baseline_results in bandit/core/manager.py, then reproduce the baseline scenario from the issue. Add focused coverage for repeated findings and verify that baseline filtering respects occurrence counts or distinct line identities, while existing baseline suppression continues to work.
Written by the indexing model from the issue text.
Description
Describe the bug
Issue.eq (bandit/core/issue.py) compares text, severity, cwe, confidence, fname, test, test_id -- not lineno. And _compare_baseline_results (bandit/core/manager.py) filters with "a not in baseline", i.e. set membership, not multiplicity. So one baseline entry with a given signature can absorb any number of new findings with the same signature in the same file, not just a same-count swap -- an unlimited one.
Reproduction steps
1. app.py has 1 B105 violation (hardcoded password) at line 2. Run: bandit -f json -o baseline.json app.py -> baseline stores 1 issue.
2. Fix the original violation for real (remove the hardcoded password from that function).
3. Introduce 2 new B105 violations with the same literal text in two different functions (lines 6 and 10).
4. Run: bandit -f json app.py (no baseline) -> 2 results.
5. Run: bandit -b baseline.json app.py -> "No issues identified.", exit 0.
Expected behavior
The baseline should only suppress the specific violation it recorded. Since only one violation was in the original baseline, at least the two new violations (different lines, same rule) should surface -- not be silently absorbed because the total count happens to be small.
Bandit version
1.9.1 (Default)
Python version
3.14 (Default)
Additional context
Suggest: include lineno (or a stable per-occurrence identity) in Issue.eq, or at minimum count occurrences per signature and only filter matching count instead of set membership (currently a not in baseline).
Reproduced locally on bandit 1.9.4 (pip install bandit) -- the version dropdown above only lists up to 1.9.1, closest available option kept as default.
Background, optional: https://doi.org/10.5281/zenodo.21908527
- 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