The best way to control Claude Code, Codex and more from any computer or phone
fix(github): read github.com-<name> SSH aliases through github.com (#22246)
Co-authored-by: matthias schedel <matze.schedel@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: maria-rcks <maria@kuuro.net>
matthias-scale committed
Oct 30, 2026 at 21:39 UTC
b5a5ab4ea5cab1d27cfa3d7351ae56e4734b235c
4 files changed
+322
-10
packages/source-control-github/src/server/GitHubSourceControlProvider.test.ts
+96
@@ -288,6 +288,102 @@ describe("GitHubSourceControlProvider repository resolution", () => {
288
assert.deepStrictEqual(paths, ["github.com repos/acme/web"]);
289
}).pipe(Effect.provide(layer));
290
});
291
+
292
+ it.effect.each([
293
+ ["github", "git@github:acme/web.git"],
294
+ ["github.com-scale", "git@github.com-scale:acme/web.git"],
295
+ ["github.com-scale", "ssh://git@github.com-scale:22/acme/web.git"],
296
+ ] as const)("reads an SSH alias on %s through github.com (%s)", ([host, remoteUrl]) => {
297
+ const hosts: string[] = [];
298
+ const { layer } = harness({
299
+ remotes: remotesOutput(["origin", remoteUrl]),
300
+ api: {
301
+ rest: (input) =>
302
+ Effect.sync(() => {
303
+ hosts.push(`${input.host} ${input.path}`);
304
+ return restResponse({
305
+ full_name: "acme/web",
306
+ html_url: "https://github.com/acme/web",
307
+ ssh_url: "git@github.com:acme/web.git",
308
+ default_branch: "main",
309
+ });
310
+ }),
311
+ },
312
+ });
313
+ return Effect.gen(function* () {
314
+ const gh = yield* GitHubSourceControlProvider.make;
315
+ const resolveWebHost = gh.resolveRemoteWebHost;
316
+ assert.ok(resolveWebHost);
317
+ assert.strictEqual(
318
+ yield* resolveWebHost({
319
+ cwd: "/repo",
320
+ context: { ...githubContext(host), remoteUrl },
321
+ resolveContext: () => Effect.succeed(null),
322
+ }),
323
+ "github.com",
324
+ );
325
+ yield* gh.getDefaultBranch({ cwd: "/repo" });
326
+ yield* gh.getDefaultBranch({
327
+ cwd: "/repo",
328
+ context: { ...githubContext(host), remoteUrl },
329
+ });
330
+ assert.deepStrictEqual(hosts, ["github.com repos/acme/web", "github.com repos/acme/web"]);
331
+ }).pipe(Effect.provide(layer));
332
+ });
333
+
334
+ it.effect.each(["sole", "upstream", "missing"])(
335
+ "preserves an HTTPS context host with %s remotes",
336
+ (mode) => {
337
+ const paths: string[] = [];
338
+ const remoteUrl = "https://github.com-scale/me/web.git";
339
+ const { layer } = harness({
340
+ remotes:
341
+ mode === "missing"
342
+ ? ""
343
+ : remotesOutput(
344
+ ["origin", remoteUrl],
345
+ ...(mode === "upstream"
346
+ ? ([["upstream", "https://github.com/acme/web.git"]] as const)
347
+ : []),
348
+ ),
349
+ api: {
350
+ rest: (input) =>
351
+ Effect.sync(() => {
352
+ paths.push(`${input.host} ${input.path}`);
353
+ return restResponse({
354
+ full_name: "me/web",
355
+ html_url: "https://github.com-scale/me/web",
356
+ ssh_url: "git@github.com-scale:me/web.git",
357
+ default_branch: "trunk",
358
+ });
359
+ }),
360
+ },
361
+ });
362
+ return Effect.gen(function* () {
363
+ const gh = yield* GitHubSourceControlProvider.make;
364
+ const resolveWebHost = gh.resolveRemoteWebHost;
365
+ assert.ok(resolveWebHost);
366
+ for (const url of [remoteUrl, "git@github.com-evil.example:me/web.git"]) {
367
+ assert.strictEqual(
368
+ yield* resolveWebHost({
369
+ cwd: "/repo",
370
+ context: { ...githubContext("github.com-scale"), remoteUrl: url },
371
+ resolveContext: () => Effect.succeed(null),
372
+ }),
373
+ url === remoteUrl ? "github.com-scale" : "github.com-evil.example",
374
+ );
375
+ }
376
+ assert.strictEqual(
377
+ yield* gh.getDefaultBranch({
378
+ cwd: "/repo",
379
+ context: { ...githubContext("github.com-scale"), remoteUrl },
380
+ }),
381
+ "trunk",
382
+ );
383
+ assert.deepStrictEqual(paths, ["github.com-scale repos/me/web"]);
384
+ }).pipe(Effect.provide(layer));
385
+ },
386
+ );
387
});
388
389
describe("GitHubSourceControlProvider change request lookups by head", () => {
packages/source-control-github/src/server/GitHubSourceControlProvider.ts
+3
@@ -859,6 +859,9 @@ export const make = Effect.gen(function* () {
859
860
return SourceControlProvider.SourceControlProvider.of({
861
kind: SourceControlProviderKind.make("github"),
862
+ resolveRemoteWebHost: Effect.fn("GitHubSourceControlProvider.resolveRemoteWebHost")(
863
+ ({ context }) => Effect.succeed(gitHubApiHostForRemote(context.remoteUrl)),
864
+ ),
865
// GitHub matches bare heads; read a full page to disambiguate forks by owner.
866
headBranchProbe: ({ headSelectors }) => ({
867
headSelectors: headSelectors.filter((selector) => !selector.includes(":")),
packages/source-control-github/src/server/gitHubRepositoryResolution.test.ts
+190
-1
@@ -2,6 +2,7 @@ import { assert, describe, it } from "@effect/vitest";
2
3
import {
4
gitHubApiHostForRemote,
5
+ resolveGitHubRepository,
6
parseGitHubRepositorySelector,
7
selectGitHubBaseRepository,
8
} from "./gitHubRepositoryResolution.ts";
@@ -48,6 +49,64 @@ describe("selectGitHubBaseRepository", () => {
49
);
50
});
51
52
+ it("honors a marked SSH alias origin over upstream", () => {
53
+ for (const url of [
54
+ "git@github.com-scale:me/web.git",
55
+ "ssh://git@github.com-scale:22/me/web.git",
56
+ "git@github-work:me/web.git",
57
+ ]) {
58
+ const input = {
59
+ remotes: remotes(["origin", url], ["upstream", "https://github.com/acme/web.git"]),
60
+ resolved: "remote.origin.gh-resolved base",
61
+ };
62
+ assert.deepStrictEqual(select(input), { owner: "me", name: "web" }, url);
63
+ assert.deepStrictEqual(
64
+ resolveGitHubRepository({ ...input, hostHint: undefined, defaultHost: "github.com" }),
65
+ { host: "github.com", locator: { host: "github.com", owner: "me", name: "web" } },
66
+ url,
67
+ );
68
+ }
69
+ });
70
+
71
+ it("does not honor a github.com mark on a different or unrecognized host", () => {
72
+ for (const url of [
73
+ "git@github.com-evil.example:me/web.git",
74
+ "git@github.com.evil.example:me/web.git",
75
+ "git@evil-github.com:me/web.git",
76
+ "https://github.com-scale/me/web.git",
77
+ "git@work:me/web.git",
78
+ ]) {
79
+ const input = {
80
+ remotes: remotes(["origin", url], ["upstream", "https://github.com/acme/web.git"]),
81
+ resolved: "remote.origin.gh-resolved base",
82
+ };
83
+ assert.strictEqual(select(input), null, url);
84
+ assert.deepStrictEqual(
85
+ resolveGitHubRepository({ ...input, hostHint: "github.com", defaultHost: "github.com" }),
86
+ { host: "github.com", locator: { host: "github.com", owner: "acme", name: "web" } },
87
+ url,
88
+ );
89
+ }
90
+ });
91
+
92
+ it("preserves selection behavior for real hosts with explicit ports", () => {
93
+ const input = {
94
+ remotes: remotes(["origin", "https://github.example.com:8443/me/web.git"]),
95
+ resolved: "remote.origin.gh-resolved acme/other",
96
+ };
97
+ assert.strictEqual(
98
+ selectGitHubBaseRepository({ ...input, host: "github.example.com:8443" }),
99
+ null,
100
+ );
101
+ assert.deepStrictEqual(
102
+ resolveGitHubRepository({ ...input, hostHint: undefined, defaultHost: "github.com" }),
103
+ {
104
+ host: "github.example.com:8443",
105
+ locator: { host: "github.example.com:8443", owner: "me", name: "web" },
106
+ },
107
+ );
108
+ });
109
+
110
it("leaves gh to choose when it might weigh the remotes differently", () => {
111
for (const input of [
112
{ remotes: "" },
@@ -60,7 +119,7 @@ describe("selectGitHubBaseRepository", () => {
119
["mirror", "git@gitlab.com:me/web.git"],
120
),
121
},
63
- { remotes: remotes(["origin", "git@github-work:me/web.git"]) },
122
+ { remotes: remotes(["origin", "git@work:me/web.git"]) },
123
{
124
remotes: remotes(
125
["origin", "git@github.com:me/web.git"],
@@ -111,6 +170,136 @@ describe("gitHubApiHostForRemote", () => {
170
});
171
});
172
173
+describe("github.com-<name> SSH aliases", () => {
174
+ it("reads a per-account alias through github.com", () => {
175
+ for (const url of [
176
+ "git@github.com-scale:scalable-so/scalablev2.git",
177
+ "git@GitHub.com-Work:acme/web.git",
178
+ "ssh://git@github.com-personal/acme/web.git",
179
+ "ssh://git@github.com-scale:22/acme/web.git",
180
+ ]) {
181
+ assert.strictEqual(gitHubApiHostForRemote(url), "github.com", url);
182
+ }
183
+ });
184
+
185
+ it("never maps a hostile or real DNS host onto github.com", () => {
186
+ for (const [url, host] of [
187
+ ["git@github.com-evil.example:acme/web.git", "github.com-evil.example"],
188
+ ["ssh://git@github.com-evil.example/acme/web.git", "github.com-evil.example"],
189
+ ["git@github.com.evil.example:acme/web.git", "github.com.evil.example"],
190
+ ["git@evil-github.com:acme/web.git", null],
191
+ ["https://github.com-scale/acme/web.git", "github.com-scale"],
192
+ ] as const) {
193
+ assert.strictEqual(gitHubApiHostForRemote(url), host, url);
194
+ }
195
+ });
196
+
197
+ it("resolves the API host and repository from an alias remote and its host hint", () => {
198
+ const remotes = [
199
+ "origin\tgit@github.com-scale:scalable-so/scalablev2.git (fetch)",
200
+ "origin\tgit@github.com-scale:scalable-so/scalablev2.git (push)",
201
+ ].join("\n");
202
+ const expected = {
203
+ host: "github.com",
204
+ locator: { host: "github.com", owner: "scalable-so", name: "scalablev2" },
205
+ };
206
+ for (const hostHint of ["github.com-scale", undefined]) {
207
+ assert.deepStrictEqual(
208
+ resolveGitHubRepository({ remotes, resolved: "", hostHint, defaultHost: "github.com" }),
209
+ expected,
210
+ );
211
+ }
212
+ });
213
+
214
+ it.each([false, true])("preserves an HTTPS alias-shaped host hint (upstream: %s)", (upstream) => {
215
+ const remotes = [
216
+ "origin\thttps://github.com-scale/me/web.git (fetch)",
217
+ ...(upstream ? ["upstream\thttps://github.com/acme/web.git (fetch)"] : []),
218
+ ].join("\n");
219
+ assert.deepStrictEqual(
220
+ resolveGitHubRepository({
221
+ remotes,
222
+ resolved: "",
223
+ hostHint: "github.com-scale",
224
+ defaultHost: "github.com",
225
+ }),
226
+ {
227
+ host: "github.com-scale",
228
+ locator: { host: "github.com-scale", owner: "me", name: "web" },
229
+ },
230
+ );
231
+ });
232
+
233
+ it("requires matching SSH evidence to normalize a dotted hint", () => {
234
+ for (const remotes of [
235
+ "",
236
+ "origin\tgit@github.com-work:me/web.git (fetch)",
237
+ "origin\tgit@github.com-scale:me/web.git (push)",
238
+ ]) {
239
+ assert.deepStrictEqual(
240
+ resolveGitHubRepository({
241
+ remotes,
242
+ resolved: "",
243
+ hostHint: "GitHub.com-Scale",
244
+ defaultHost: "github.com",
245
+ }),
246
+ { host: "github.com-scale", locator: null },
247
+ );
248
+ }
249
+ });
250
+
251
+ it("preserves a dotted hint when matching remotes use both transports", () => {
252
+ const entries = [
253
+ "origin\thttps://github.com-scale/me/web.git (fetch)",
254
+ "upstream\tgit@github.com-scale:acme/web.git (fetch)",
255
+ ];
256
+ for (const [remotes, hostHint, resolved] of [
257
+ [entries.join("\n"), "github.com-scale", "remote.origin.gh-resolved base"],
258
+ [entries.join("\n"), "github.com-scale", ""],
259
+ [entries.toReversed().join("\n"), undefined, "remote.origin.gh-resolved base"],
260
+ [entries.toReversed().join("\n"), undefined, ""],
261
+ ] as const) {
262
+ assert.deepStrictEqual(
263
+ resolveGitHubRepository({
264
+ remotes,
265
+ resolved,
266
+ hostHint,
267
+ defaultHost: "github.com",
268
+ }),
269
+ {
270
+ host: "github.com-scale",
271
+ locator: { host: "github.com-scale", owner: "me", name: "web" },
272
+ },
273
+ );
274
+ }
275
+ });
276
+
277
+ it("retains dotless hint compatibility without remote evidence", () => {
278
+ for (const hostHint of ["github", "github-work", "workgithub"]) {
279
+ assert.deepStrictEqual(
280
+ resolveGitHubRepository({ remotes: "", resolved: "", hostHint, defaultHost: hostHint }),
281
+ { host: "github.com", locator: null },
282
+ );
283
+ }
284
+ });
285
+
286
+ it("keeps a hostile host hint and its remote off github.com", () => {
287
+ const remotes = "origin\tgit@github.com-evil.example:acme/web.git (fetch)";
288
+ assert.deepStrictEqual(
289
+ resolveGitHubRepository({
290
+ remotes,
291
+ resolved: "",
292
+ hostHint: "github.com-evil.example",
293
+ defaultHost: "github.com-evil.example",
294
+ }),
295
+ {
296
+ host: "github.com-evil.example",
297
+ locator: { host: "github.com-evil.example", owner: "acme", name: "web" },
298
+ },
299
+ );
300
+ });
301
+});
302
+
303
describe("parseGitHubRepositorySelector", () => {
304
it("reads host/owner/name only when the host is a plain hostname", () => {
305
assert.deepStrictEqual(parseGitHubRepositorySelector("GHE.corp:8443/acme/web", "github.com"), {
packages/source-control-github/src/server/gitHubRepositoryResolution.ts
+33
-9
@@ -21,7 +21,7 @@ export function parseFetchRemotes(
21
.map((match) => ({ name: match[1]!, url: match[2]! }));
22
}
23
24
-/** gh priority: marked default, upstream/github/origin, sole remote. Null if ambiguous or SSH-aliased. */
24
+/** gh priority: marked default, upstream/github/origin, sole remote. Null if ambiguous. */
25
export function selectGitHubBaseRepository(input: {
26
readonly remotes: string;
27
readonly resolved: string;
@@ -30,7 +30,11 @@ export function selectGitHubBaseRepository(input: {
30
const host = input.host.toLowerCase();
31
const repositories = new Map<string, { readonly owner: string; readonly name: string }>();
32
for (const remote of parseFetchRemotes(input.remotes)) {
33
- const [remoteHost, owner, name, ...rest] = normalizeGitRemoteUrl(remote.url).split("/");
33
+ const [normalizedHost, owner, name, ...rest] = normalizeGitRemoteUrl(remote.url).split("/");
34
+ const remoteHost =
35
+ normalizedHost && isSshRemoteUrl(remote.url)
36
+ ? (apiHostForSshAlias(normalizedHost) ?? normalizedHost)
37
+ : normalizedHost;
38
if (remoteHost !== host || !owner || !name || rest.length > 0) return null;
39
repositories.set(remote.name, { owner, name });
40
}
@@ -69,7 +73,7 @@ export function resolveGitHubRepository(input: {
73
host: gitHubApiHostForRemote(remote.url),
74
}));
75
const host =
72
- (input.hostHint === undefined ? undefined : apiHostForHint(input.hostHint)) ??
76
+ (input.hostHint === undefined ? undefined : apiHostForHint(input.hostHint, fetchRemotes)) ??
77
fetchRemotes.find((remote) => remote.name === "origin" && remote.host !== null)?.host ??
78
fetchRemotes.find((remote) => remote.host !== null)?.host ??
79
input.defaultHost;
@@ -83,7 +87,9 @@ export function resolveGitHubRepository(input: {
87
const rank = (name: string) => ["upstream", "github", "origin"].indexOf(name.toLowerCase());
88
const candidates = fetchRemotes
89
.filter(
86
- (remote) => remote.host === host || normalizeGitRemoteUrl(remote.url).split("/")[0] === host,
90
+ (remote) =>
91
+ remote.host === host ||
92
+ (remote.host === null && normalizeGitRemoteUrl(remote.url).split("/")[0] === host),
93
)
94
.toSorted((left, right) => {
95
const l = rank(left.name);
@@ -148,18 +154,36 @@ export function parsePullRequestReference(
154
return { kind: "branch", headSelector: trimmed };
155
}
156
151
-/** SSH aliases without a domain cannot identify an API host; default to github.com. */
157
+// An additional dot is a real DNS host, never a github.com SSH alias.
158
+const GITHUB_DOT_COM_SSH_ALIAS = /^github\.com-[a-z0-9_-]+$/u;
159
+
160
+function apiHostForSshAlias(host: string): string | null | undefined {
161
+ if (!host.includes(".")) return host.includes("github") ? "github.com" : null;
162
+ return GITHUB_DOT_COM_SSH_ALIAS.test(host) ? "github.com" : undefined;
163
+}
164
+
165
+/** Recognized GitHub SSH aliases use github.com for API requests. */
166
export function gitHubApiHostForRemote(remoteUrl: string): string | null {
167
const remote = parseGitRemoteHost(remoteUrl);
168
if (remote === null) return null;
169
const host = new URL(`https://${remote.host}`).host.toLowerCase();
156
- if (isSshRemoteUrl(remoteUrl) && !host.includes(".")) {
157
- return host.includes("github") ? "github.com" : null;
170
+ if (isSshRemoteUrl(remoteUrl)) {
171
+ const aliased = apiHostForSshAlias(host);
172
+ if (aliased !== undefined) return aliased;
173
}
174
return definition.recognizeRemote(remote) === null ? null : host;
175
}
176
162
-function apiHostForHint(host: string): string {
177
+function apiHostForHint(host: string, remotes: ReadonlyArray<{ readonly url: string }>): string {
178
const normalized = host.toLowerCase();
164
- return !normalized.includes(".") && normalized.includes("github") ? "github.com" : normalized;
179
+ if (GITHUB_DOT_COM_SSH_ALIAS.test(normalized)) {
180
+ const matching = remotes.filter(
181
+ (remote) => normalizeGitRemoteUrl(remote.url).split("/")[0] === normalized,
182
+ );
183
+ // A hint carries no transport; an HTTPS remote or missing evidence must not select
184
+ // the github.com endpoint and credentials for a dotted host.
185
+ if (matching.length === 0 || matching.some((remote) => !isSshRemoteUrl(remote.url)))
186
+ return normalized;
187
+ }
188
+ return apiHostForSshAlias(normalized) ?? normalized;
189
}