Skip to content

Fix B501 false negative: detect verify=False on Session/Client instances#1407

Open
kimjune01 wants to merge 1 commit intoPyCQA:mainfrom
kimjune01:fix-b501-session-verify-false
Open

Fix B501 false negative: detect verify=False on Session/Client instances#1407
kimjune01 wants to merge 1 commit intoPyCQA:mainfrom
kimjune01:fix-b501-session-verify-false

Conversation

@kimjune01
Copy link
Copy Markdown

Summary

B501 only checked module-level calls like requests.get(verify=False). Instance method calls like session.get(verify=False) on requests.Session, httpx.Client, and httpx.AsyncClient were not flagged.

The qualname matching now handles three patterns:

  1. Module-level: requests.get(verify=False) — HIGH/HIGH (unchanged)
  2. Chained constructor: requests.Session().get(verify=False) — HIGH/HIGH (new)
  3. Variable instance: session.get(verify=False) — HIGH/MEDIUM (new, lower confidence since we can't statically confirm the type)

Test plan

  • Example file examples/requests-session-verify-disabled.py covers all patterns
  • Verified manually: 8 issues detected across session/client patterns, 0 false positives on verify=True

Fixes #1394

Resolves PyCQA#1394

B501 previously only detected verify=False on module-level calls like
requests.get() and httpx.get(), missing equivalent insecure calls on
Session/Client instances.

Changes:
- Detect session.get(..., verify=False) where session is any variable
- Detect requests.Session().get(..., verify=False) chained calls
- Detect httpx.Client().get(..., verify=False) chained calls
- Use HIGH confidence for module-level calls
- Use MEDIUM confidence for instance methods (can't statically verify type)

Adds examples/requests-session-verify-disabled.py demonstrating the
newly detected patterns.

All functional tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False negative: B501 misses verify=False on requests.Session / httpx.Client instance methods

1 participant