From 27b48e6ba4d0dd7d198357c8df36bdaccd65fd1e Mon Sep 17 00:00:00 2001 From: rUv Date: Thu, 29 Oct 2026 09:41:56 -0400 Subject: [PATCH] fix(github): redact credentials from github_repo_analyze remoteUrl (#4577) github_repo_analyze returned `git remote get-url origin` verbatim. A remote with embedded credentials (https://x-access-token:@github.com/..., the form CI checkouts and some credential helpers write) put the token into MCP tool output, where it reaches the model and session transcripts. Strip URL userinfo before returning it. Greedy up to the last `@` in the authority, so a raw `@` in a password cannot leave a fragment behind. scp-form remotes (git@host:o/r) carry no secret and are unchanged. Found while reviewing #4571, which widened the same parser. Co-authored-by: r --- .../github-repo-analyze-dotted-name.test.ts | 14 ++++++++++++++ v3/@claude-flow/cli/src/mcp-tools/github-tools.ts | 11 ++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/v3/@claude-flow/cli/__tests__/github-repo-analyze-dotted-name.test.ts b/v3/@claude-flow/cli/__tests__/github-repo-analyze-dotted-name.test.ts index fa4d2a9189..95350a0119 100644 --- a/v3/@claude-flow/cli/__tests__/github-repo-analyze-dotted-name.test.ts +++ b/v3/@claude-flow/cli/__tests__/github-repo-analyze-dotted-name.test.ts @@ -69,3 +69,17 @@ describe('github_repo_analyze owner/repo from the origin remote', () => { expect(r.repository).toBe('acme/widgets'); }); }); + +describe('github_repo_analyze never echoes credentials from the origin remote', () => { + it.each([ + ['https://x-access-token:ghp_SECRET@github.com/ruvnet/ruflo.git', 'https://github.com/ruvnet/ruflo.git'], + ['https://oauth2:p@ss@gitlab.com/acme/next.js.git', 'https://gitlab.com/acme/next.js.git'], + ['ssh://git@github.com/ruvnet/ruflo.git', 'ssh://github.com/ruvnet/ruflo.git'], + ['git@github.com:ruvnet/ruflo.git', 'git@github.com:ruvnet/ruflo.git'], + ])('%s is reported as %s', async (remoteUrl, expected) => { + gitWithRemote(remoteUrl); + const r = await analyze(); + expect(r.remoteUrl).toBe(expected); + expect(JSON.stringify(r)).not.toMatch(/SECRET|p@ss/); + }); +}); diff --git a/v3/@claude-flow/cli/src/mcp-tools/github-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/github-tools.ts index 97c58ba18b..7abc5fcc94 100644 --- a/v3/@claude-flow/cli/src/mcp-tools/github-tools.ts +++ b/v3/@claude-flow/cli/src/mcp-tools/github-tools.ts @@ -142,6 +142,15 @@ function sanitizeLabels(value: unknown): string[] | null { return out; } +/** + * Drop userinfo from a URL-form remote (`https://user:token@host/o/r`) so a + * credential embedded in the origin URL never reaches tool output. scp-form + * remotes (`git@host:o/r`) carry no secret and are returned unchanged. + */ +export function redactRemoteUrl(url: string): string { + return url.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^/]*@/i, '$1'); +} + /** Check if gh CLI is available */ function hasGhCli(): boolean { return run('gh --version') !== null; @@ -219,7 +228,7 @@ export const githubTools: MCPTool[] = [ repository: repoKey, branch: repoInfo.branch, metrics: repoInfo.metrics, - remoteUrl: remoteUrl || null, + remoteUrl: remoteUrl ? redactRemoteUrl(remoteUrl) : null, lastAnalyzed: repoInfo.lastAnalyzed, }; }