Skip to content

[Bug]: GitHub repository/PR resolution throws uncaught TypeError: Invalid URL when any remote uses an IPv6 SCP URL or SSH alias rejected by new URL #41221

Closed

Description

@gpu004

What I observed

gitHubApiHostForRemote (packages/source-control-github/src/server/gitHubRepositoryResolution.ts:166-175) calls new URL(\https://${remote.host}`).host.toLowerCase()on line 169 without atry/catch`.

Because resolveGitHubRepository (gitHubRepositoryResolution.ts:71-74) maps gitHubApiHostForRemote(remote.url) over every fetch remote from git remote -v, having any secondary remote that uses an IPv6 SCP URL (git@[2001:db8::1]:team/repo.git) or an OpenSSH Host alias whose last dot-separated label fails WHATWG URL's IPv4 check (git@nas.08:team/repo.git, git@08:team/repo.git, git@node.256:team/repo.git) throws an uncaught TypeError: Invalid URL and crashes GitHub repository/PR resolution for the entire repo — even when origin is a normal github.com remote.

parseGitRemoteHost (packages/source-control-core/src/shared/definition.ts:573-596) explicitly wraps its own new URL(\https://${host}`)intry/catchand returns{ remoteUrl, host, hostname }, so these valid SCP remotes reach gitHubApiHostForRemote` directly.

Reproduction

  • Commit: main @ 9d3054a7bb
  • Environment: macOS 27.2.1, Node v26.13.1, git 2.56.1

Run from the repo root (also reproduces identically with git@08:team/repo.git, git@node.256:team/repo.git, or git@[2001:db8::1]:team/repo.git):

node --experimental-strip-types -e '
import { execFileSync } from "node:child_process";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import {
  resolveGitHubRepository,
} from "./packages/source-control-github/src/server/gitHubRepositoryResolution.ts";

const dir = mkdtempSync(join(tmpdir(), "repro-gh-"));
try {
  execFileSync("git", ["init", "-q"], { cwd: dir });
  execFileSync("git", ["remote", "add", "origin", "git@github.com:pingdotgg/t3code.git"], { cwd: dir });
  execFileSync("git", ["remote", "add", "backup", "git@nas.08:team/repo.git"], { cwd: dir });
  const remotes = execFileSync("git", ["remote", "-v"], { cwd: dir, encoding: "utf8" });
  console.log(resolveGitHubRepository({ remotes, resolved: "", hostHint: undefined, defaultHost: "github.com" }));
} finally {
  rmSync(dir, { recursive: true, force: true });
}
'

Expected behavior

gitHubApiHostForRemote returns null for non-GitHub or unparseable remote hosts instead of throwing, and resolveGitHubRepository resolves origin to { host: "github.com", locator: { host: "github.com", owner: "pingdotgg", name: "t3code" } }.

Actual behavior

gitHubApiHostForRemote throws an uncaught TypeError: Invalid URL, aborting resolveGitHubRepository and causing an unhandled Effect defect across all five live call sites in GitHubSourceControlProvider.ts (resolveRepository, checkoutPullRequest, createsChangeRequestsIn, resolveRemoteWebHost, refineUnknownRemote).

Evidence

Stack trace from the command above:

TypeError: Invalid URL
    at gitHubApiHostForRemote (packages/source-control-github/src/server/gitHubRepositoryResolution.ts:169:16)
    at resolveGitHubRepository (packages/source-control-github/src/server/gitHubRepositoryResolution.ts:73:11)

Additional investigation

  • How found: Property-based testing of external-format/source-control parsers, minimized to the plain Node + git snippet above.
  • Verified: Confirmed on origin/main (9d3054a7bb). GitHubSourceControlProvider invokes gitHubApiHostForRemote / resolveGitHubRepository synchronously inside Effect.fn without catching defects at 5 call sites (resolveRepository, checkoutPullRequest, createsChangeRequestsIn, resolveRemoteWebHost, refineUnknownRemote).
  • Duplicate check: Searched open and closed issues/PRs for gitHubApiHostForRemote, resolveGitHubRepository, TypeError: Invalid URL, and parseGitRemoteHost.
  • Impact: Major for affected repos — any secondary backup/deploy/LAN remote with a numeric-suffix SSH alias or IPv6 SCP URL breaks all GitHub PR lookup, creation, listing, and checkout operations in that repo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions