@devries-cameron20 / t3code Mirror · read-only / commits / 21fc0c1438
Fork 0

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(gitlab): keep the environment token off hosts a caller names (#39522)

Julius Marminge committed Nov 19, 2026 at 20:25 UTC 21fc0c143833e5fcd8d2615a4f7895617b5860ae
3 files changed +39 -5
packages/source-control-gitlab/src/server/GitLabCli.test.ts
+8 -3
@@ -325,16 +325,19 @@ layer("GitLabCli.layer", (it) => {
325 );
326
327 it.effect.each([
328 - { repository: "group/project", args: ["api", "projects/group%2Fproject"] },
328 + { repository: "group/project", args: ["api", "projects/group%2Fproject"], env: {} },
329 {
330 repository: "https://gitlab.example.com:8443/group/sub/project.git",
331 args: ["api", "--hostname", "gitlab.example.com:8443", "projects/group%2Fsub%2Fproject"],
332 + // The environment token is the default host's login, not this host's.
333 + env: { GITLAB_TOKEN: "", GITLAB_ACCESS_TOKEN: "", OAUTH_TOKEN: "" },
334 },
335 {
336 repository: "https://gitlab.com/group/project/-/tree/main",
337 args: ["api", "--hostname", "gitlab.com", "projects/group%2Fproject"],
338 + env: {},
339 },
337 - ])("looks up $repository by its project path", ({ repository, args }) =>
340 + ])("looks up $repository by its project path", ({ repository, args, env }) =>
341 Effect.gen(function* () {
342 mockedRun.mockReturnValueOnce(
343 Effect.succeed(
@@ -352,7 +355,9 @@ layer("GitLabCli.layer", (it) => {
355 const glab = yield* GitLabCli.GitLabCli;
356 yield* glab.getRepositoryCloneUrls({ cwd: "/repo", repository });
357
355 - expect(mockedRun).toHaveBeenCalledWith(expect.objectContaining({ command: "glab", args }));
358 + expect(mockedRun).toHaveBeenCalledWith(
359 + expect.objectContaining({ command: "glab", args, env }),
360 + );
361 }),
362 );
363
packages/source-control-gitlab/src/server/GitLabCli.ts
+30 -2
@@ -16,6 +16,7 @@ import {
16 type VcsProcessExitFailureKind,
17 } from "@t3tools/contracts";
18
19 +import * as HostProcess from "@t3tools/shared/HostProcess";
20 import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
21 import {
22 decodeGitLabMergeRequestJson,
@@ -300,6 +301,8 @@ export class GitLabCli extends Context.Service<
301 readonly execute: (input: {
302 readonly cwd: string;
303 readonly host?: string | undefined;
304 + /** A host taken from caller input, not from a project remote. See `ENVIRONMENT_TOKEN_VARIABLES`. */
305 + readonly callerNamedHost?: string | undefined;
306 readonly args: ReadonlyArray<string>;
307 readonly timeoutMs?: number;
308 /** Keeps sensitive payloads out of argv. */
@@ -476,10 +479,29 @@ const classifyGlabFailure = (stderr: string): VcsProcessExitFailureKind | null =
479 return null;
480 };
481
482 +/**
483 + * These are the login for glab's default host (GITLAB_HOST, else gitlab.com). glab before 1.131
484 + * sends them to any host a command names, so a host a caller names runs without them and falls
485 + * back to that host's own `glab auth login`.
486 + */
487 +const ENVIRONMENT_TOKEN_VARIABLES = ["GITLAB_TOKEN", "GITLAB_ACCESS_TOKEN", "OAUTH_TOKEN"] as const;
488 +const WITHOUT_ENVIRONMENT_TOKEN = Object.fromEntries(
489 + ENVIRONMENT_TOKEN_VARIABLES.map((name) => [name, ""]),
490 +);
491 +
492 +const hostOf = (value: string) =>
493 + value
494 + .trim()
495 + .toLowerCase()
496 + .replace(/^[a-z][a-z0-9+.-]*:\/\//, "")
497 + .replace(/\/.*$/, "");
498 +
499 /** @public */
500 export const make = Effect.gen(function* () {
501 const { process } = yield* SourceControlHost.SourceControlHost;
502 const fileSystem = yield* FileSystem.FileSystem;
503 + const environment = yield* HostProcess.Environment;
504 + const defaultHost = hostOf(environment.GITLAB_HOST?.trim() || "gitlab.com");
505
506 const run = (
507 input: Parameters<GitLabCli["Service"]["execute"]>[0],
@@ -491,8 +513,13 @@ export const make = Effect.gen(function* () {
513 command: "glab",
514 args: input.args,
515 cwd: input.cwd,
494 - // glab may otherwise prefer a different checkout remote.
495 - ...(input.host === undefined ? {} : { env: { GITLAB_HOST: input.host } }),
516 + env: {
517 + // glab may otherwise prefer a different checkout remote.
518 + ...(input.host === undefined ? {} : { GITLAB_HOST: input.host }),
519 + ...(input.callerNamedHost !== undefined && hostOf(input.callerNamedHost) !== defaultHost
520 + ? WITHOUT_ENVIRONMENT_TOKEN
521 + : {}),
522 + },
523 classifyFailure: classifyGlabFailure,
524 notFoundDetail: "Merge request not found.",
525 timeoutMs: input.timeoutMs ?? DEFAULT_TIMEOUT_MS,
@@ -612,6 +639,7 @@ export const make = Effect.gen(function* () {
639 const { host, projectPath } = parseRepositoryLookup(input.repository);
640 return execute({
641 cwd: input.cwd,
642 + ...(host === null ? {} : { callerNamedHost: host }),
643 args: [
644 "api",
645 ...(host === null ? [] : ["--hostname", host]),
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.ts
+1
@@ -177,6 +177,7 @@ export const make = Effect.gen(function* () {
177 const result = yield* gitlab
178 .execute({
179 cwd: input.cwd,
180 + callerNamedHost: input.url.host,
181 args: ["api", "--hostname", input.url.host, endpoint],
182 timeoutMs: 3_000,
183 maxOutputBytes: 32_000,