Skip to content

fix(git): GHSA-wvv2-676g-r57j - git_remote credential redaction bypassed by a tab in a remote name or a prefixed URL - #5674

Merged
cliffhall merged 1 commit into
v2/mainfrom
v2/fix/ghsa-wvv2-676g-r57j
Nov 27, 2026
Merged

cliffhall merged 1 commit into
v2/mainfrom
v2/fix/ghsa-wvv2-676g-r57j

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #5666

Fix for GHSA-wvv2-676g-r57j. It was written and reviewed in the advisory's private fork, where a subagent reviewer stood in for Copilot (which cannot review a private fork) until a clean round. Per the advisory flow this PR gets no Copilot review. The private fork has no Actions, so this PR's CI is the first CI run on the change; the full npm run local:gate passed on this exact head and on a rollup of all eight advisory fixes.

Fix for GHSA-wvv2-676g-r57j (private fork; no public issue).

Description

git_remote could return a credential from a URL in two ways:

  1. A remote name holding a TAB. git remote -v prints <name> <url> (fetch), and the parser split each line on the first tab. A name such as c d moved the column boundary, so the URL field became d https://alice:TOKEN@.... That does not start with scheme://, so redact_url returned it unchanged. With a credential-bearing url.<cred>.insteadOf in the user's global config, this returned the host user's token for a repository whose own config holds no secret at all.
  2. A URL that does not start its value, e.g. url = " https://bob:TOKEN@..." (leading whitespace). redact_url returned any value without a scheme at offset 0 unchanged.

The fix, in src/git/src/mcp_server_git/server.py:

  • git_remote now gets the configured remote names from git remote (one per line; git allows no newline in a remote name) and takes each remote -v line's name as the longest configured name the line starts with, followed by a tab. The tab inside a name no longer shifts the URL column. A line that starts with no configured name is withheld (<redacted>), the same as an unparseable line today. _REMOTE_LINE is replaced by _REMOTE_ENTRY, which parses only what follows <name> .
  • redact_url: a value that has no scheme at its start but holds scheme:// anywhere (_EMBEDDED_URL) is withheld whole as <redacted>. The URL cannot be split safely from what comes before it. This also covers the ambiguous case where both c and c d are configured, and the line really came from c with a URL that holds a tab. That URL is left holding a URL that does not start it, so it is withheld. A remote-helper prefix keeps working: https:: https://... becomes https::<redacted>.

The output keeps the git remote -v format, insteadOf rewrites included, so existing clients see no change for ordinary remotes. I considered rebuilding the listing from git remote get-url --all per remote. It does not match remote -v: it prints the remote's name as its URL for a remote with no URL, and it loses the promisor filter. So I kept remote -v and take the names from git's own listing instead.

What this leaves open: a URL that does start with a scheme still keeps its path segments verbatim. That is unchanged and documented ("A token carried as a path segment ... is not redacted"). A remote name is shown as configured, and names are not URLs and are not redacted. Neither is reachable through an insteadOf rewrite, which only rewrites a URL's prefix.

Server Details

  • Server: git (mcp-server-git, Python)
  • Changes to: git_remote tool output (redaction), redact_url

Motivation and Context

The README promises that "A credential embedded in a URL is never returned", and both cases above broke that promise. This is a sibling of the earlier newline fix (_remote_url_has_newline, commit 20a1775), which is unchanged.

How Has This Been Tested?

  • Regression tests (src/git/tests/test_remote.py), all failing on origin/v2/main and passing here:
    • test_tab_in_remote_name_keeps_the_url_whole (protocol level): a c d remote with a global insteadOf that carries a host token. The URL is redacted and the token is absent.
    • test_url_not_starting_with_its_scheme_is_withheld (protocol level): a leading-space URL is withheld.
    • test_longest_configured_name_is_matched: remotes c and c d together, and a line whose name is not configured.
    • New test_redact_url cases: leading space, a tab-prefixed value, x https://..., and https:: https://....
    • test_unparseable_line_is_withheld was updated to mock both git remote and git remote -v.
  • Advisory PoC (triage repro t_remote.py, real server over an in-memory transport): before, alice:HOSTTOKEN and bob:REPOTOKEN were returned. After, both are <redacted>.
  • Inspector CLI (@modelcontextprotocol/inspector@2.12.0 --cli, git_remote, --repository set, GIT_CONFIG_GLOBAL carrying the insteadOf token), in both eras (--protocol-era legacy and modern):
    • Before (origin/v2/main): c d https://alice:HOSTTOKEN@srv.example.com/org/r.git (fetch) … and lead https://bob:REPOTOKEN@example.com/r.git (fetch) …
    • After: c d https://<redacted>@srv.example.com/org/r.git (fetch) … and lead <redacted> (fetch) …
  • LLM client: not run. This fixer runs non-interactively, and the change is fully exercised by the Inspector CLI in both eras.
  • npm run local:gate: EXIT=0.

Breaking Changes

None. Only values that hold a URL not at their start are now withheld, plus lines that start with no configured remote name. git remote -v never prints such a line for a configured remote.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation (tool results)
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly (git_remote entry)
  • I have tested this with an LLM client (not done: Inspector CLI only, as stated above)
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall cliffhall added the v2 label Nov 27, 2026
@changeset-bot

changeset-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4eacdbb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

git: MCP interface diff

Base: 90e6a48c8c90 (Merge pull request #5652 from modelcontextprotocol/v2/feat/5651-everything-events)
Head: the build in this checkout, at f46c11e2e890 (Merge 4eacdbb into 90e6a48)

Diffed because it was named (--server).

✅ No interface changes detected.

Tools Prompts Resources Resource templates
Base 14 2 0 0
Head 14 2 0 0

Updated by this run for 4eacdbb2b41aeedddc8161318f72613d568f5068.

@cliffhall
cliffhall merged commit 62c6664 into v2/main Nov 27, 2026
47 checks passed
@cliffhall
cliffhall deleted the v2/fix/ghsa-wvv2-676g-r57j branch November 27, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GHSA-wvv2-676g-r57j] - mcp-server-git: git_remote credential redaction bypassed by a tab in a remote name or a prefixed URL

1 participant