harden: bound remaining catalog reads + lock in no-unbounded-read invariant
Part of splitting #2442 into smaller, dedicated PRs. Re-derived against current main. Final PR of the runtime-hardening stack.
Stacked on #3141 (which is itself stacked on #3140). Its diff includes those commits — review/merge #3140 → #3141 → this, in order.
What
- Bound the remaining catalog JSON reads via
read_response_limited(max_bytes=MAX_JSON_CATALOG_BYTES)and passstrict_redirects=True:workflows/catalog.py,integrations/catalog.py,bundler/services/adapters.py,commands/bundle/__init__.py.
__init__.pyworkflow_add/workflow_step_add: bounded reads +strict_redirects=True+ sharedis_https_or_localhost_httpURL validation.extensions/_commands.py: bound theextension add --from <url>ZIP download — the last unbounded network read (surfaced by the gate below).
The invariant
Adds tests/test_download_security.py::test_remote_downloads_do_not_use_unbounded_response_reads: an AST scan over the whole src/specify_cli tree that fails CI if any response.read() is unbounded, with a 3-entry allowlist for the local-file get_hash reads (extensions/presets/integrations). This only goes green once #3140 + #3141 + this have converted every remote read — it's the lock that keeps the bound from silently regressing.
Validation
test_download_security(incl. the AST gate),test_workflows,test_integration_catalog,test_bundler_adapters,test_upgrade,test_extensions— 792 passed.- Bundle integration tests — 10 passed.
ruff checkclean. - Existing catalog/workflow tests pass with stream mocks made cursor-based (so they exercise the bounded reads) and
strict_redirectsthreaded through the fake openers.
This completes the runtime hardening. The Bandit + detect-secrets CI gates land in a separate PR on the #2/#3 track.
Converted to a draft as it is waiting for #3141