@devries-cameron20 / t3code-1 / commits / 1cc9d413a5
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): clone errors no longer show a token from the URL's query (#24698)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Oct 29, 2026 at 12:57 UTC 1cc9d413a52c05ad51df5faa8d11437ca97043c7
2 files changed +68 -4
apps/server/src/sourceControl/SourceControlRepositoryService.test.ts
+56
@@ -383,6 +383,62 @@ it.effect.each([
383 }),
384 );
385
386 +it.effect.each([
387 + ["a plain token", "s3cret"],
388 + ["a token with an apostrophe", "s3'cret"],
389 + ["a token with a double quote", 's3"cret'],
390 + ["a host-only token with an at sign", "abc@secret"],
391 + ["an unquoted token with an apostrophe", "s3'cret", true],
392 + ["an unquoted token with a double quote", 's3"cret', true],
393 + ["an unquoted URL with an apostrophe in its path", "path-token", true],
394 +] as const)("keeps %s in the query out of a failed clone's error text", ([, token, unquoted]) =>
395 + Effect.gen(function* () {
396 + const remote =
397 + token === "abc@secret"
398 + ? "https://github.com"
399 + : token === "path-token"
400 + ? "https://github.com/octocat/t3code's.git"
401 + : "https://github.com/octocat/t3code.git";
402 + const error = yield* Effect.flip(
403 + cloneInTemporaryDirectory(
404 + {
405 + execute: (input) =>
406 + Effect.gen(function* () {
407 + const cloneUrl = input.args.at(-2)!;
408 + // Git treats @ in a pathless URL's query as userinfo, losing the query delimiter.
409 + const diagnosticUrl =
410 + cloneUrl === "https://github.com?access_token=abc@secret"
411 + ? "https://secret"
412 + : cloneUrl;
413 + yield* (
414 + input.progress?.onStderrLine?.(
415 + unquoted
416 + ? `fatal: ${diagnosticUrl}/info/refs not valid: is this a git repository?`
417 + : `fatal: unable to access '${diagnosticUrl}/': Could not resolve host: github.com`,
418 + ) ?? Effect.void
419 + );
420 + return yield* new GitCommandError({
421 + operation: input.operation,
422 + command: "git",
423 + cwd: input.cwd,
424 + detail: "Git command exited with a non-zero status.",
425 + exitCode: 128,
426 + });
427 + }),
428 + },
429 + { remoteUrl: `${remote}?access_token=${token}` },
430 + ),
431 + );
432 +
433 + assert.strictEqual(
434 + error.detail,
435 + unquoted
436 + ? `fatal: ${remote} not valid: is this a git repository?`
437 + : `fatal: unable to access '${remote}${token === "abc@secret" ? "/" : ""}': Could not resolve host: github.com`,
438 + );
439 + }),
440 +);
441 +
442 it.effect("strips embedded credentials from the remote URL it reports", () =>
443 Effect.gen(function* () {
444 const fs = yield* FileSystem.FileSystem;
apps/server/src/sourceControl/SourceControlRepositoryService.ts
+12 -4
@@ -110,7 +110,7 @@ function toRepositoryInfo(
110 };
111 }
112
113 -// Redact credentials from client clone snapshots; git still receives the original URL.
113 +// Redact credentials from client clone snapshots; git still receives the credentials.
114 function redactRemoteUrl(remoteUrl: string): string {
115 try {
116 const url = new URL(remoteUrl);
@@ -128,10 +128,16 @@ function redactRemoteUrl(remoteUrl: string): string {
128 }
129
130 // Userinfo can contain @; remove through the last one before the host boundary.
131 -const URL_WITH_USERINFO = /\b([a-z][a-z0-9+.-]*:\/\/)[^\s/]+@/gi;
131 +const URL_WITH_USERINFO = /\b([a-z][a-z0-9+.-]*:\/\/)[^\s/?#]+@/gi;
132 +// Git leaves quotes inside query tokens unescaped; consume through the closing quote.
133 +const QUOTED_URL_QUERY = /(['"])([a-z][a-z0-9+.-]*:\/\/[^\s?]*)\?.*\1(?=[\s:]|$)/gi;
134 +const URL_QUERY = /\b([a-z][a-z0-9+.-]*:\/\/[^\s?]*)\?[^\s]*/gi;
135
136 function redactUrlCredentials(text: string): string {
134 - return text.replace(URL_WITH_USERINFO, "$1");
137 + return text
138 + .replace(QUOTED_URL_QUERY, "$1$2$1")
139 + .replace(URL_QUERY, "$1")
140 + .replace(URL_WITH_USERINFO, "$1");
141 }
142
143 // The remote already exists after push failure; advise fixing access and pushing.
@@ -340,11 +346,13 @@ export const make = Effect.gen(function* () {
346 if (stderrTail.length > 4) stderrTail.shift();
347 });
348 };
349 + // Git misreads @ in a pathless URL's query as userinfo and echoes its suffix as the host.
350 + const normalizedCloneUrl = cloneUrl.replace(/^([a-z][a-z0-9+.-]*:\/\/[^/?#]+)\?/i, "$1/?");
351 yield* git
352 .execute({
353 operation: "SourceControlRepositoryService.cloneRepository",
354 cwd: path.dirname(destinationPath),
347 - args: ["clone", "--progress", "--", cloneUrl, path.basename(destinationPath)],
355 + args: ["clone", "--progress", "--", normalizedCloneUrl, path.basename(destinationPath)],
356 timeoutMs: options?.timeoutMs === undefined ? CLONE_TIMEOUT_MS : options.timeoutMs,
357 // Buffered output is unused and progress can be huge; cap it while retaining line callbacks.
358 maxOutputBytes: 256 * 1024,