An HTTP request with requests has no timeout

tx0/python:request-without-timeoutrecommendedwarningbug, cwe-400

What it finds

requests.get(url): requests waits for an answer without a time limit unless it is given one, so a server that stops answering stalls the program, a thread or a worker for good (CWE-400). timeout= sets how long to wait.

Calls that pass **kwargs, which may hold a timeout, are left alone, and so is an explicit timeout=None, which says the wait is meant.

From the rule's source, request_without_timeout.rs.

Example from the rule's tests
import requests  def fetch(url, options):    a = requests.get(url)tx0 reports: requests.get waits for the server without a time limit    b = requests.post(url, data={})tx0 reports: requests.post waits    c = requests.get(url, timeout=10)    d = requests.get(url, **options)    e = requests.get(url, timeout=None)    return a, b, c, d, e
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:request-without-timeout" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:request-without-timeout] reason="..."

tx0 explain tx0/python:request-without-timeout shows the same in the terminal. Found a false positive? Report it.