This project might be open to known security vulnerabilities, which can be prevented by tightening the version range of affected dependencies. Find detailed information at the bottom.

Crate gix

Dependencies

(56 total, 39 outdated, 1 possibly insecure)

CrateRequiredLatestStatus
 async-std^1.12.01.12.0up to date
 document-features^0.2.00.2.8up to date
 gix-actor^0.26.00.31.2out of date
 gix-archive^0.4.00.13.1out of date
 gix-attributes^0.18.00.22.2out of date
 gix-commitgraph^0.20.00.24.2out of date
 gix-config^0.29.00.37.0out of date
 gix-credentials^0.19.00.24.2out of date
 gix-date^0.8.00.8.6up to date
 gix-diff^0.35.00.44.0out of date
 gix-discover^0.24.00.32.0out of date
 gix-features^0.34.00.38.2out of date
 gix-filter^0.4.00.11.2out of date
 gix-fs^0.6.00.11.1out of date
 gix-glob^0.12.00.16.3out of date
 gix-hash^0.13.00.14.2out of date
 gix-hashtable^0.4.00.5.2out of date
 gix-ignore^0.7.00.11.2out of date
 gix-index^0.24.00.33.0out of date
 gix-lock^9.0.014.0.0out of date
 gix-macros^0.1.00.1.5up to date
 gix-mailmap^0.18.00.23.1out of date
 gix-negotiate^0.7.00.13.1out of date
 gix-object^0.36.00.42.2out of date
 gix-odb^0.52.00.61.0out of date
 gix-pack^0.42.00.51.0out of date
 gix-path^0.10.00.10.7up to date
 gix-pathspec^0.2.00.7.5out of date
 gix-prompt^0.7.00.8.5out of date
 gix-protocol^0.39.00.45.1out of date
 gix-ref^0.36.00.44.1out of date
 gix-refspec^0.17.00.23.0out of date
 gix-revision^0.21.00.27.1out of date
 gix-revwalk^0.7.00.13.1out of date
 gix-sec^0.10.00.10.6up to date
 gix-submodule^0.3.00.11.0out of date
 gix-tempfile^9.0.014.0.0out of date
 gix-trace^0.1.30.1.9up to date
 gix-transport ⚠️^0.36.00.42.1out of date
 gix-traverse^0.32.00.39.1out of date
 gix-url^0.23.00.27.3out of date
 gix-utils^0.1.50.1.12up to date
 gix-validate^0.8.00.8.5up to date
 gix-worktree^0.25.00.34.0out of date
 gix-worktree-state^0.2.00.11.0out of date
 gix-worktree-stream^0.4.00.13.0out of date
 once_cell^1.14.01.19.0up to date
 parking_lot^0.12.10.12.3up to date
 prodash^26.228.0.0out of date
 regex^1.6.01.10.5up to date
 reqwest^0.11.130.12.5out of date
 serde^1.0.1141.0.203up to date
 signal-hook^0.3.90.3.17up to date
 smallvec^1.9.01.13.2up to date
 thiserror^1.0.261.0.61up to date
 unicode-normalization^0.1.190.1.23up to date

Dev dependencies

(5 total, 1 outdated)

CrateRequiredLatestStatus
 anyhow^11.0.86up to date
 async-std^1.12.01.12.0up to date
 is_ci^1.1.11.2.0up to date
 serial_test^2.0.03.1.1out of date
 walkdir^2.3.22.5.0up to date

Security Vulnerabilities

gix-transport: gix-transport indirect code execution via malicious username

RUSTSEC-2024-0335

Summary

gix-transport does not check the username part of a URL for text that the external ssh program would interpret as an option. A specially crafted clone URL can smuggle options to SSH. The possibilities are syntactically limited, but if a malicious clone URL is used by an application whose current working directory contains a malicious file, arbitrary code execution occurs.

The first gix crate with the fix is version 0.62.0, and the first fixed gix CLI is version 0.35. gix-transport at version v0.42 is the lowest-level plumbing crate with the fix.

Details

This is related to the patched vulnerability RUSTSEC-2023-0064, but appears less severe due to a greater attack complexity. Since https://github.com/Byron/gitoxide/pull/1032, gix-transport checks the host and path portions of a URL for text that has a - in a position that will cause ssh to interpret part of all of the URL as an option argument. But it does not check the non-mandatory username portion of the URL.

