# CVE-2023-22742: libgit2 fails to verify SSH keys by default

> libgit2 fails to verify SSH keys by default, allowing man-in-the-middle attacks unless a certificate check callback is explicitly configured.

- **Severity:** Medium 5.3 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 20 Jan 2023
- **Updated:** 10 Mar 2025
- **Also known as:** AZL-13175, DEBIAN-CVE-2023-22742, GHSA-8643-3wh5-rmjq, GHSA-m4ch-rfv5-x5g3, JLSEC-2025-184, OESA-2023-1957, RUSTSEC-2023-0003, SUSE-SU-2023:1570-1, SUSE-SU-2023:1788-1, SUSE-SU-2023:1909-1, UBUNTU-CVE-2023-22742, openSUSE-SU-2024:12632-1

## What is CVE-2023-22742?

CVE-2023-22742 is a medium-severity vulnerability in libgit2, published on 20 Jan 2023. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

libgit2 is a cross-platform, linkable library implementation of Git. When using an SSH remote with the optional libssh2 backend, libgit2 does not perform certificate checking by default. Prior versions of libgit2 require the caller to set the `certificate_check` field of libgit2's `git_remote_callbacks` structure - if a certificate check callback is not set, libgit2 does not perform any certificate checking. This means that by default - without configuring a certificate check callback, clients will not perform validation on the server SSH keys and may be subject to a man-in-the-middle attack. Users are encouraged to upgrade to v1.4.5 or v1.5.1. Users unable to upgrade should ensure that all relevant certificates are manually checked.

Weakness: CWE-347 (Improper Verification of Cryptographic Signature)

## Which versions are affected by CVE-2023-22742?

7 open source packages ship an affected version, including libgit2-sys and git2. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `libgit2-sys` | crates.io | All versions | 0.13.5 |
| `libgit2-sys` | crates.io | All versions | 0.13.5 |
| `libgit2-sys` | crates.io | From 0.0.0-0 | 0.13.5, 0.14.2 |
| `libgit2-sys` | crates.io | From 0.14.0 | 0.14.2 |
| `libgit2-sys` | crates.io | From 0.14.0 | 0.14.2 |
| `git2` | crates.io | All versions | 0.16.1 |
| `git2` | crates.io | All versions | 0.16.1 |
| `libgit2` | SUSE:Linux Enterprise Module for Development Tools 15 SP4 | All versions | 1.3.0-150400.3.6.1 |
| `libgit2` | SUSE:Linux Enterprise Real Time 15 SP3 | All versions | 0.28.4-150200.3.6.1 |
| `libgit2` | SUSE:Manager Server Module 4.2 | All versions | 0.28.4-150200.3.6.1 |
| `libgit2` | SUSE:Manager Server Module 4.3 | All versions | 0.28.4-150200.3.6.1 |
| `libgit2` | openSUSE:Leap 15.4 | All versions | 0.26.8-150000.3.18.1 |
| `libgit2` | openSUSE:Leap 15.4 | All versions | 0.28.4-150200.3.6.1 |
| `libgit2` | openSUSE:Leap 15.4 | All versions | 1.3.0-150400.3.6.1 |
| `libgit2` | openSUSE:Tumbleweed | All versions | 1.5.1-1.1 |

Products: Libgit2 Libgit2.

## How do I fix CVE-2023-22742?

Upgrade libgit2-sys to a fixed version for your release line: 0.13.5 or 0.14.2.

## Is CVE-2023-22742 being exploited?

There is no known exploitation of CVE-2023-22742 in the wild and no public exploit code.

## Other vulnerabilities in libgit2

- [CVE-2024-24577](https://insights.sbomify.com/CVE-2024-24577/): libgit2 is vulnerable to arbitrary code execution due to heap corruption in `git_index_add` (high 8.6)
- [CVE-2024-24575](https://insights.sbomify.com/CVE-2024-24575/): libgit2 is vulnerable to a denial of service attack in `git_revparse_single` (high 7.5)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2023-22742 and fix it if it is affected.

What it is: CVE-2023-22742 is a medium-severity vulnerability in libgit2, published on 20 Jan 2023. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2023-22742 in the wild and no public exploit code.

Affected packages and fixed versions:
- libgit2-sys (crates.io): affected all versions; fixed in 0.13.5
- libgit2-sys (crates.io): affected all versions; fixed in 0.13.5
- libgit2-sys (crates.io): affected from 0.0.0-0; fixed in 0.13.5, 0.14.2
- libgit2-sys (crates.io): affected from 0.14.0; fixed in 0.14.2
- libgit2-sys (crates.io): affected from 0.14.0; fixed in 0.14.2
- git2 (crates.io): affected all versions; fixed in 0.16.1
- git2 (crates.io): affected all versions; fixed in 0.16.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2023-22742/ (Markdown: https://insights.sbomify.com/CVE-2023-22742/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2023-22742
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2023-22742
- OSV: https://osv.dev/vulnerability/CVE-2023-22742

---
From sbomify Insights: https://insights.sbomify.com/CVE-2023-22742/
Summaries are generated and may contain mistakes; the official description above is the record.
