Skip to content

Commit 518f46c

Browse files
committed
add explicit timeouts to MobSF requests
- Added \ imeout=30\ to \MobSFAdapter\ API calls to prevent hanging requests. - Addressed SonarQube/linter warnings regarding missing timeouts in \ equests\ calls.
1 parent a972caf commit 518f46c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

secuscan/scanners/android/mobsf_adapter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def upload_file(self, file_path: str) -> str:
4747
with open(file_path, 'rb') as f:
4848
# Explicitly define filename and content type
4949
files = {'file': (os.path.basename(file_path), f, 'application/octet-stream')}
50-
response = requests.post(upload_url, headers=self._get_headers(), files=files)
50+
response = requests.post(upload_url, headers=self._get_headers(), files=files, timeout=60)
5151

5252
if response.status_code != 200:
5353
logger.error(f"MobSF Upload Failed: {response.text}")
@@ -79,7 +79,7 @@ def scan_file(self, file_hash: str) -> dict:
7979

8080
try:
8181
logger.info(f"Initiating scan for hash {file_hash}...")
82-
response = requests.post(scan_url, headers=self._get_headers(), data=data)
82+
response = requests.post(scan_url, headers=self._get_headers(), data=data, timeout=120)
8383
response.raise_for_status()
8484
logger.info("Scan completed successfully.")
8585
return response.json()
@@ -100,7 +100,7 @@ def get_report(self, file_hash: str) -> dict:
100100

101101
try:
102102
logger.info(f"Fetching report for hash {file_hash}...")
103-
response = requests.post(report_url, headers=self._get_headers(), data=data)
103+
response = requests.post(report_url, headers=self._get_headers(), data=data, timeout=30)
104104
response.raise_for_status()
105105
return response.json()
106106

@@ -119,7 +119,7 @@ def delete_scan(self, file_hash: str):
119119
data = {'hash': file_hash}
120120

121121
try:
122-
requests.post(delete_url, headers=self._get_headers(), data=data)
122+
requests.post(delete_url, headers=self._get_headers(), data=data, timeout=30)
123123
logger.info(f"Deleted scan data for {file_hash}.")
124124
except Exception as e:
125125
logger.warning(f"Failed to delete scan data: {e}")

0 commit comments

Comments
 (0)