fix(security): harden credential handling, concurrency, validation, and retry mechanisms - #8
Merged
Merged
Conversation
…nd retry backoff - Mask credentials and secrets in __repr__ across client, auth, and token models (CWE-532) - Eliminate race conditions in OAuthTokenManager lock and cache synchronization (CWE-362/662) - Protect HTTP client initialization with mutexes to prevent socket descriptor leaks (CWE-400/775) - Implement jittered exponential backoff and Retry-After header parsing for 429/5xx (CWE-399/799) - Enforce strict operation allowlists and parameter boundary validation (CWE-20/88/1284) - Bound error response memory capture in exception handlers (CWE-400) - Add least-privilege permissions to CI workflow (CWE-250) - Update README Python version badge to show Python 3.9-3.13+ support - Add 15 new security-focused unit tests
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.
Summary of Changes
1. Credential & Secret Protection (CWE-532)
repr=FalsetoOAuthToken.access_tokenand implemented masked__repr__methods acrossOAuthToken,OAuthTokenManager,SigV4Signer,AmazonCreatorsAPI,AsyncAmazonCreatorsAPI,AmazonPAAPI5,AsyncAmazonPAAPI5,AmazonAPI, andAsyncAmazonAPI.credential_secret,secret_key,access_token) in interactive sessions, logging, and error tracebacks.2. Concurrency & Race Condition Elimination (CWE-362 / CWE-662)
asyncio.LockinOAuthTokenManager._cached_tokenreading and updating across synchronous and asynchronous execution paths and cache clearing.3. HTTP Client Lifecycle & Resource Safety (CWE-400 / CWE-775)
.clientproperty initialization with mutex locks to prevent race conditions and duplicate orphaned client allocations.4. Thundering Herd Defense & Retry Hardening (CWE-399 / CWE-799)
calculate_backoff()with full jitter (random.uniform) to prevent synchronized retry storms.parse_retry_after()to extract and respect HTTP 429 and transient 502/503/504Retry-Afterheaders (integer seconds and RFC 7231 HTTP-date).5. Operation Allowlisting & SSRF Protection (CWE-20 / CWE-88)
ALLOWED_CREATORS_ENDPOINTSandALLOWED_PAAPI5_OPERATIONS) in_execute_requestto reject path traversal and header/operation injection attempts.6. Client-Side Input Validation (CWE-20 / CWE-1284)
item_count(1–10),item_page(1–10),min_reviews_rating(1–5),min_saving_percent(1–100), and negative prices before making remote requests.7. Bounded Error Response Memory (CWE-400)
map_http_error()to 4096 characters to prevent memory exhaustion and log bloat from massive error responses.8. CI/CD & Documentation Hardening (CWE-250)
permissions: contents: readto.github/workflows/ci.yml.README.mdto accurately reflect Python 3.9 through 3.13 support.Test & Validation Results