# CVE-2024-39677: NHibernate SQL injection vulnerability in discriminator mappings, static fields referenced in HQL, and some utilities

> Attackers can execute arbitrary SQL commands via NHibernate discriminator mappings, HQL static fields, or SQL builder utilities, compromising database integrity.

- **Severity:** Medium 5.9 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:N/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:** Not needed
- **Fix available:** Yes
- **Published:** 8 Jul 2024
- **Updated:** 2 Aug 2024
- **Also known as:** GHSA-fg4q-ccq8-3r5q

## What is CVE-2024-39677?

CVE-2024-39677 is a medium-severity SQL injection vulnerability in nhibernate-core, published on 8 Jul 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

NHibernate is an object-relational mapper for the .NET framework. A SQL injection vulnerability exists in some types implementing ILiteralType.ObjectToSQLString. Callers of these methods are exposed to the vulnerability, which includes mappings using inheritance with discriminator values; HQL queries referencing a static field of the application; users of the SqlInsertBuilder and SqlUpdateBuilder utilities, calling their AddColumn overload taking a literal value; and any direct use of the ObjectToSQLString methods for building SQL queries on the user side. This vulnerability is fixed in 5.4.9 and 5.5.2.

Weakness: CWE-89 (Improper Neutralization of Special Elements used in an SQL Command)

## Which versions are affected by CVE-2024-39677?

4 open source packages ship an affected version, including NHibernate. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `NHibernate` | NuGet | All versions | 5.4.9 |
| `NHibernate` | NuGet | All versions | 5.4.9 |
| `NHibernate` | NuGet | From 5.5.0 | 5.5.2 |
| `NHibernate` | NuGet | From 5.5.0 | 5.5.2 |

Products: Nhibernate Nhibernate-Core.

## How do I fix CVE-2024-39677?

Upgrade NHibernate to a fixed version for your release line: 5.4.9 or 5.5.2.

## Is CVE-2024-39677 being exploited?

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

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-39677 and fix it if it is affected.

What it is: CVE-2024-39677 is a medium-severity SQL injection vulnerability in nhibernate-core, published on 8 Jul 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2024-39677 in the wild and no public exploit code.

Affected packages and fixed versions:
- NHibernate (NuGet): affected all versions; fixed in 5.4.9
- NHibernate (NuGet): affected all versions; fixed in 5.4.9
- NHibernate (NuGet): affected from 5.5.0; fixed in 5.5.2
- NHibernate (NuGet): affected from 5.5.0; fixed in 5.5.2

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-2024-39677/ (Markdown: https://insights.sbomify.com/CVE-2024-39677/index.md)
```

## Sources

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

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