fix: bound response reads in preset catalog and download - #3778
Open
Quratulain-bilal wants to merge 4 commits into
Open
fix: bound response reads in preset catalog and download#3778Quratulain-bilal wants to merge 4 commits into
Quratulain-bilal wants to merge 4 commits into
Conversation
Replace unbounded response.read() calls with read_response_limited() in presets/__init__.py to prevent DoS via oversized catalog or preset archive responses. Three call sites fixed: - _fetch_single_catalog JSON read (catalog metadata) - _fetch_catalog JSON read (legacy path) - download_preset ZIP read (binary download)
Contributor
There was a problem hiding this comment.
Pull request overview
Bounds preset catalog and archive response reads to mitigate oversized-response DoS risks.
Changes:
- Caps catalog JSON responses at 1 MiB.
- Caps preset ZIP downloads at 50 MiB.
- Reuses the shared bounded-response helper.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/presets/__init__.py |
Adds bounded reads for catalogs and preset archives. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
src/specify_cli/presets/init.py:4641
- The download tests also use non-consuming
read.return_valueresponses (tests/test_presets.py:2363-2364and2473-2474). With the bounded reader, each call replays the ZIP until the 50 MiB limit is hit, so matching-hash, no-hash, and direct-asset tests no longer reach their assertions. Convert these fixtures to consuming streams and add an oversized archive regression test that expectsPresetError.
zip_data = read_response_limited(response, max_bytes=MAX_DOWNLOAD_BYTES)
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Medium
Contributor
There was a problem hiding this comment.
Review details
Comments suppressed due to low confidence (1)
src/specify_cli/presets/init.py:27
- This duplicates
read_response_limitedfrom the existing import block below and introducesMAX_DOWNLOAD_BYTESandMAX_JSON_METADATA_BYTES, neither of which is used in this module. The resulting redefinition/unused imports will fail static lint checks; remove this line and keep the existing_download_securityimport block.
from .._download_security import MAX_DOWNLOAD_BYTES, MAX_JSON_METADATA_BYTES, read_response_limited
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Medium
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
Replace unbounded
esponse.read()\ calls with
ead_response_limited()\ in \presets/init.py\ to prevent DoS via oversized catalog or preset archive responses.
Changes
Three call sites fixed:
Added \rom .._download_security import MAX_DOWNLOAD_BYTES, MAX_JSON_METADATA_BYTES, read_response_limited.