fix(presets): re-validate catalog URL after redirects (HTTPS parity/security)#3523
Open
jawwad-ali wants to merge 1 commit into
Open
fix(presets): re-validate catalog URL after redirects (HTTPS parity/security)#3523jawwad-ali wants to merge 1 commit into
jawwad-ali wants to merge 1 commit into
Conversation
PresetCatalog._fetch_single_catalog opened the catalog URL and trusted the payload without re-validating response.geturl() after redirects. _open_url follows redirects (stripping auth only on an HTTPS->HTTP downgrade), so an https:// catalog entry that 30x-redirects to http://attacker/... was still fetched and trusted. The catalog payload supplies each preset's download_url + sha256, so a redirected payload can drive install of an arbitrary archive that passes verify_archive_sha256. Add the post-redirect geturl() re-validation via _validate_catalog_url, mirroring integrations/catalog.py, workflows/catalog.py, and bundler adapters — and presets/_commands.py, which already does this on its --from download path. This is the lone preset catalog-fetch site missing the guard. Test: an HTTPS URL whose response.geturl() reports http:// is rejected (PresetValidationError). Completed four existing fetch-test mocks that predated this behavior to report geturl() like a real urllib response. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds post-redirect URL validation for preset catalog fetching.
Changes:
- Validates the final catalog URL before reading its payload.
- Adds redirect regression coverage and updates response mocks.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/presets/__init__.py |
Adds final URL validation. |
tests/test_presets.py |
Tests insecure redirects and updates mocks. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Medium
Comment on lines
+2197
to
+2199
| final_url = response.geturl() | ||
| if final_url != entry.url: | ||
| self._validate_catalog_url(final_url) |
Comment on lines
+2198
to
+2199
| if final_url != entry.url: | ||
| self._validate_catalog_url(final_url) |
mnriem
requested changes
Jul 15, 2026
mnriem
left a comment
Collaborator
There was a problem hiding this comment.
Please address Copilot feedback
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.
What
PresetCatalog._fetch_single_catalogfetched the catalog JSON and trusted it without re-validating the post-redirect URL:_open_urlfollows redirects (stripping auth only on an HTTPS→HTTP downgrade), so anhttps://catalogentry.urlthat 30x-redirects tohttp://attacker/catalog.jsonis still fetched and trusted. Because the catalog payload supplies each preset'sdownload_urlandsha256, an attacker-controlled redirected payload defeatsverify_archive_sha256and can drive installation of an arbitrary archive.Fix
Re-validate
response.geturl()after the redirect via the existing_validate_catalog_url, exactly mirroring the other catalog systems:integrations/catalog.py(final_url = resp.geturl(); if final_url != entry.url: self._validate_catalog_url(final_url))workflows/catalog.py,bundler/services/adapters.pypresets/_commands.pyitself, which already does redirect re-validation on its--fromdownload path.This was the one preset catalog-fetch site missing the guard — clearly an oversight, not a deliberate omission.
Test
test_fetch_single_catalog_revalidates_redirected_url: an HTTPS URL whoseresponse.geturl()reportshttp://is rejected withPresetValidationError(fails before: no revalidation). Four pre-existing fetch-test mocks were completed to reportgeturl()like a realurllibresponse.🤖 Written with the assistance of Claude Code (AI). Bug self-found; fix/tests verified locally (fail-before / pass-after).