As in Git, when an address is a URL of the form ssh://username@hostname/path, or when it takes the special form username@hostname:dirs/repo, this is treated as an SSH URL. gix-transport will replace some characters in username with their %-based URL encodings, but otherwise passes username@hostname as an argument to the external ssh command. This happens even if username begins with a hyphen. In that case, ssh treats that argument as an option argument, and attempts to interpret and honor it as a sequence of one or more options possibly followed by an operand for the last option.

This is harder to exploit than RUSTSEC-2023-0064, because the possibilities are constrained by:

  • The difficulty of forming an option argument ssh accepts, given that characters such as =, /, and \, are URL-encoded, : is removed, and the argument passed to ssh contains the @ sign and subsequent host identifier, which in an effective attack must be parseable as a suffix of the operand passed to the last option.

    The inability to include a literal = prevents the use of -oNAME=VALUE (e.g., -oProxyCommand=payload). The inability to include a literal / or \ prevents smuggling in a path operand residing outside the current working directory, incuding on Windows. (Although a ~ character may be smuggled in, ssh does not perform its own tilde expansion, so it does not form an absolute path.)

  • The difficulty, or perhaps impossibility, of completing a connection (other than when arbitrary code execution has been achieved). This complicates or altogether prevents the use of options such as -A and -X together with a connection to a real but malicious server. The reason a connection cannot generally be completed when exploiting this vulnerability is that, because the argument gix-transport intends as a URL is treated as an option argument, ssh treats the subsequent non-option argument git-upload-pack as the host instead of the command, but it is not a valid host name.

    Although ssh supports aliases for hosts, even if git-upload-pack could be made an alias, that is made difficult by the URL-encoding transformation.

However, an attacker who is able to cause a specially named ssh configuration file to be placed in the current working directory can smuggle in an -F option referencing the file, and this allows arbitrary command execution.

This scenario is especially plausible because programs that operate on git repositories are often run in untrusted git repositories, sometimes even to operate on another repository. Situations where this is likely, such that an attacker could predict or arrange it, may for some applications include a malicious repository with a malicious submodule configuration.

Other avenues of exploitation exist, but appear to be less severe. For example, the -E option can be smuggled to create or append to a file in the current directory (or its target, if it is a symlink). There may also be other significant ways to exploit this that have not yet been discovered, or that would arise with new options in future versions of ssh.

PoC

To reproduce the known case that facilitates arbitrary code execution, first create a file in the current directory named [email protected], of the form

ProxyCommand payload

where payload is a command with an observable side effect. On Unix-like systems, this could be date | tee vulnerable or an xdg-open, open, or other command command to launch a graphical application. On Windows, this could be the name of a graphical application already in the search path, such as calc.exe.

(Although the syntax permitted in the value of ProxyCommand may vary by platform, this is not limited to running commands in the current directory. That limitation only applies to paths directly smuggled in the username, not to the contents of a separate malicious configuration file. Arbitrary other settings may be specified in [email protected] as well.)

Then run:

gix clone 'ssh://[email protected]/abc'

Or:

gix clone -- '[email protected]:abc/def'

(The -- is required to ensure that gix is really passing the argument as a URL for use in gix-transport, rather than interpreting it as an option itself, which would not necessarily be a vulnerability.)

In either case, the payload specified in [email protected] runs, and its side effect can be observed.

Other cases may likewise be produced, in either of the above two forms of SSH addresses. For example, to create or append to the file [email protected], or to create or append to its target if it is a symlink:

gix clone 'ssh://[email protected]/abc'
gix clone -- '[email protected]:abc/def'

Impact

As in RUSTSEC-2023-0064, this would typically require user interaction to trigger an attempt to clone or otherwise connect using the malicious URL. Furthermore, known means of exploiting this vulnerability to execute arbitrary commands require further preparatory steps to establish a specially named file in the current directory. The impact is therefore expected to be lesser, though it is difficult to predict it with certainty because it is not known exactly what scenarios will arise when using the gix-transport library.

Users who use applications that make use of gix-transport are potentially vulnerable, especially:

  • On repositories with submodules that are automatically added, depending how the application manages submodules.
  • When operating on other repositories from inside an untrusted repository.
  • When reviewing contributions from untrusted developers by checking out a branch from an untrusted fork and performing clones from that location.