fix: patch path traversal and missing HTTP timeouts - #1
Merged
Conversation
All service modules used str.replace() to interpolate user-supplied IDs into URL path templates without URL encoding. The requests library normalizes ../ sequences during URL preparation, so a crafted ID like '../../admin/settings' could redirect requests to unintended API endpoints with the merchant's API key attached. Added _safe_path_param() in client_base.py using urllib.parse.quote() with safe='' and updated all 40 path parameter interpolations across 17 service files to use it. Co-authored-by: Babacar Diop <princemuichkine@users.noreply.github.com>
The SDK's _request() method called session.request() without any timeout parameter, causing all HTTP calls to block indefinitely if the API server is slow or unresponsive. This could exhaust worker threads in consuming applications and halt payment processing. Added a configurable 'timeout' constructor parameter (default 30s) that is passed to every requests.Session.request() call. Co-authored-by: Babacar Diop <princemuichkine@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Security Fixes
Addresses two vulnerabilities found during an automated security scan.
1. Path traversal via unencoded path parameters
Severity: Medium
All 17 service modules used
str.replace()to interpolate user-supplied IDs into URL path templates without URL encoding. Therequestslibrary normalizes../sequences during URL preparation, so a crafted ID (e.g.../../admin/settings) could redirect authenticated requests to unintended API endpoints — bypassing the SDK's "public routes only" design.Fix: Added a
_safe_path_param()helper inclient_base.pythat appliesurllib.parse.quote(str(value), safe="")and updated all 40 path parameter interpolations across 17 service files to use it.Before:
After:
2. HTTP client denial of service via missing request timeouts
Severity: Medium
The SDK's
_request()method calledsession.request()without anytimeoutparameter. Therequestslibrary defaults toNone(infinite wait), meaning every HTTP call could block indefinitely if the API server is slow or unresponsive — leading to worker thread exhaustion in consuming applications.Fix: Added a configurable
timeoutconstructor parameter (default 30s) toLomiClientthat is passed to everysession.request()call.Testing
test_generated_surface.pyis unrelated — it references apayment_intentsattribute that doesn't exist onLomiClient)_safe_path_param("../../admin")→..%2F..%2FadminLomiClient(api_key="test").timeout→30