Fix code scanning alert - Add timeout parameter to all requests calls #62
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
GitHub Code Scanning Alert #70 identified multiple HTTP requests calls without timeout parameters. Requests without timeouts can hang indefinitely if the remote server becomes unresponsive, leading to:
Solution
Added
timeout=30parameter to allrequestslibrary calls that were missing it. The 30-second timeout value is:DEFAULT_TIMEOUTconstant insrc/rapid7/constants.pysrc/paloalto/api_pa_xdr.py)Changes
Fixed 9 requests calls across 4 files:
1.
OLD/add_smtp_alerts.py(3 calls)requests.get()for retrieving SMTP alertsrequests.put()for updating SMTP alertsrequests.post()for creating SMTP alerts2.
src/rapid7/api/insightvm-api-examples-master/v3/python/run-scan/run-scan.py(2 calls)requests.post()for initiating scansrequests.get()for checking scan status3.
src/rapid7/api/insightvm-api-examples-master/v3/python/add-asset-groups/add-asset-groups.py(1 call)requests.post()for creating asset groups4.
src/rapid7/api/insightvm-api-examples-master/v3/python/IVM_functions.py(3 calls)requests.request("GET")inget_stuff()methodrequests.request("POST")inpost_stuff()methodrequests.request("PUT")input_stuff()methodImpact
✅ Security: Prevents indefinite hanging on network failures
✅ Reliability: Improves application resilience and error handling
✅ Compatibility: Zero breaking changes - purely additive modification
✅ Consistency: Aligns with existing timeout patterns in the codebase
Testing
Resolves #70
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.