Skip to content

fix(github-http): return None on malformed GHES port instead of raising#3379

Merged
mnriem merged 1 commit into
github:mainfrom
jawwad-ali:fix/github-http-malformed-port
Jul 7, 2026
Merged

fix(github-http): return None on malformed GHES port instead of raising#3379
mnriem merged 1 commit into
github:mainfrom
jawwad-ali:fix/github-http-malformed-port

Conversation

@jawwad-ali

Copy link
Copy Markdown
Contributor

Description

resolve_github_release_asset_api_url is contracted to either resolve a browser release-download URL to its REST API asset URL or return None — every unresolvable case (unknown host, not-an-asset path, network error, missing asset) returns None. But the GHES branch builds the authority via parsed.port:

elif is_ghes:
    authority = hostname if parsed.port is None else f"{hostname}:{parsed.port}"

urllib's .port raises ValueError on a malformed port. So an allowlisted GHES host with a bad port (e.g. https://ghes.example:notaport/...) crashes the caller instead of returning None. Reproduced on main @ 92b7cf7: ValueError: Port could not be cast to integer value as 'notaport'.

Fix

Read parsed.port inside a try/except ValueError: return None, matching the function's existing graceful return None behavior.

Testing

New test_returns_none_on_malformed_ghes_port: an allowlisted GHES host with :notaport returns None and induces no network call. Fails before (ValueError — verified by source-stash), passes after. The existing valid-port GHES test still passes (happy path unchanged). Full test_github_http.py: 27 passed. uvx ruff check clean.

AI Disclosure

  • I did use AI assistance (describe below)

Found and fixed with Claude Code (Claude Fable 5) under my direction. AI spotted the unguarded parsed.port against the function's return-None contract; I reproduced the ValueError, verified fail-before/pass-after, and reviewed the diff.

resolve_github_release_asset_api_url's is_ghes branch built the authority
with 'parsed.port', which raises ValueError on a malformed port (e.g.
host:notaport). The function's contract is to resolve or return None,
never raise — every other unresolvable case returns None. An allowlisted
GHES host with a bad port therefore crashed the caller. Read parsed.port
defensively and return None on ValueError.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a contract violation in resolve_github_release_asset_api_url where malformed GHES ports (e.g. :notaport) could raise a ValueError instead of returning None, aligning behavior with the function’s documented “resolve or return None” semantics.

Changes:

  • Guard GHES authority construction by reading parsed.port inside a try/except ValueError and returning None on malformed ports.
  • Add a regression test ensuring malformed GHES ports return None and do not trigger any network call.
Show a summary per file
File Description
src/specify_cli/_github_http.py Handles malformed GHES ports by catching ValueError from parsed.port and returning None per function contract.
tests/test_github_http.py Adds a regression test for malformed GHES port handling and verifies open_url_fn is not invoked.

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: Low

@mnriem mnriem merged commit a307894 into github:main Jul 7, 2026
12 checks passed
@mnriem

mnriem commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

kanfil added a commit to tikalk/agentic-sdlc-spec-kit that referenced this pull request Jul 8, 2026
Upstream commits merged (9):

- 0151d23 agy honors SPECKIT_INTEGRATION_AGY_EXTRA_ARGS (github#3347)

- fb796c2 shell step validate() rejects non-string run (github#3348)

- 220e6fc fan-in validate() rejects non-mapping output (github#3349)

- 12faf7b workflow run/resume errors to stderr under --json (github#3352)

- d5ba062 bundle update uninstalls dropped components (github#3353)

- f1a8d8f release 0.12.7, begin 0.12.8.dev0 (github#3398)

- 10d4bca guard _sha256 against unreadable managed files (github#3376)

- a307894 return None on malformed GHES port (github#3379)

- 882e1e9 exit cleanly on malformed IPv6 URLs in add commands (github#3369)

Conflict: presets/_commands.py — combined IPv6 try/except + _esc()

with fork accent() theming.

Assisted-by: OpenCode (model: glm-5.2, autonomous)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants