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, }; }