Skip to content

Commit 0e7219b

Browse files
committed
Security Fix: Add timeout parameters to HTTP requests
This fix addresses a critical security vulnerability where HTTP requests could hang indefinitely, potentially causing denial of service. Changes: - Added 10-second timeout to version check API call - Added 10-second timeout to GitHub pull request API call - Added 30-second timeout to data file downloads (larger timeout for data) - Added 10-second timeout to exclusions list download Impact: - Prevents infinite hangs that could freeze the application - Improves user experience with predictable response times - Fixes security issue flagged by Bandit static analysis (B113) - Makes the application more robust in poor network conditions The timeouts are conservative enough to work with slow connections while preventing indefinite blocking that could be exploited.
1 parent 1d2c4b1 commit 0e7219b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

sherlock_project/sherlock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ def main():
742742

743743
# Check for newer version of Sherlock. If it exists, let the user know about it
744744
try:
745-
latest_release_raw = requests.get(forge_api_latest_release).text
745+
latest_release_raw = requests.get(forge_api_latest_release, timeout=10).text
746746
latest_release_json = json_loads(latest_release_raw)
747747
latest_remote_tag = latest_release_json["tag_name"]
748748

@@ -802,7 +802,7 @@ def main():
802802
if args.json_file.isnumeric():
803803
pull_number = args.json_file
804804
pull_url = f"https://api.github.com/repos/sherlock-project/sherlock/pulls/{pull_number}"
805-
pull_request_raw = requests.get(pull_url).text
805+
pull_request_raw = requests.get(pull_url, timeout=10).text
806806
pull_request_json = json_loads(pull_request_raw)
807807

808808
# Check if it's a valid pull request

sherlock_project/sites.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def __init__(
129129
if data_file_path.lower().startswith("http"):
130130
# Reference is to a URL.
131131
try:
132-
response = requests.get(url=data_file_path)
132+
response = requests.get(url=data_file_path, timeout=30)
133133
except Exception as error:
134134
raise FileNotFoundError(
135135
f"Problem while attempting to access data file URL '{data_file_path}': {error}"
@@ -166,7 +166,7 @@ def __init__(
166166

167167
if honor_exclusions:
168168
try:
169-
response = requests.get(url=EXCLUSIONS_URL)
169+
response = requests.get(url=EXCLUSIONS_URL, timeout=10)
170170
if response.status_code == 200:
171171
exclusions = response.text.splitlines()
172172
exclusions = [exclusion.strip() for exclusion in exclusions]

0 commit comments

Comments
 (0)