Skip to content

Detect requests.request() calls without a timeout in B113 - #1463

Open
arpitjain099 wants to merge 1 commit into
PyCQA:mainfrom
arpitjain099:chore/b113-requests-request
Open

Detect requests.request() calls without a timeout in B113#1463
arpitjain099 wants to merge 1 commit into
PyCQA:mainfrom
arpitjain099:chore/b113-requests-request

Conversation

@arpitjain099

Copy link
Copy Markdown

I work on supply-chain security tooling and was reading the B113 plugin.

B113 flags requests calls that are missing a timeout, but it only looks at the named verb helpers (get, post, put, and so on). It never checks requests.request(method, url, ...), which is the generic entry point those helpers all wrap and which also has no default timeout. So both of these are missed today:

requests.request('GET', url)                 # missing timeout
requests.request('GET', url, timeout=None)   # timeout disabled

The httpx side of the same plugin already includes "request" in its set, so httpx.request(..., timeout=None) is caught while the requests equivalent is not. This lines the two up.

The change is small: add a REQUESTS_ATTRS set (the verbs plus "request") and use it for the two requests branches. httpx behavior is unchanged. I extended examples/requests-missing-timeout.py with the two new error cases plus a timeout=5 okay case, and bumped the expected counts in the functional test (25 to 27). The functional suite passes locally.

B113 flags requests calls that lack a timeout, but it only matched the
named verb helpers (get, post, put, and so on). It never checked
requests.request(method, url, ...), the generic entry point those helpers
wrap, which also has no default timeout. Both requests.request('GET', url)
and requests.request('GET', url, timeout=None) were missed.

The httpx branch of the same plugin already keeps "request" in its set, so
httpx.request(..., timeout=None) was caught while the requests equivalent
was not. This adds a REQUESTS_ATTRS set (the verbs plus "request") and uses
it for the two requests branches; httpx behavior is unchanged.

Extends examples/requests-missing-timeout.py with the two new error cases
and a timeout=5 okay case, and bumps the functional test counts from 25 to
27.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.

1 participant