Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper detection of non-requests module #1011

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions bandit/plugins/request_without_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@
@test.test_id("B113")
def request_without_timeout(context):
http_verbs = ("get", "options", "head", "post", "put", "patch", "delete")
if (
"requests" in context.call_function_name_qual
and context.call_function_name in http_verbs
):
qualname = context.call_function_name_qual.split(".")[0]

if qualname == "requests" and context.call_function_name in http_verbs:
# check for missing timeout
if context.check_call_arg_value("timeout") is None:
return bandit.Issue(
Expand Down
4 changes: 4 additions & 0 deletions examples/requests-missing-timeout.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
import not_requests

requests.get('https://gmail.com')
requests.get('https://gmail.com', timeout=None)
Expand All @@ -21,3 +22,6 @@
requests.head('https://gmail.com')
requests.head('https://gmail.com', timeout=None)
requests.head('https://gmail.com', timeout=5)

# Okay
not_requests.get('https://gmail.com')