During checkout, gitoxide does not verify that paths point to locations in the working tree. A specially crafted repository can, when cloned, place new files anywhere writable by the application.
Although gix-worktree-state checks for collisions with existing files, it does not itself check if a path is really in the working tree when performing a checkout, nor do the path checks in gix-fs and gix-worktree prevent this. Cloning an untrusted repository containing specially crafted tree or blob names will create new files outside the repository, or inside the repository or a submodule's .git directory. The simplest cases are:
.. to traverse upward. This facilitates arbitrary code execution because files can be placed in one or more locations where they are likely to be executed soon..git to enter a .git directory. This facilitates arbitrary code execution because hooks can be installed.A number of alternatives that achieve the same effect are also possible, some of which correspond to specific vulnerabilities that have affected Git in the past:
/, to traverse upward or downward. For example, even without containing any tree named .. or .git, a repository can represent a file named ../outside or .git/hooks/pre-commit. This is distinct from the more intuitive case a repository containing trees that represent those paths.\, to traverse upward or downward. (Unlike /, these are valid on other systems.) See GHSA-xjx4-8694-q2fq..git..git or a case variant, with characters added that HFS+ ignores in collation. See https://github.com/git/git/commit/6162a1d323d24fd8cbbb1a6145a91fb849b2568f..git (or a case variant) by the use of NTFS stream notation, such as .git::$INDEX_ALLOCATION. See GHSA-5wph-8frv-58vj.git~1 (or a case variant). See GHSA-589j-mmg9-733v.When a checkout creates some files outside the repository directory but fails to complete, the repository directory is usually removed, but the outside files remain.
For simplicity, these examples stage a stand-in file with a valid name, modify the index, and commit. The instructions assume sed supports -i, which is the case on most systems. If using Windows, a Git Bash shell should be used.
git init dangerous-repo-installs-hook and cd into the directory..git@hooks@pre-commit, with the contents:
#!/bin/sh
printf 'Vulnerable!\n'
date >vulnerable
git add --chmod=+x .git@hooks@pre-commitenv LC_ALL=C sed -i.orig 's|\.git@hooks@pre-commit|.git/hooks/pre-commit|' .git/indexgit commit -m 'Initial commit'Then, on another or the same machine:
gix clone … command.ls -l .git/hooks to observe that the pre-commit hook is already present.git. This causes the payload surreptitiously installed as a pre-commit hook to run, printing the message Vulnerable! and creating a file in the current directory containing the current date and time.Note that the effect is not limited to modifying the current directory. The payload could be written to perform any action that the user who runs git commit is capable of.
git init dangerous-repo-reaches-up, and cd into the directory.echo 'A file outside the working tree, somehow.' >..@outsidegit add ..@outsideenv LC_ALL=C sed -i.orig 's|\.\.@outside|../outside|' .git/indexgit commit -m 'Initial commit'Then, as above, on the same or another machine, clone the repository with a gix clone … command. Observe that a file named outside is present alongside (not inside) the cloned directory.
Any use of gix or another application that makes use of gix-worktree-state, or otherwise relies on gix-fs and gix-worktree for validation, is affected, if used to clone untrusted repositories. The above description focuses on code execution, as that leads to a complete loss of confidentiality, integrity, and availability, but creating files outside a working tree without attempting to execute code can directly impact integrity as well.
In use cases where no untrusted repository is ever cloned, this vulnerability has no impact. Furthermore, the impact of this vulnerability may be lower when gix is used to clone a repository for CI/CD purposes, even if untrusted, since in such uses the environment is usually isolated and arbitrary code is usually run deliberately from the repository with necessary safeguards in place.
{
"nvd_published_at": "2024-05-23T09:15:09Z",
"severity": "HIGH",
"github_reviewed": true,
"cwe_ids": [
"CWE-22",
"CWE-23"
],
"github_reviewed_at": "2024-05-22T14:05:58Z"
}