fix(github-http): return None on malformed host in resolve_github_release_asset_api_url#3715
Merged
mnriem merged 1 commit intoJul 24, 2026
Conversation
…ease_asset_api_url Accessing the parsed authority (via urlparse/.hostname) raises ValueError on a malformed bracketed host, e.g. https://[not-an-ip]/..., mirroring the existing .port guard below. download_url is server-controlled (a catalog download_url payload), so the function's resolve-or-return-None contract must hold rather than leaking a raw traceback to the caller. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents malformed GitHub release hosts from violating the resolver’s return-None contract.
Changes:
- Catches
ValueErrorduring URL parsing and hostname access. - Adds regression coverage for invalid bracketed IPv6 hosts.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/_github_http.py |
Safely rejects malformed authorities. |
tests/test_github_http.py |
Verifies malformed hosts return None. |
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: 0
- Review effort level: Medium
Collaborator
|
Thank you! |
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
resolve_github_release_asset_api_url()documents a resolve-or-return-Nonecontract ("Returns ...Nonewhen the URL is not a resolvable GitHub release download or the lookup fails"), but reading the parsed authority could raiseValueErrorfor a malformed host and leak a raw traceback past the caller.The function already guards the twin case for
parsed.port(malformed port -> returnNone). This applies the same guard to the host read: on Python 3.14urlparse()itself raisesValueErrorfor an invalid bracketed IPv6 host such ashttps://[not-an-ip]/...; on older versions the raise happens on.hostname. Wrapping bothurlparseand.hostnamein thetrycovers every version.This matters because
download_urlis server-controlled — it comes from a catalogdownload_urlpayload — so a malformed value must not crash resolution.Test plan
test_returns_none_on_malformed_host, mirroring the existingtest_returns_none_on_malformed_ghes_port. It fails without the fix (rawValueError) and passes with it.pytest tests/test_github_http.py-> 30 passed.🤖 Generated with Claude Code