spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

harden: bound remaining catalog reads + lock in no-unbounded-read invariant

Open PascalThuet opened this issue 5 months ago • 1 comments

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 pass strict_redirects=True:
    • workflows/catalog.py, integrations/catalog.py, bundler/services/adapters.py, commands/bundle/__init__.py.
  • __init__.py workflow_add / workflow_step_add: bounded reads + strict_redirects=True + shared is_https_or_localhost_http URL validation.
  • extensions/_commands.py: bound the extension 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 check clean.
  • Existing catalog/workflow tests pass with stream mocks made cursor-based (so they exercise the bounded reads) and strict_redirects threaded 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.

PascalThuet avatar Jun 24 '26 07:06 PascalThuet

Converted to a draft as it is waiting for #3141

mnriem avatar Jun 24 '26 18:06 mnriem