Git 公布多个安全漏洞
今天,Git 项目发布新版本,以修复六个安全漏洞。这些漏洞包括递归克隆恶意仓库时导致的任意代码执行、写入非预期文件,以及处理合并或二进制补丁时的内存损坏。
这些修复包含在 Git 2.56.1 中,并向后移植到 Git 2.55.1、2.54.1、2.53.1、2.52.1、2.51.3 和 2.50.2。我们建议更新到 Git 2.56.1 或你所处维护系列对应的已修补版本,并更新任何捆绑了 Git 的应用程序。
Git 在将文件写入工作区之前会检查路径,包括拒绝那些会覆盖其自身仓库元数据的路径。然而,Git 索引处理中的整数截断可能导致一个极长的路径以某个名称通过校验,随后却用更短的名称被写入。
攻击者可以利用这一差异,将子模块的 .git 文件替换为一个符号链接,指向包含恶意配置或钩子的目录。当 Git 随后使用该目录时,就可能在递归克隆过程中执行攻击者控制的代码。
该修复会在极长的索引条目路径长度被截断之前就将其拒绝。
使用 Git 协议 v2 克隆空仓库时,服务器可以通告一个指向未出生分支(即尚无任何提交的分支)的 HEAD 符号引用。Git 此前在将其存储到本地之前并未验证该符号引用的目标。
恶意服务器可以提供包含路径穿越组件的名称。在使用 files 引用后端时,后续更新该分支的操作可能会写入预期引用目录之外的位置。
Git 现在会在接受通告的目标之前先对其进行验证。该版本还会验证通过协议 v2 接收的其他引用名称和符号引用目标。
在剥离消息中的 GPG 签名时,Git 假定签名最多只有两个。一条经过特殊构造、包含两个以上签名的消息,会导致 Git 写出固定大小栈数组的边界之外。
合并一个包含两个以上签名的标签即可触发该问题,造成内存破坏,并可能导致拒绝服务。代表用户执行此类合并的托管服务同样会受到影响。
修复方案移除了该固定大小数组,改为处理任意数量签名的消息。
Git 会拒绝大于约 1 GiB 的补丁,因为其补丁应用代码无法安全处理更大的输入。但这项检查只考虑了补丁被提供时的大小。
二进制补丁经过压缩和编码,因此一个相对较小的补丁可以膨胀到超出该限制。精心构造的补丁能够绕过输入大小检查,导致越界读取,使 Git 崩溃。
现在 Git 在处理二进制补丁之前,还会检查其声明的未压缩大小。
Git 的合并机制会在写出结果之前,计算合并结果需要多少内存。当结果非常大时,该计算可能溢出,包括在存在大量冲突并叠加较大的 conflict-marker-size 属性时。
溢出会导致 Git 分配的缓冲区过小,随后写出其边界之外,破坏堆内存。这会影响使用 Git 合并不可信内容的应用和托管服务,本地合并同样受影响。
该修复使用与大小相匹配的类型和带检查的算术运算,拒绝那些输出大小无法安全表示的合并。
git fast-import 读取命令流来构建仓库。某些命令可以访问仓库之外的文件,因此当这些命令出现在不可信的输入流中时,Git 已经对它们加以限制。
另有三个功能缺少这种保护。rewrite-submodules-from 和 rewrite-submodules-to 功能可以读取任意文件,可能通过错误信息泄露其内容。export-pack-edges 选项可以创建文件或向现有文件追加数据。
现在,除非调用方显式启用 --allow-unsafe-features,否则通过输入流提供这些功能时会被拒绝。只有当你信任生成该流的程序时,才应启用该选项。
除这些修复之外,该版本还在检出和树处理期间为相关的索引条目分配增加了溢出检查。这些检查与上述路径长度限制相互补充,防止在 Git 将路径复制到内存之前,分配大小被截断或发生溢出。
更新是防范这些漏洞最有效的方式。请从你的操作系统或 Git 发行方安装已修补的版本,并更新那些自带 Git 副本的应用程序。管理员还应更新自动化程序以及代表用户处理仓库的服务所使用的 Git 安装。
如果你无法立即更新,请仅从可信服务器克隆,并避免递归克隆不可信的仓库。避免合并不可信的内容或标签,也不要处理来自不可信来源的二进制补丁或 fast-import 流。这些预防措施不能替代安装修复程序。
获取更新版本的 Git >
《Git 安全漏洞公布》一文最先发布于 The GitHub Blog。
译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。
查看英文原文(Git security vulnerabilities announced)
Today, the Git project is releasing new versions to address six security vulnerabilities. These include arbitrary code execution when recursively cloning a malicious repository, writes to unintended files, and memory corruption when processing merges or binary patches.
The fixes are included in Git 2.56.1, with backports to Git 2.55.1, 2.54.1, 2.53.1, 2.52.1, 2.51.3, and 2.50.2. We recommend updating to Git 2.56.1 or the patched release for your maintenance series, and updating any applications that bundle Git.
Vulnerabilities in Git
CVE-2026-111760: Code execution during recursive clones
Git checks paths before writing files into a working tree, including rejecting paths that would overwrite its own repository metadata. However, an integer truncation in Git’s index handling can cause an extremely long path to pass validation under one name and then be written using a shorter name.
An attacker can use this discrepancy to replace a submodule’s .git file with a symbolic link pointing to a directory containing malicious configuration or hooks. When Git subsequently uses that directory, it can execute attacker-controlled code during a recursive clone.
The fix rejects extremely long index entry paths before their lengths can be truncated.
[Advisory]
CVE-2026-113408: Path traversal through a server’s advertised HEAD
When cloning an empty repository using Git protocol v2, the server can advertise a HEAD symref pointing to an unborn branch (one that has no commits yet). Git did not validate the symref’s target before storing it locally.
A malicious server can supply a name containing path-traversal components. With the files reference backend, a later operation that updates the branch can write outside the intended reference directory.
Git now validates the advertised target before accepting it. The release also validates other reference names and symbolic-reference targets received through protocol v2.
[Advisory]
CVE-2026-114467: Stack corruption when removing signatures
When stripping GPG signatures from a message, Git assumed there would be at most two signatures. A specially crafted message containing more than two signatures can cause Git to write past the end of a fixed-size stack array.
This can be triggered by merging a tag containing more than two signatures, causing memory corruption and a potential denial of service. Hosting services that perform these merges on behalf of users can also be affected.
The fix removes the fixed-size array and handles messages with any number of signatures.
[Advisory]
CVE-2026-114469: Out-of-bounds reads when applying binary patches
Git rejects patches larger than approximately 1 GiB because its patch application code cannot safely handle larger inputs. However, this check only considered the size of the patch as supplied.
Binary patches are compressed and encoded, so a relatively small patch can expand beyond that limit. A crafted patch can bypass the input-size check and cause an out-of-bounds read, crashing Git.
Git now also checks the declared uncompressed size before processing a binary patch.
[Advisory]
CVE-2026-105437: Heap corruption during large merges
Git’s merge machinery calculates how much memory it needs for a merge result before writing the output. That calculation can overflow when the result is very large, including when many conflicts are combined with a large conflict-marker-size attribute.
The overflow can cause Git to allocate a buffer that is too small, then write outside it, corrupting heap memory. This affects applications and hosting services that use Git to merge untrusted content, as well as local merges.
The fix uses size-appropriate types and checked arithmetic, rejecting merges whose output size cannot be represented safely.
[Advisory]
CVE-2026-114466: Filesystem access through fast-import streams
git fast-import reads a stream of commands to build a repository. Some commands can access files outside the repository, so Git already restricts them when they appear in an untrusted input stream.
Three additional features lacked that protection. The rewrite-submodules-from and rewrite-submodules-to features can read arbitrary files, potentially exposing their contents through error messages. The export-pack-edges option can create files or append data to existing files.
These features are now rejected when supplied through the input stream unless the caller explicitly enables --allow-unsafe-features. Only enable that option when you trust the program generating the stream.
[Advisory]
Additional hardening
Alongside these fixes, the release adds overflow checks to related index entry allocations during checkout and tree processing. These checks complement the path-length limits above, preventing allocation sizes from being truncated or overflowing before Git copies a path into memory.
Protecting GitHub users
- We have deployed fixes for these vulnerabilities across github.com, GitHub Enterprise Cloud, and GitHub Enterprise Cloud with data residency.
- Updates for GitHub Enterprise Server are available in versions 3.19.15, 3.20.11, 3.21.9, and 3.22.4. We recommend that administrators upgrade as soon as possible.
- We are coordinating releases of GitHub Desktop and the GitHub Copilot app that include patched versions of Git.
- GitHub Codespaces and GitHub Actions will also receive patched versions of Git.
Update Git
Updating is the most effective way to protect against these vulnerabilities. Install a patched version from your operating system or Git distributor, and update applications that include their own copy of Git. Administrators should also update Git installations used by automation and services that process repositories on behalf of users.
If you cannot update immediately, clone only from trusted servers and avoid recursive clones of untrusted repositories. Avoid merging untrusted content or tags, or processing binary patches or fast-import streams from untrusted sources. These precautions do not replace installing the fixes.
The post Git security vulnerabilities announced appeared first on The GitHub Blog.
正文保留英文原文,标题与摘要由机器翻译。
原文发布于 GitHub Blog(Git security vulnerabilities announced),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。