fix(python-sdk): add robust input validation and timeout bounding to REST requests - #43
Open
mozluk wants to merge 1 commit into
Open
fix(python-sdk): add robust input validation and timeout bounding to REST requests#43mozluk wants to merge 1 commit into
mozluk wants to merge 1 commit into
Conversation
…REST requests ## Motivation This PR hardens the `python-sdk` repository by introducing comprehensive input validation bounds and explicit network request timeouts, as identified during the Pacific-Fi security audit[cite: 29]. Previously, decimal amounts, addresses, and leverage parameters lacked strict format and range checks, and outgoing REST requests lacked execution timeouts[cite: 29]. ## Modifications * **Shared Input Validation (`common/validate.py`, `tests/test_validate.py`)**: * Implemented strict decimal string parsing and exact base-unit conversion (`to_base_units`) to prevent floating-point precision loss and silent token rounding[cite: 29]. * Added validation guards for leverage ranges (1–50x) and base58 Solana address lengths[cite: 29]. * Added and executed a comprehensive unit test suite covering validation logic[cite: 29]. * **Outbound Request Bounding (`rest/*`)**: * Enforced explicit execution timeouts on all `requests.get` and `requests.post` calls to prevent hanging connections[cite: 29]. * Migrated query string arguments to safe parameter passing (`params=`)[cite: 29]. ## Checklist - [x] Format your code according to the Contributor Guide. - [x] Add unit tests as outlined in the Contributor Guide. - [x] Update documentation as needed, including docstrings or example tutorials. ```[cite: 29]
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.
Motivation
This PR hardens the
python-sdkrepository by introducing comprehensive input validation bounds and explicit network request timeouts, as identified during the Pacific-Fi security audit[cite: 29]. Previously, decimal amounts, addresses, and leverage parameters lacked strict format and range checks, and outgoing REST requests lacked execution timeouts[cite: 29].Modifications
common/validate.py,tests/test_validate.py):to_base_units) to prevent floating-point precision loss and silent token rounding[cite: 29].rest/*):requests.getandrequests.postcalls to prevent hanging connections[cite: 29].params=)[cite: 29].Checklist