The best way to control Claude Code, Codex and more from any computer or phone
fix(server): repository lookups no longer send GitHub tokens to arbitrary hosts (#26176)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 27, 2026 at 16:23 UTC
80b7b0fd237eb5e8b2df75c43d4dae690ffe99b8
4 files changed
+47
-2
packages/source-control-github/src/server/GitHubCredentials.test.ts
+13
@@ -148,4 +148,17 @@ describe("GitHubCredentials", () => {
148
);
149
}).pipe(Effect.provide(layer));
150
});
151
+
152
+ it.effect("never hands a token to a host that is not a plain hostname", () => {
153
+ vi.stubEnv("GH_TOKEN", "env-token");
154
+ const { layer, calls } = harness();
155
+ return Effect.gen(function* () {
156
+ const credentials = yield* GitHubCredentials.GitHubCredentials;
157
+ for (const host of ["evil.com#.ghe.com", "evil.com/.ghe.com", "user@x.ghe.com"]) {
158
+ expect(GitHubCredentials.environmentToken(host, { GH_TOKEN: "env-token" })).toBeNull();
159
+ expect((yield* Effect.flip(credentials.get(host)))._tag).toBe("GitHubNotSignedInError");
160
+ }
161
+ expect(calls).toEqual([]);
162
+ }).pipe(Effect.provide(layer));
163
+ });
164
});
packages/source-control-github/src/server/GitHubCredentials.ts
+10
@@ -96,6 +96,14 @@ function normalizeHost(host: string): string {
96
return host.trim().toLowerCase();
97
}
98
99
+const HOSTNAME =
100
+ /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*(?::\d{1,5})?$/;
101
+
102
+/** API URLs are built from the host text, so anything but a bare hostname could redirect a token. */
103
+export function isGitHubHost(host: string): boolean {
104
+ return HOSTNAME.test(host);
105
+}
106
+
107
function isGitHubDotCom(host: string): boolean {
108
return host === "github.com" || host.endsWith(".ghe.com");
109
}
@@ -105,6 +113,7 @@ export function environmentToken(
113
host: string,
114
env: Readonly<Record<string, string | undefined>>,
115
): string | null {
116
+ if (!isGitHubHost(host)) return null;
117
const names = isGitHubDotCom(host)
118
? ["GH_TOKEN", "GITHUB_TOKEN"]
119
: env.GH_HOST?.trim().toLowerCase() === host
@@ -222,6 +231,7 @@ export const make = Effect.gen(function* () {
231
return GitHubCredentials.of({
232
get: Effect.fn("GitHubCredentials.get")(function* (rawHost) {
233
const host = normalizeHost(rawHost);
234
+ if (!isGitHubHost(host)) return yield* new GitHubNotSignedInError({ host });
235
const choice = yield* hostChoice(host);
236
if (choice?.enabled === false) {
237
return yield* new GitHubHostDisabledError({ host });
packages/source-control-github/src/server/gitHubRepositoryResolution.test.ts
+20
@@ -2,6 +2,7 @@ import { assert, describe, it } from "@effect/vitest";
2
3
import {
4
gitHubApiHostForRemote,
5
+ parseGitHubRepositorySelector,
6
selectGitHubBaseRepository,
7
} from "./gitHubRepositoryResolution.ts";
8
@@ -89,3 +90,22 @@ describe("gitHubApiHostForRemote", () => {
90
assert.strictEqual(gitHubApiHostForRemote("git@gitlab.com:a/b.git"), null);
91
});
92
});
93
+
94
+describe("parseGitHubRepositorySelector", () => {
95
+ it("reads host/owner/name only when the host is a plain hostname", () => {
96
+ assert.deepStrictEqual(parseGitHubRepositorySelector("GHE.corp:8443/acme/web", "github.com"), {
97
+ host: "ghe.corp:8443",
98
+ owner: "acme",
99
+ name: "web",
100
+ });
101
+ for (const selector of [
102
+ "evil.com#.ghe.com/acme/web",
103
+ "evil.com?.ghe.com/acme/web",
104
+ "token@evil.com/acme/web",
105
+ "evil.com\\.ghe.com/acme/web",
106
+ "-evil.com/acme/web",
107
+ ]) {
108
+ assert.strictEqual(parseGitHubRepositorySelector(selector, "github.com"), null, selector);
109
+ }
110
+ });
111
+});
packages/source-control-github/src/server/gitHubRepositoryResolution.ts
+4
-2
@@ -2,6 +2,7 @@ import { normalizeGitRemoteUrl } from "@t3tools/shared/git";
2
import { isSshRemoteUrl } from "@t3tools/shared/sourceControl";
3
import { parseGitRemoteHost } from "@t3tools/source-control-core/shared/definition";
4
import { definition } from "../shared/definition.ts";
5
+import { isGitHubHost } from "./GitHubCredentials.ts";
6
7
export interface GitHubRepositoryLocator {
8
readonly host: string;
@@ -114,8 +115,9 @@ export function parseGitHubRepositorySelector(
115
}
116
const parts = trimmed.split("/").filter(Boolean);
117
if (parts.length === 2) return { host: defaultHost, owner: parts[0]!, name: parts[1]! };
117
- if (parts.length === 3)
118
- return { host: parts[0]!.toLowerCase(), owner: parts[1]!, name: parts[2]! };
118
+ const host = parts[0]?.toLowerCase();
119
+ if (parts.length === 3 && host !== undefined && isGitHubHost(host))
120
+ return { host, owner: parts[1]!, name: parts[2]! };
121
return null;
122
}
123