security(polymarket-browse): add MAX_RESPONSE_SIZE limit to prevent memory exhaustion #35
Reference in New Issue
Block a user
Delete Branch "security/8-response-size-limits"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add response size limit to prevent memory exhaustion from malicious or gigantic API responses.
Changes
MAX_RESPONSE_SIZE = 10 * 1024 * 1024(10MB) constantjson.loads()infetch_page()ValueErrorif response exceeds limitSecurity Impact
Prevents memory exhaustion attack where a compromised/malicious Polymarket API returns gigabytes of data.
Testing
70/70 tests passing
Review requested
what is the current response size? also is this response size limit just for a single endpoint or for every endpoints?
first, for global-search endpoint, I think maybe to make it safe something like 10 times of the current response size. use max(10 times of current response size, 10mb).
second I dont think we could uniform the limit. because global-search supposed to be large. while something like detail maybe could be smaller. so I think having 10mb as global, but then we can override it across the endpoint should be an option. what do you think about this approach?
Great questions! Let me clarify:
Current Implementation (PR #35)
MAX_RESPONSE_SIZE = 10 * 1024 * 1024)public-search(global-search) endpoint infetch_page()fetch_page()which handles public-searchYour Proposed Approach
I like your thinking! A few observations:
10x current response size: Good idea - we should size the limit based on actual expected response sizes. For global-search with PAGE_SIZE=50, a typical response is probably < 1MB.
Endpoint-specific limits: Makes sense. Different endpoints have different payload sizes:
public-search(global): Larger, multi-event responsesConfigurable override: Yes, this gives flexibility.
Proposed Changes
And make these constants configurable via environment variables or CLI args if needed.
Questions for You
What do you think?
Updated the implementation based on your feedback:
Changes Made
Dynamic Response Size Limit instead of fixed 10MB:
Rationale
Note
For now, this only applies to
fetch_page()(public-search endpoint). If we add other endpoints (event detail, etc.), each can callget_max_response_size()with appropriate page_size.Tests: 70/70 passing
Does this approach work for you?
lgtm
Pull request closed