harden: safe ZIP extraction, checksums, and bounded reads for extension/preset downloads
Part of splitting #2442 into smaller, dedicated PRs. Re-derived against current main and adapted to the extensions/ package layout (the original PR predated the module→package refactor #3014).
Stacked on #3140 (bounded HTTP reads). This PR extends the
_download_securitymodule introduced there, so its diff currently includes #3140's commit — review/merge #3140 first.
What
- Extend
src/specify_cli/_download_security.pywithsafe_extract_zip(path-traversal + symlink + per-member/total-size + entry-count bounds),read_zip_member_limited, andverify_sha256. extensions/__init__.py+presets/__init__.py:install_from_zipnow extracts viasafe_extract_zip(zip-slip + symlink + zip-bomb defense) instead of the path-only containment check; catalog fetches and package downloads use bounded reads; downloads are checked against their catalogsha256when present.extensions/_commands.py: the inlineextension.ymlmanifest pre-read (before extraction) usesread_zip_member_limitedso a crafted manifest can't zip-bomb memory.catalogs.py(CatalogStackBase) + the preset catalog validator: reject hostless URLs before the scheme check.
Deliberately omitted
The command-registration path-traversal guard the original #2442 change carried is already on main (landed via #3088, and more thoroughly) — so agents.py/test_registrar_path_traversal.py are not touched here.
Validation
test_download_security.py,test_extensions.py,test_presets.py,integrations/test_integration_catalog.py— 757 passed.ruff checkclean on all changed files.- Existing extension/preset tests pass unchanged except for mock/assertion updates: stream mocks made cursor-based (so they exercise the new bounded reads), and one catalog-URL message assertion updated for the host-before-scheme order.
integrations/test_integration_catalog.pycarries a one-line param fix because it asserts the sharedCatalogStackBasebehavior changed here (the rest of that file's bounded-read work is a later PR).
Catalog bounded-reads for the workflow/integration/bundler readers, and the tree-wide unbounded-read gate, come in the next PR.
Converting to draft as https://github.com/github/spec-kit/pull/3140 has to land first
Rebased this PR onto current main after #3140 and #3671, then force-updated the branch to b52570e (54d5f0c for the rebased feature wiring, b52570e for the independent audit fixes).
The refreshed diff removes the duplicated #3140 history, retains the shared redirect/checksum behavior from main, and adds bounded ZIP32 central-directory preflight, portable path/collision validation, bounded direct/catalog/update reads, safe catalog-derived output filenames, and manifest selection aligned with extraction. The trailing-backslash directory feedback remains covered.
Validation on the published tree: full Python 3.12 suite 5291 passed, 166 skipped; focused Python 3.13 suite 915 passed; Ruff 0.15.0 and git diff --check clean; Bandit found no medium/high issue in changed production files. ZIP64 is intentionally rejected, SHA-256 applies only where catalogs provide hashes, and atomic cache publication/local symlink races remain a separate follow-up.
Posted on behalf of @PascalThuet by OpenAI Codex (model: GPT-5).
Please address Copilot feedback and fix test & lint errors
Thank you!