False negative: narrow argument-shape checks in B508/B509

Open
#1,397 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #1398 by @9iang22 — closed without merging
  • #1433 by @omobolajiadeyan — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
security

Research direction

Start in bandit/plugins/snmp_security_check.py at the B508 and B509 checks, then compare their argument handling with each reproduction case in the issue. Use the omitted, positional, and keyword examples as regression cases; done means B508 consistently evaluates mpModel and B509 evaluates privacy semantically without the reported false negatives or false positive.

Written by the indexing model from the issue text.

Description

bug
Describe the bug

B508 and B509 currently rely on narrow argument-shape checks in bandit/plugins/snmp_security_check.py.
This causes:

  • false negatives for insecure SNMP usage when arguments are omitted/positional
  • false positives for secure UsmUserData configs passed via kwargs
Reproduction steps
# Orignal Test Cases:

# SHOULD FAIL
a = CommunityData('public', mpModel=0)
# SHOULD FAIL
insecure = UsmUserData("securityName")
# SHOULD FAIL
auth_no_priv = UsmUserData("securityName","authName")
# SHOULD PASS
less_insecure = UsmUserData("securityName","authName","privName")

---
# False negatives cases:
CommunityData("public")                  # default mpModel=1 (v2c)
CommunityData("public", 1)               # positional mpModel
UsmUserData("securityName", "authName", None)  # authNoPriv

---
# False positive (should pass)
UsmUserData(userName="user", authKey="auth", privKey="priv")  # authPriv
Expected behavior
  • B508 should treat omitted/positional/keyword mpModel consistently.
  • B509 should evaluate privacy presence semantically (privKey / equivalent), not only positional arg count.
Bandit version

1.9.1 (Default)

Python version

3.14 (Default)

Additional context

No response

Dominant language
Python
Stars
8.4k
Forks
893
Avg merge
6h 52m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PyCQA/bandit

All issues in PyCQA/bandit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.