Skip to content

fix: port-safe GHEC detection in deriveAPIFromServerURL#2484

Merged
lpcox merged 2 commits intofix/ghec-tenant-supportfrom
copilot/sub-pr-2481
Mar 24, 2026
Merged

fix: port-safe GHEC detection in deriveAPIFromServerURL#2484
lpcox merged 2 commits intofix/ghec-tenant-supportfrom
copilot/sub-pr-2481

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 24, 2026

url.Parse stores host+port together in parsed.Host (e.g. mycompany.ghe.com:8443), so strings.HasSuffix(host, ".ghe.com") silently fails when a non-standard port is present, causing GHEC URLs to fall through to GHES /api/v3 derivation.

Changes

  • deriveAPIFromServerURL: switch from parsed.Host to parsed.Hostname() for .ghe.com/github.com checks; re-append port via parsed.Port() when formatting the GHEC copilot-api.* URL
  • Tests: add GHEC tenant with port case (https://mycompany.ghe.com:8443https://copilot-api.mycompany.ghe.com:8443)
// Before — port breaks suffix match, falls through to GHES
host := strings.ToLower(parsed.Host)          // "mycompany.ghe.com:8443"
strings.HasSuffix(host, ".ghe.com")           // false ❌

// After — hostname-only check, port re-added when formatting
hostname := strings.ToLower(parsed.Hostname()) // "mycompany.ghe.com"
strings.HasSuffix(hostname, ".ghe.com")        // true ✅

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

@lpcox lpcox marked this pull request as ready for review March 24, 2026 23:11
Copilot AI review requested due to automatic review settings March 24, 2026 23:11
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 24, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build2845124146/b333/launcher.test /tmp/go-build2845124146/b333/launcher.test -test.testlogfile=/tmp/go-build2845124146/b333/testlog.txt -test.paniconexit0 -test.timeout=10m0s fetc�� 64/src/runtime/cgo rg x_amd64/vet (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build2845124146/b318/config.test /tmp/go-build2845124146/b318/config.test -test.testlogfile=/tmp/go-build2845124146/b318/testlog.txt -test.paniconexit0 -test.timeout=10m0s 64/s�� 64/src/runtime/cgo fix/ghec-tenant-support x_amd64/vet (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build2845124146/b333/launcher.test /tmp/go-build2845124146/b333/launcher.test -test.testlogfile=/tmp/go-build2845124146/b333/testlog.txt -test.paniconexit0 -test.timeout=10m0s fetc�� 64/src/runtime/cgo rg x_amd64/vet (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build2845124146/b333/launcher.test /tmp/go-build2845124146/b333/launcher.test -test.testlogfile=/tmp/go-build2845124146/b333/testlog.txt -test.paniconexit0 -test.timeout=10m0s fetc�� 64/src/runtime/cgo rg x_amd64/vet (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build2845124146/b342/mcp.test /tmp/go-build2845124146/b342/mcp.test -test.testlogfile=/tmp/go-build2845124146/b342/testlog.txt -test.paniconexit0 -test.timeout=10m0s o_.o�� 64/src/net ache/go/1.25.8/x64/src/crypto/internal/fips140/e--64 x_amd64/compile -p internal/itoa -lang=go1.25 x_amd64/compile -o 64/src/net -trimpath x_amd64/vet -p crypto/internal/-e -lang=go1.25 x_amd64/vet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Add GHEC tenant support for proxy and guard URL parsing fix: port-safe GHEC detection in deriveAPIFromServerURL Mar 24, 2026
Copilot AI requested a review from lpcox March 24, 2026 23:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the proxy’s GitHub API URL derivation logic to correctly handle GITHUB_SERVER_URL values that include an explicit port for GHEC tenants (*.ghe.com), and adds a regression test for this case.

Changes:

  • Fix deriveAPIFromServerURL() to perform domain/suffix checks against url.URL.Hostname() (so ports don’t break matching).
  • Preserve the original port when deriving copilot-api.<tenant>.ghe.com URLs.
  • Add a unit test covering a GHEC tenant URL with a port.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/proxy/proxy.go Adjusts URL parsing to use Hostname() for matching and re-adds port for GHEC derivation.
internal/proxy/proxy_test.go Adds a test case validating correct derivation for GHEC tenant URLs with a port.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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