The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
fix(github): keep the enterprise token off hosts other than GH_HOST (#39480)
Julius Marminge committed
Nov 19, 2026 at 19:40 UTC
6348824b45c886960c856b1877ad95ba72708abf
2 files changed
+42
-2
packages/source-control-github/src/server/GitHubCredentials.test.ts
+34
@@ -20,6 +20,8 @@ const TOKEN_VARIABLES = [
20
"GITHUB_ENTERPRISE_TOKEN",
21
] as const;
22
23
+const ENTERPRISE_TOKEN_VARIABLES = ["GH_ENTERPRISE_TOKEN", "GITHUB_ENTERPRISE_TOKEN"] as const;
24
+
25
const hostSettings = (
26
hosts: Record<string, { readonly account?: string; readonly enabled?: boolean }>,
27
) =>
@@ -46,6 +48,22 @@ function harness(
48
stderrTruncated: false,
49
};
50
}
51
+ // gh hands the enterprise variables to every host but github.com.
52
+ const fromEnterpriseEnv = input.args.includes("github.com")
53
+ ? undefined
54
+ : ENTERPRISE_TOKEN_VARIABLES.map(
55
+ (name) =>
56
+ (input.env !== undefined && name in input.env ? input.env : process.env)[name],
57
+ ).find(Boolean);
58
+ if (fromEnterpriseEnv !== undefined) {
59
+ return {
60
+ exitCode: ChildProcessSpawner.ExitCode(0),
61
+ stdout: `${fromEnterpriseEnv}\n`,
62
+ stderr: "",
63
+ stdoutTruncated: false,
64
+ stderrTruncated: false,
65
+ };
66
+ }
67
return {
68
exitCode: ChildProcessSpawner.ExitCode(0),
69
stdout: input.args.includes("--user") ? `token-for-${user}\n` : "active-token\n",
@@ -180,6 +198,22 @@ describe("GitHubCredentials", () => {
198
}).pipe(Effect.provide(layer));
199
});
200
201
+ it.effect.each(ENTERPRISE_TOKEN_VARIABLES)(
202
+ "keeps %s away from a host other than GH_HOST",
203
+ (name) => {
204
+ vi.stubEnv("GH_HOST", "ghe.corp.example");
205
+ vi.stubEnv(name, "enterprise-secret");
206
+ const { layer } = harness();
207
+ return Effect.gen(function* () {
208
+ const credentials = yield* GitHubCredentials.GitHubCredentials;
209
+ const other = yield* credentials.get("git.other.example");
210
+ expect(Redacted.value(other.token)).toBe("active-token");
211
+ const own = yield* credentials.get("ghe.corp.example");
212
+ expect(Redacted.value(own.token)).toBe("enterprise-secret");
213
+ }).pipe(Effect.provide(layer));
214
+ },
215
+ );
216
+
217
it.effect("never hands a token to a host that is not a plain hostname", () => {
218
vi.stubEnv("GH_TOKEN", "env-token");
219
const { layer, calls } = harness();
packages/source-control-github/src/server/GitHubCredentials.ts
+8
-2
@@ -174,8 +174,14 @@ export const make = Effect.gen(function* () {
174
...(account === undefined ? [] : ["--user", account]),
175
],
176
cwd: workingDirectory,
177
- // Never let gh print the token into a debug log.
178
- env: { GH_DEBUG: "", GH_PROMPT_DISABLED: "1" },
177
+ // Never let gh print the token into a debug log. gh answers any host but github.com with
178
+ // the enterprise variables, which would undo the GH_HOST restriction above.
179
+ env: {
180
+ GH_DEBUG: "",
181
+ GH_PROMPT_DISABLED: "1",
182
+ GH_ENTERPRISE_TOKEN: "",
183
+ GITHUB_ENTERPRISE_TOKEN: "",
184
+ },
185
timeoutMs: 10_000,
186
concurrency: GH_PROCESS_CONCURRENCY,
187
})