The best way to control Claude Code, Codex and more from any computer or phone
fix(server): gh credential lookups no longer leak D-Bus daemons (#23824)
Co-authored-by: HelixNebula <249811984+helixnebulatech@users.noreply.github.com>
Julius Marminge committed
Nov 19, 2026 at 12:13 UTC
a2a463a32e6b8cf673c326be06bfe9699b8a8518
8 files changed
+192
-2
packages/source-control-github/src/server/GitHubAppSignIn.test.ts
+2
@@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "@effect/vitest"
3
import * as Deferred from "effect/Deferred";
4
import * as Effect from "effect/Effect";
5
import * as Fiber from "effect/Fiber";
6
+import * as FileSystem from "effect/FileSystem";
7
import * as Layer from "effect/Layer";
8
import * as Option from "effect/Option";
9
import * as Redacted from "effect/Redacted";
@@ -113,6 +114,7 @@ function harness(options: {
114
Layer.provideMerge(SourceControlRateLimit.layer),
115
Layer.provideMerge(options.settingsWritesFail === true ? failingWrites : host),
116
Layer.provide(NodeCrypto.layer),
117
+ Layer.provide(FileSystem.layerNoop({})),
118
Layer.provide(Layer.succeed(HttpClient.HttpClient, http)),
119
);
120
return { layer, requests };
packages/source-control-github/src/server/GitHubCredentials.test.ts
+2
@@ -1,6 +1,7 @@
1
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2
import { afterEach, beforeEach, describe, expect, it, vi } from "@effect/vitest";
3
import * as Effect from "effect/Effect";
4
+import * as FileSystem from "effect/FileSystem";
5
import * as Layer from "effect/Layer";
6
import * as Redacted from "effect/Redacted";
7
import { HttpClient } from "effect/http";
@@ -63,6 +64,7 @@ function harness(
64
}),
65
),
66
Layer.provide(NodeCrypto.layer),
67
+ Layer.provide(FileSystem.layerNoop({})),
68
Layer.provide(
69
Layer.succeed(
70
HttpClient.HttpClient,
packages/source-control-github/src/server/GitHubCredentials.ts
+2
-1
@@ -23,6 +23,7 @@ import {
23
} from "@t3tools/contracts";
24
25
import * as GitHubClient from "../shared/definition.ts";
26
+import { makeGhProcess } from "./gitHubCliProcess.ts";
27
28
/**
29
* Every gh run on the server shares this. A burst of them (a status poll across many checkouts)
@@ -149,7 +150,7 @@ export function environmentToken(
150
/** @public */
151
export const make = Effect.gen(function* () {
152
const sourceControlHost = yield* SourceControlHost.SourceControlHost;
152
- const process = sourceControlHost.process;
153
+ const process = yield* makeGhProcess;
154
const crypto = yield* Digest.Digest;
155
const environment = yield* HostProcess.Environment;
156
const workingDirectory = yield* HostProcess.WorkingDirectory;
packages/source-control-github/src/server/GitHubRest.test.ts
+2
@@ -10,6 +10,7 @@ import * as NodeOS from "node:os";
10
import * as NodePath from "node:path";
11
import * as HostProcess from "@t3tools/shared/HostProcess";
12
import * as Effect from "effect/Effect";
13
+import * as FileSystem from "effect/FileSystem";
14
import * as Layer from "effect/Layer";
15
import * as Redacted from "effect/Redacted";
16
import * as TestClock from "effect/testing/TestClock";
@@ -611,6 +612,7 @@ describe("GitHubCredentials", () => {
612
GitHubCredentials.layer.pipe(
613
Layer.provide(TestSourceControlHost.layer({ process: { run } })),
614
Layer.provide(NodeCrypto.layer),
615
+ Layer.provide(FileSystem.layerNoop({})),
616
Layer.provide(Layer.succeed(HttpClient.HttpClient, unexpectedHttp)),
617
);
618
packages/source-control-github/src/server/GitHubSourceControlProvider.ts
+2
-1
@@ -68,6 +68,7 @@ import {
68
} from "@t3tools/source-control-core/shared/definition";
69
70
import * as GitHubClient from "../shared/definition.ts";
71
+import { makeGhProcess } from "./gitHubCliProcess.ts";
72
import {
73
PullRequestByNumber,
74
PullRequestNode,
@@ -215,7 +216,7 @@ function environmentTokenVariable(environment: NodeJS.ProcessEnv): string | null
216
export const makeDiscovery = Effect.gen(function* () {
217
const api = yield* GitHubRest.GitHubRest;
218
const sourceControlHost = yield* SourceControlHost.SourceControlHost;
218
- const process = sourceControlHost.process;
219
+ const process = yield* makeGhProcess;
220
const environment = yield* HostProcess.Environment;
221
const appSignIn = yield* GitHubAppSignIn.GitHubAppSignIn;
222
const offerAppSignIn = <A extends SourceControlProviderDiscoveryItem>(item: A): A =>
packages/source-control-github/src/server/gitHubCliProcess.test.ts
new
+116
@@ -0,0 +1,116 @@
1
+import { describe, expect, it } from "@effect/vitest";
2
+import * as Effect from "effect/Effect";
3
+import * as FileSystem from "effect/FileSystem";
4
+import * as Layer from "effect/Layer";
5
+import * as PlatformError from "effect/PlatformError";
6
+import { ChildProcessSpawner } from "effect/process";
7
+
8
+import * as HostProcess from "@t3tools/shared/HostProcess";
9
+import type * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
10
+import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";
11
+import { makeGhProcess } from "./gitHubCliProcess.ts";
12
+
13
+function spawnedBusAddress(input: {
14
+ readonly platform?: NodeJS.Platform;
15
+ readonly address?: string;
16
+ readonly spawnAddress?: string;
17
+ /** File contents by path; a path not listed does not exist. */
18
+ readonly files?: Readonly<Record<string, string>>;
19
+ /** A path that exists but cannot be stat'ed or read. */
20
+ readonly unreadable?: string;
21
+}) {
22
+ const files = input.files ?? {};
23
+ const denied = (path: string, method: string) =>
24
+ Effect.fail(
25
+ PlatformError.systemError({
26
+ _tag: path === input.unreadable ? "PermissionDenied" : "NotFound",
27
+ module: "FileSystem",
28
+ method,
29
+ pathOrDescriptor: path,
30
+ }),
31
+ );
32
+ const envs: Array<NodeJS.ProcessEnv | undefined> = [];
33
+ const run: SourceControlHost.SourceControlHost["Service"]["process"]["run"] = (spawn) =>
34
+ Effect.sync(() => {
35
+ envs.push(spawn.env);
36
+ return {
37
+ exitCode: ChildProcessSpawner.ExitCode(0),
38
+ stdout: "",
39
+ stderr: "",
40
+ stdoutTruncated: false,
41
+ stderrTruncated: false,
42
+ };
43
+ });
44
+ return Effect.gen(function* () {
45
+ const gh = yield* makeGhProcess;
46
+ yield* gh.run({
47
+ operation: "test",
48
+ command: "gh",
49
+ args: ["auth", "status"],
50
+ cwd: "/",
51
+ ...(input.spawnAddress === undefined
52
+ ? {}
53
+ : { env: { DBUS_SESSION_BUS_ADDRESS: input.spawnAddress } }),
54
+ });
55
+ return envs[0]?.DBUS_SESSION_BUS_ADDRESS;
56
+ }).pipe(
57
+ Effect.provide(
58
+ Layer.mergeAll(
59
+ TestSourceControlHost.layer({ process: { run } }),
60
+ FileSystem.layerNoop({
61
+ exists: (path) =>
62
+ path === input.unreadable ? denied(path, "exists") : Effect.succeed(path in files),
63
+ readFileString: (path) =>
64
+ path in files ? Effect.succeed(files[path]!) : denied(path, "readFileString"),
65
+ }),
66
+ ),
67
+ ),
68
+ Effect.provideService(HostProcess.Platform, input.platform ?? "linux"),
69
+ Effect.provideService(HostProcess.UserId, 1000),
70
+ Effect.provideService(
71
+ HostProcess.Environment,
72
+ input.address === undefined ? {} : { DBUS_SESSION_BUS_ADDRESS: input.address },
73
+ ),
74
+ );
75
+}
76
+
77
+describe("makeGhProcess", () => {
78
+ it.effect("turns the bus off when godbus would have to autolaunch one", () =>
79
+ Effect.gen(function* () {
80
+ expect(yield* spawnedBusAddress({})).toBe("disabled:");
81
+ expect(yield* spawnedBusAddress({ address: "autolaunch:" })).toBe("disabled:");
82
+ expect(yield* spawnedBusAddress({ spawnAddress: "autolaunch:" })).toBe("disabled:");
83
+ // A spawn that clears the host's address leaves godbus nothing to use either.
84
+ expect(yield* spawnedBusAddress({ address: "unix:path=/tmp/bus", spawnAddress: "" })).toBe(
85
+ "disabled:",
86
+ );
87
+ // godbus ignores a `dbus-session` file it cannot read or that names no address.
88
+ const session = "/run/user/1000/dbus-session";
89
+ expect(yield* spawnedBusAddress({ unreadable: session })).toBe("disabled:");
90
+ expect(yield* spawnedBusAddress({ files: { [session]: "garbage\n" } })).toBe("disabled:");
91
+ expect(
92
+ yield* spawnedBusAddress({ files: { [session]: "DBUS_SESSION_BUS_ADDRESS=\r\n" } }),
93
+ ).toBe("disabled:");
94
+ }),
95
+ );
96
+
97
+ it.effect("leaves a bus godbus can find or was given", () =>
98
+ Effect.gen(function* () {
99
+ expect(yield* spawnedBusAddress({ files: { "/run/user/1000/bus": "" } })).toBeUndefined();
100
+ expect(
101
+ yield* spawnedBusAddress({
102
+ files: {
103
+ "/run/user/1000/dbus-session": "DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-x\n",
104
+ },
105
+ }),
106
+ ).toBeUndefined();
107
+ expect(yield* spawnedBusAddress({ address: "unix:path=/tmp/bus" })).toBeUndefined();
108
+ expect(yield* spawnedBusAddress({ spawnAddress: "unix:path=/tmp/bus" })).toBe(
109
+ "unix:path=/tmp/bus",
110
+ );
111
+ expect(yield* spawnedBusAddress({ platform: "darwin" })).toBeUndefined();
112
+ // godbus counts a socket it cannot stat as present, so an unreadable one is left alone too.
113
+ expect(yield* spawnedBusAddress({ unreadable: "/run/user/1000/bus" })).toBeUndefined();
114
+ }),
115
+ );
116
+});
packages/source-control-github/src/server/gitHubCliProcess.ts
new
+63
@@ -0,0 +1,63 @@
1
+import * as Effect from "effect/Effect";
2
+import * as FileSystem from "effect/FileSystem";
3
+
4
+import * as HostProcess from "@t3tools/shared/HostProcess";
5
+import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
6
+
7
+const SESSION_ADDRESS_PREFIX = "DBUS_SESSION_BUS_ADDRESS=";
8
+
9
+/**
10
+ * gh reads its keyring through godbus, which autolaunches a `dbus-launch` daemon that outlives gh
11
+ * when no session bus is configured or discoverable. On WSL and headless hosts each lookup leaks one
12
+ * until inotify runs out, so only then turn the bus off and let the keyring read fail.
13
+ */
14
+export const makeGhProcess = Effect.gen(function* () {
15
+ const { process } = yield* SourceControlHost.SourceControlHost;
16
+ const fileSystem = yield* FileSystem.FileSystem;
17
+ const environment = yield* HostProcess.Environment;
18
+ const platform = yield* HostProcess.Platform;
19
+ const userId = yield* HostProcess.UserId;
20
+
21
+ const noBusToDiscover = Effect.gen(function* () {
22
+ if (platform === "darwin" || userId === undefined) return false;
23
+ const runtimeDir = `/run/user/${userId}`;
24
+ // godbus takes the bus socket if stat finds anything there, but uses `dbus-session` only
25
+ // when it reads as `DBUS_SESSION_BUS_ADDRESS=<address>`; otherwise it still autolaunches.
26
+ if (yield* fileSystem.exists(`${runtimeDir}/bus`).pipe(Effect.orElseSucceed(() => true))) {
27
+ return false;
28
+ }
29
+ const session = yield* fileSystem
30
+ .readFileString(`${runtimeDir}/dbus-session`)
31
+ .pipe(Effect.orElseSucceed(() => ""));
32
+ if (!session.startsWith(SESSION_ADDRESS_PREFIX)) return true;
33
+ // Trailing line breaks are not an address; a loop keeps this linear on a malformed file.
34
+ let end = session.length;
35
+ while (
36
+ end > SESSION_ADDRESS_PREFIX.length &&
37
+ (session[end - 1] === "\n" || session[end - 1] === "\r")
38
+ ) {
39
+ end--;
40
+ }
41
+ return end === SESSION_ADDRESS_PREFIX.length;
42
+ });
43
+
44
+ return {
45
+ run: (input) => {
46
+ // The spawn's own env extends the host's, so its address is the one gh will see.
47
+ const address =
48
+ input.env !== undefined && "DBUS_SESSION_BUS_ADDRESS" in input.env
49
+ ? input.env.DBUS_SESSION_BUS_ADDRESS
50
+ : environment.DBUS_SESSION_BUS_ADDRESS;
51
+ if (address && address !== "autolaunch:") return process.run(input);
52
+ return noBusToDiscover.pipe(
53
+ Effect.flatMap((missing) =>
54
+ process.run(
55
+ missing
56
+ ? { ...input, env: { ...input.env, DBUS_SESSION_BUS_ADDRESS: "disabled:" } }
57
+ : input,
58
+ ),
59
+ ),
60
+ );
61
+ },
62
+ } satisfies SourceControlHost.SourceControlHost["Service"]["process"];
63
+});
packages/source-control-github/src/server/gitHubDiscovery.test.ts
+3
@@ -2,6 +2,7 @@ import { ServerSettings, SourceControlProviderKind } from "@t3tools/contracts";
2
import * as HostProcess from "@t3tools/shared/HostProcess";
3
import { assert, it } from "@effect/vitest";
4
import * as Effect from "effect/Effect";
5
+import * as FileSystem from "effect/FileSystem";
6
import * as Layer from "effect/Layer";
7
import * as Option from "effect/Option";
8
import * as Redacted from "effect/Redacted";
@@ -29,6 +30,7 @@ const makeDiscovery = (credential: GitHubRest.GitHubRest["Service"]["credential"
30
Layer.mock(GitHubRest.GitHubRest)({ credential }),
31
Layer.mock(GitHubAppSignIn.GitHubAppSignIn)({ enabled: false }),
32
TestSourceControlHost.layer(),
33
+ FileSystem.layerNoop({}),
34
),
35
),
36
Effect.provideService(HostProcess.Environment, {}),
@@ -155,6 +157,7 @@ it.effect.each([
157
},
158
}),
159
Layer.mock(GitHubAppSignIn.GitHubAppSignIn)({ enabled: false }),
160
+ FileSystem.layerNoop({}),
161
Layer.effect(
162
SourceControlHost.SourceControlHost,
163
Effect.gen(function* () {