Skip to content

Commit d71e4a7

Browse files
committed
fix(server): redact quotes in unquoted clone query errors
1 parent 3969ac0 commit d71e4a7

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ it.effect.each([
388388
["a token with an apostrophe", "s3'cret"],
389389
["a token with a double quote", 's3"cret'],
390390
["a host-only token with an at sign", "abc@secret"],
391-
] as const)("keeps %s in the query out of a failed clone's error text", ([, token]) =>
391+
["an unquoted token with an apostrophe", "s3'cret", true],
392+
["an unquoted token with a double quote", 's3"cret', true],
393+
] as const)("keeps %s in the query out of a failed clone's error text", ([, token, unquoted]) =>
392394
Effect.gen(function* () {
393395
const remote =
394396
token === "abc@secret" ? "https://github.com" : "https://github.com/octocat/t3code.git";
@@ -405,7 +407,9 @@ it.effect.each([
405407
: cloneUrl;
406408
yield* (
407409
input.progress?.onStderrLine?.(
408-
`fatal: unable to access '${diagnosticUrl}/': Could not resolve host: github.com`,
410+
unquoted
411+
? `fatal: ${diagnosticUrl}/info/refs not valid: is this a git repository?`
412+
: `fatal: unable to access '${diagnosticUrl}/': Could not resolve host: github.com`,
409413
) ?? Effect.void
410414
);
411415
return yield* new GitCommandError({
@@ -423,7 +427,9 @@ it.effect.each([
423427

424428
assert.strictEqual(
425429
error.detail,
426-
`fatal: unable to access '${remote}${token === "abc@secret" ? "/" : ""}': Could not resolve host: github.com`,
430+
unquoted
431+
? `fatal: ${remote} not valid: is this a git repository?`
432+
: `fatal: unable to access '${remote}${token === "abc@secret" ? "/" : ""}': Could not resolve host: github.com`,
427433
);
428434
}),
429435
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function toRepositoryInfo(
110110
};
111111
}
112112

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.
114114
function redactRemoteUrl(remoteUrl: string): string {
115115
try {
116116
const url = new URL(remoteUrl);
@@ -131,7 +131,7 @@ function redactRemoteUrl(remoteUrl: string): string {
131131
const URL_WITH_USERINFO = /\b([a-z][a-z0-9+.-]*:\/\/)[^\s/?#]+@/gi;
132132
// Git leaves quotes inside query tokens unescaped; consume through the closing quote.
133133
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;
134+
const URL_QUERY = /\b([a-z][a-z0-9+.-]*:\/\/[^\s?'"]*)\?[^\s]*/gi;
135135

136136
function redactUrlCredentials(text: string): string {
137137
return text

0 commit comments

Comments
 (0)