Skip to content

Commit dec17ab

Browse files
dschoGit for Windows Build Agent
authored andcommitted
mingw: skip symlink type auto-detection for network share targets
On Windows, symbolic links come in two flavors: file symlinks and directory symlinks. Since Git was born on Linux where this distinction does not exist, Git for Windows has to auto-detect the type by looking at the target. When the target does not yet exist at symlink creation time, Git for Windows creates a "phantom" file symlink and later, once checkout is complete, calls `CreateFileW()` on the target to check whether it is actually a directory. If the symlink target is a UNC path (e.g. `\\attacker\share`), this auto-detection triggers an SMB connection to the remote host. Windows performs NTLM authentication by default for such connections, which means a crafted repository can exfiltrate the cloning user's NTLMv2 hash to an attacker-controlled server without any user interaction beyond `git clone -c core.symlinks=true <url>`. There are ways to specify UNC paths that start with only a single backslash (e.g. `\??\UNC\host\share`); All of them do start like that, though, so let's use that as a tell-tale that we should skip the auto-detection in `process_phantom_symlink()`. The symlink is then left as a file symlink (the `mklink` default), and a warning is emitted suggesting the user set the `symlink` gitattribute to `dir` if a directory symlink is needed. When the attribute is already set, auto-detection is never invoked in the first place, so that code path is unaffected. This is the same class of vulnerability as CVE-2025-66413 (GHSA-hv9c-4jm9-jh3x) and follows the same general mitigation pattern that MinTTY adopted for ANSI escape sequences referencing network share paths (GHSA-jf4m-m6rv-p6c5). Note that there are legitimate paths starting with a single backslash that are _not_ network paths: drive-less absolute paths are interpreted as relative to the current working directory's drive. In practice, these are highly uncommon (and brittle, just one working directory change away from breaking). In any case, the only consequence is now that the symlink type of those has to be specified via Git attributes, is all. Reported-by: Justin Lee <jessdhoctor@gmail.com> Addresses: CVE-2026-32631 Addresses: GHSA-9j5h-h4m7-85hx Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 7c81b18 commit dec17ab

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

compat/mingw.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,29 @@ process_phantom_symlink(const wchar_t *wtarget, const wchar_t *wlink)
351351
wchar_t relative[MAX_PATH];
352352
const wchar_t *rel;
353353

354+
/*
355+
* Do not follow symlinks to network shares, to avoid NTLM credential
356+
* leak from crafted repositories (e.g. \\attacker-server\share).
357+
* Since paths come in all kind of enterprising shapes and forms (in
358+
* addition to the canonical `\\host\share` form, there's also
359+
* `\??\UNC\host\share`, `\GLOBAL??\UNC\host\share` and also
360+
* `\Device\Mup\host\share`, just to name a few), we simply avoid
361+
* following every symlink target that starts with a slash.
362+
*
363+
* This also catches drive-less absolute paths, of course. These are
364+
* uncommon in practice (and also fragile because they are relative to
365+
* the current working directory's drive). The only "harm" this does
366+
* is that it now requires users to specify via the Git attributes if
367+
* they have such an uncommon symbolic link and need it to be a
368+
* directory type link.
369+
*/
370+
if (is_wdir_sep(wtarget[0])) {
371+
warning("created file symlink '%ls' pointing to '%ls';\n"
372+
"set the `symlink` gitattribute to `dir` if a "
373+
"directory symlink is required", wlink, wtarget);
374+
return PHANTOM_SYMLINK_DONE;
375+
}
376+
354377
/* check that wlink is still a file symlink */
355378
if ((GetFileAttributesW(wlink)
356379
& (FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_DIRECTORY))

0 commit comments

Comments
 (0)