PyCQA / PyCQA/bandit

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

Open
#1,394 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
8.3k
Forks
836
Avg merge
5d 3h
Merged PRs (30d)
1

Description

Describe the bug

B501 currently detects verify=False for module-level calls like requests.get(...) and httpx.get(...), but misses equivalent insecure calls on client/session instances (for example session.get(..., verify=False)).
This creates false negatives for common usage patterns and leaves CWE-295 cases undetected.

Reproduction steps
import httpx
import requests
session = requests.Session()
session.get("https://gmail.com", timeout=30, verify=False)
session.post("https://gmail.com", timeout=30, verify=False)
with requests.Session() as scoped_session:
    scoped_session.put("https://gmail.com", timeout=30, verify=False)
    scoped_session.delete("https://gmail.com", timeout=30, verify=False)
client = httpx.Client(timeout=30)
client.get("https://gmail.com", timeout=30, verify=False)
client.post("https://gmail.com", timeout=30, verify=False)
Run:
bandit -q -r <repro_file.py> -t B501 -f json
Actual result: no B501 findings for the above calls.
Expected behavior

Six alarms should be generated.

Bandit version

1.9.1 (Default)

Python version

3.14 (Default)

Additional context

No response

Contributor guide

Open the contributing guide

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.

Research direction

Start by reproducing the B501 case with the provided requests.Session and httpx.Client examples, then trace the B501 check that handles module-level calls. Confirm the change by running the shown bandit command and verify that six B501 alarms are reported for the instance-method calls.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.