From ad76636313e0a3650ce04bb824c9cac9b1578a47 Mon Sep 17 00:00:00 2001 From: veerababu1729 <20A91A0546@aec.edu.in> Date: Thu, 23 Oct 2025 22:26:02 +0530 Subject: [PATCH] Fix timeout inconsistency in network requests Add explicit timeout parameter to urllib.request.urlopen() calls to ensure consistent timeout behavior and prevent hanging in poor network conditions. --- lib/core/common.py | 6 +++--- lib/request/connect.py | 2 +- lib/utils/api.py | 2 +- lib/utils/search.py | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 3bb5023f0..5d1fe404b 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -3919,7 +3919,7 @@ def getLatestRevision(): req = _urllib.request.Request(url="https://raw.githubusercontent.com/sqlmapproject/sqlmap/master/lib/core/settings.py", headers={HTTP_HEADER.USER_AGENT: fetchRandomAgent()}) try: - content = getUnicode(_urllib.request.urlopen(req).read()) + content = getUnicode(_urllib.request.urlopen(req, timeout=conf.timeout).read()) retVal = extractRegexResult(r"VERSION\s*=\s*[\"'](?P[\d.]+)", content) except: pass @@ -3987,7 +3987,7 @@ def createGithubIssue(errMsg, excMsg): req = _urllib.request.Request(url="https://api.github.com/search/issues?q=%s" % _urllib.parse.quote("repo:sqlmapproject/sqlmap Unhandled exception (#%s)" % key), headers={HTTP_HEADER.USER_AGENT: fetchRandomAgent()}) try: - content = _urllib.request.urlopen(req).read() + content = _urllib.request.urlopen(req, timeout=conf.timeout).read() _ = json.loads(content) duplicate = _["total_count"] > 0 closed = duplicate and _["items"][0]["state"] == "closed" @@ -4006,7 +4006,7 @@ def createGithubIssue(errMsg, excMsg): req = _urllib.request.Request(url="https://api.github.com/repos/sqlmapproject/sqlmap/issues", data=getBytes(json.dumps(data)), headers={HTTP_HEADER.AUTHORIZATION: "token %s" % token, HTTP_HEADER.USER_AGENT: fetchRandomAgent()}) try: - content = getText(_urllib.request.urlopen(req).read()) + content = getText(_urllib.request.urlopen(req, timeout=conf.timeout).read()) except Exception as ex: content = None _excMsg = getSafeExString(ex) diff --git a/lib/request/connect.py b/lib/request/connect.py index 7db7bea77..d2be23653 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -661,7 +661,7 @@ class Connect(object): logger.log(CUSTOM_LOGGING.TRAFFIC_OUT, requestMsg) - conn = _urllib.request.urlopen(req) + conn = _urllib.request.urlopen(req, timeout=conf.timeout) if not kb.authHeader and getRequestHeader(req, HTTP_HEADER.AUTHORIZATION) and (conf.authType or "").lower() == AUTH_TYPE.BASIC.lower(): kb.authHeader = getUnicode(getRequestHeader(req, HTTP_HEADER.AUTHORIZATION)) diff --git a/lib/utils/api.py b/lib/utils/api.py index eb9c07b46..323f2803b 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -750,7 +750,7 @@ def _client(url, options=None): headers["Authorization"] = "Basic %s" % encodeBase64("%s:%s" % (DataStore.username or "", DataStore.password or ""), binary=False) req = _urllib.request.Request(url, data, headers) - response = _urllib.request.urlopen(req) + response = _urllib.request.urlopen(req, timeout=conf.timeout) text = getText(response.read()) except: if options: diff --git a/lib/utils/search.py b/lib/utils/search.py index ec19114f6..cdf2863f5 100644 --- a/lib/utils/search.py +++ b/lib/utils/search.py @@ -57,7 +57,7 @@ def _search(dork): try: req = _urllib.request.Request("https://www.google.com/ncr", headers=requestHeaders) - conn = _urllib.request.urlopen(req) + conn = _urllib.request.urlopen(req, timeout=conf.timeout) except Exception as ex: errMsg = "unable to connect to Google ('%s')" % getSafeExString(ex) raise SqlmapConnectionException(errMsg) @@ -72,7 +72,7 @@ def _search(dork): try: req = _urllib.request.Request(url, headers=requestHeaders) - conn = _urllib.request.urlopen(req) + conn = _urllib.request.urlopen(req, timeout=conf.timeout) requestMsg = "HTTP request:\nGET %s" % url requestMsg += " %s" % _http_client.HTTPConnection._http_vsn_str @@ -138,7 +138,7 @@ def _search(dork): try: req = _urllib.request.Request(url, data=getBytes(data), headers=requestHeaders) - conn = _urllib.request.urlopen(req) + conn = _urllib.request.urlopen(req, timeout=conf.timeout) requestMsg = "HTTP request:\nGET %s" % url requestMsg += " %s" % _http_client.HTTPConnection._http_vsn_str