{"thread":{"id":"66079","subject":"[PATCH] mingw: skip symlink type auto-detection for network share targets","startedAt":"2026-07-28T11:46:38Z","lastAt":"2026-07-28T22:45:05Z","messageCount":2,"participants":["Johannes Schindelin via GitGitGadget","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"549121","messageId":"pull.2189.git.1785239196007.gitgitgadget@gmail.com","threadId":"66079","inReplyTo":null,"subject":"[PATCH] mingw: skip symlink type auto-detection for network share targets","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-07-28T11:46:35Z","receivedAt":"2026-07-28T11:46:38Z","isPatch":true,"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nOn Windows, symbolic links come in two flavors: file symlinks and\ndirectory symlinks.  Since Git was born on Linux where this distinction\ndoes not exist, Git for Windows has to auto-detect the type by looking\nat the target.  When the target does not yet exist at symlink creation\ntime, Git for Windows creates a \"phantom\" file symlink and later, once\ncheckout is complete, calls `CreateFileW()` on the target to check\nwhether it is actually a directory.\n\nIf the symlink target is a UNC path (e.g. `\\\\attacker\\share`), this\nauto-detection triggers an SMB connection to the remote host.  Windows\nperforms NTLM authentication by default for such connections, which\nmeans a crafted repository can exfiltrate the cloning user's NTLMv2 hash\nto an attacker-controlled server without any user interaction beyond\n`git clone -c core.symlinks=true <url>`.\n\nThere are ways to specify UNC paths that start with only a single\nbackslash (e.g. `\\??\\UNC\\host\\share`); All of them do start like that,\nthough, so let's use that as a tell-tale that we should skip the\nauto-detection in `process_phantom_symlink()`. The symlink is then left\nas a file symlink (the `mklink` default), and a warning is emitted\nsuggesting the user set the `symlink` gitattribute to `dir` if a\ndirectory symlink is needed.  When the attribute is already set,\nauto-detection is never invoked in the first place, so that code path is\nunaffected.\n\nThis is the same class of vulnerability as CVE-2025-66413\n(https://github.com/git-for-windows/git/security/advisories/GHSA-hv9c-4jm9-jh3x)\nand follows the same general mitigation pattern that MinTTY adopted for\nANSI escape sequences referencing network share paths\n(https://github.com/mintty/mintty/security/advisories/GHSA-jf4m-m6rv-p6c5).\n\nNote that there are legitimate paths starting with a single backslash\nthat are _not_ network paths: drive-less absolute paths are interpreted\nas relative to the current working directory's drive. In practice, these\nare highly uncommon (and brittle, just one working directory change away\nfrom breaking). In any case, the only consequence is now that the\nsymlink type of those has to be specified via Git attributes, is all.\n\nReported-by: Justin Lee <jessdhoctor@gmail.com>\nAddresses: CVE-2026-32631\nAssisted-by: Claude Opus 4.6\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    mingw: skip symlink type auto-detection for network share targets\n    \n    This was released as part of Git for Windows v2.53.0(3) already.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2189%2Fdscho%2Fskip-symlink-detection-for-network-shares-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2189/dscho/skip-symlink-detection-for-network-shares-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2189\n\n compat/mingw.c | 23 +++++++++++++++++++++++\n 1 file changed, 23 insertions(+)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 3eca3a7f2e..2b0d162d49 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -352,6 +352,29 @@ process_phantom_symlink(const wchar_t *wtarget, const wchar_t *wlink)\n \twchar_t relative[MAX_PATH];\n \tconst wchar_t *rel;\n \n+\t/*\n+\t * Do not follow symlinks to network shares, to avoid NTLM credential\n+\t * leak from crafted repositories (e.g. \\\\attacker-server\\share).\n+\t * Since paths come in all kind of enterprising shapes and forms (in\n+\t * addition to the canonical `\\\\host\\share` form, there's also\n+\t * `\\??\\UNC\\host\\share`, `\\GLOBAL??\\UNC\\host\\share` and also\n+\t * `\\Device\\Mup\\host\\share`, just to name a few), we simply avoid\n+\t * following every symlink target that starts with a slash.\n+\t *\n+\t * This also catches drive-less absolute paths, of course. These are\n+\t * uncommon in practice (and also fragile because they are relative to\n+\t * the current working directory's drive). The only \"harm\" this does\n+\t * is that it now requires users to specify via the Git attributes if\n+\t * they have such an uncommon symbolic link and need it to be a\n+\t * directory type link.\n+\t */\n+\tif (is_wdir_sep(wtarget[0])) {\n+\t\twarning(\"created file symlink '%ls' pointing to '%ls';\\n\"\n+\t\t\t\"set the `symlink` gitattribute to `dir` if a \"\n+\t\t\t\"directory symlink is required\", wlink, wtarget);\n+\t\treturn PHANTOM_SYMLINK_DONE;\n+\t}\n+\n \t/* check that wlink is still a file symlink */\n \tif ((GetFileAttributesW(wlink)\n \t\t\t& (FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_DIRECTORY))\n\nbase-commit: 13c7afec212fc97ce257d15601659314c6673d6c\n-- \ngitgitgadget\n"},{"id":"549175","messageId":"xmqqcxw6d98x.fsf@gitster.g","threadId":"66079","inReplyTo":"pull.2189.git.1785239196007.gitgitgadget@gmail.com","subject":"Re: [PATCH] mingw: skip symlink type auto-detection for network share targets","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-28T22:45:02Z","receivedAt":"2026-07-28T22:45:05Z","isPatch":true,"body":"\"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> On Windows, symbolic links come in two flavors: file symlinks and\n> directory symlinks.  Since Git was born on Linux where this distinction\n> does not exist, Git for Windows has to auto-detect the type by looking\n> at the target.  When the target does not yet exist at symlink creation\n> time, Git for Windows creates a \"phantom\" file symlink and later, once\n> checkout is complete, calls `CreateFileW()` on the target to check\n> whether it is actually a directory.\n> ...\n> Note that there are legitimate paths starting with a single backslash\n> that are _not_ network paths: drive-less absolute paths are interpreted\n> as relative to the current working directory's drive. In practice, these\n> are highly uncommon (and brittle, just one working directory change away\n> from breaking). In any case, the only consequence is now that the\n> symlink type of those has to be specified via Git attributes, is all.\n\nThanks, will queue.\n"}]}