Skip to content

Commit e9c6fe9

Browse files
only21milclaude
andcommitted
fix(server): a quote in a query token no longer leaves part of it in clone errors
The query rule stopped at the first quote, so a token such as access_token=a'b left b in the failed-clone error text. A quoted query now runs to the last matching quote that closes git's quoted URL. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent fe7c8b4 commit e9c6fe9

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎apps/server/src/sourceControl/SourceControlRepositoryService.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,11 @@ it.effect.each([
383383
}),
384384
);
385385

386-
it.effect("keeps a query token out of a failed clone's error text", () =>
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+
] as const)("keeps %s in the query out of a failed clone's error text", ([, token]) =>
387391
Effect.gen(function* () {
388392
const error = yield* Effect.flip(
389393
cloneInTemporaryDirectory(
@@ -393,7 +397,7 @@ it.effect("keeps a query token out of a failed clone's error text", () =>
393397
// Git quotes the URL it was given, query included, and appends a slash.
394398
yield* (
395399
input.progress?.onStderrLine?.(
396-
"fatal: unable to access 'https://github.com/octocat/t3code.git?access_token=s3cret/': Could not resolve host: github.com",
400+
`fatal: unable to access 'https://github.com/octocat/t3code.git?access_token=${token}/': Could not resolve host: github.com`,
397401
) ?? Effect.void
398402
);
399403
return yield* new GitCommandError({
@@ -405,7 +409,7 @@ it.effect("keeps a query token out of a failed clone's error text", () =>
405409
});
406410
}),
407411
},
408-
{ remoteUrl: "https://github.com/octocat/t3code.git?access_token=s3cret" },
412+
{ remoteUrl: `https://github.com/octocat/t3code.git?access_token=${token}` },
409413
),
410414
);
411415

‎apps/server/src/sourceControl/SourceControlRepositoryService.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,16 @@ function redactRemoteUrl(remoteUrl: string): string {
139139
// host boundary goes.
140140
const URL_WITH_USERINFO = /\b([a-z][a-z0-9+.-]*:\/\/)[^\s/]+@/gi;
141141
// A query is a token, as in redactRemoteUrl. Git quotes the URL and appends a
142-
// `/`, so the query runs to the closing quote or whitespace.
142+
// `/`. The token may itself hold a quote, so a quoted query runs to the last
143+
// matching quote that closes the URL; an unquoted one runs to whitespace.
144+
const QUOTED_URL_QUERY = /(['"])([a-z][a-z0-9+.-]*:\/\/[^\s?]*)\?.*\1(?=[\s:]|$)/gi;
143145
const URL_QUERY = /\b([a-z][a-z0-9+.-]*:\/\/[^\s?'"]*)\?[^\s'"]*/gi;
144146

145147
function redactUrlCredentials(text: string): string {
146-
return text.replace(URL_WITH_USERINFO, "$1").replace(URL_QUERY, "$1");
148+
return text
149+
.replace(URL_WITH_USERINFO, "$1")
150+
.replace(QUOTED_URL_QUERY, "$1$2$1")
151+
.replace(URL_QUERY, "$1");
147152
}
148153

149154
/**

0 commit comments

Comments
 (0)