Vulnerabilities in pkg:nuget/NHibernate

PACKAGE
Advisory Identifier: GHSA-fg4q-ccq8-3r5q
Advisory Summary

CVE-2024-39677 is a HIGH (CVSS 5.9) sql injection vulnerability (CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')) affecting NHibernate libraries in the NuGet ecosystem. The issue involves nhibernate sql injection vulnerability in discriminator mappings, static fields referenced in hql, and some utilities. Remediation is available by upgrading affected packages to version 5.4.9, 5.5.2.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:nuget/NHibernate

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:nuget/NHibernate. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-fg4q-ccq8-3r5q CVE-2024-39677 HIGH NHibernate SQL injection vulnerability in discriminator mappings, static fields referenced in HQL, and some utilities

CVE-2024-39677 at a Glance

CVE Identifier CVE-2024-39677
GHSA Identifier GHSA-fg4q-ccq8-3r5q
Severity HIGH
CVSS v3.1 Base Score 5.9
CWE Classification CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Affected Product NHibernate
Package Ecosystem NuGet
Published Date
Last Updated

Security Impact

CVSS: 5.9

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2024-39677

To remediate this vulnerability, upgrade all affected NHibernate dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

NHibernate fixed: 5.4.9
Upgrade NHibernate to 5.4.9
NHibernate fixed: 5.5.2
Upgrade NHibernate to 5.5.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for NHibernate

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-39677, inspect your project dependencies for NHibernate:

inspect dependencies for NHibernate

Analyze the terminal output to locate any version of NHibernate in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 5.4.9), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the product constructs all or part of an sql command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended sql command when it is sent to a downstream component. without sufficient removal or quoting of sql syntax in user-controllable inputs, the generated sql query can cause those inputs to be interpreted as sql instead of ordinary user data. In NHibernate, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact 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: - The discriminator value could be written in the mapping in a way exploiting the vulnerability of the associated discriminator type, if that type is among the vulnerable ones. - The current culture settings for formatting the discriminator value type could be altered in a way resulting into SQL injections with the 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. These overloads are unused by NHibernate but could be used by users referencing directly these utilities. - Any direct use of the `ObjectToSQLString` methods for building SQL queries on the user side. ### Patches Releases 5.4.9 and 5.5.2. ### Workarounds - Ensure the application does not use the features listed above. - For discriminator usages, ensure the discriminator values in the mappings do not contain quotes for string discriminators. Furthermore, for types which `ToString` conversion can be altered to include SQL injections through adequate hacking of the current culture settings, either change for another type, or ensure the used values cannot allow culture exploits, or ensure the application performs sanity checks of the current culture settings. Types sensitive to culture include integers for negative values, dates, times and datetimes, floats and decimals. ### References - https://github.com/nhibernate/nhibernate-core/issues/3516 - https://github.com/nhibernate/nhibernate-core/pull/3517 - https://github.com/nhibernate/nhibernate-core/pull/3547

CVE-2024-39677 Affected NHibernate Versions

2 component(s)
Fixed Versions:
5.4.95.5.2
Product / Package Ecosystem Affected Versions Fixed Version
NHibernate
NuGet
< 5.4.9
5.4.9
NHibernate
NuGet
≥ 5.5.0
< 5.5.2
5.5.2

References

Frequently Asked Questions

What is CVE-2024-39677?
CVE-2024-39677 is a security vulnerability in NHibernate involving NHibernate SQL injection vulnerability in discriminator mappings, static fields referenced in HQL, and some utilities under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Which NHibernate versions are affected?
Affected versions include releases prior to 5.4.9, 5.5.2 across affected packages: NHibernate.
What version fixes CVE-2024-39677?
Upgrading to 5.4.9, 5.5.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is NHibernate affected?
Yes, NHibernate is affected in releases prior to 5.4.9, 5.5.2. Upgrade your dependency to 5.4.9, 5.5.2 or later.
What is the CVSS score of CVE-2024-39677?
CVE-2024-39677 has a CVSS v3.1 base score of 5.9 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2024-39677?
CVE-2024-39677 is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.).
How can I check NuGet dependencies for CVE-2024-39677?
Run the dependency tree command: 'inspect dependencies for NHibernate'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-fg4q-ccq8-3r5q",
  "modified" : "2024-11-18T16:26:49Z",
  "published" : "2024-07-08T14:20:33Z",
  "aliases" : [ "CVE-2024-39677" ],
  "summary" : "NHibernate SQL injection vulnerability in discriminator mappings, static fields referenced in HQL, and some utilities",
  "details" : "### Impact\nA SQL injection vulnerability exists in some types implementing `ILiteralType.ObjectToSQLString`. Callers of these methods are exposed to the vulnerability, which includes:\n - Mappings using inheritance with discriminator values:\n   - The discriminator value could be written in the mapping in a way exploiting the vulnerability of the associated discriminator type, if that type is among the vulnerable ones.\n   - The current culture settings for formatting the discriminator value type could be altered in a way resulting into SQL injections with the discriminator values.\n - HQL queries referencing a static field of the application.\n - Users of the `SqlInsertBuilder` and `SqlUpdateBuilder` utilities, calling their `AddColumn` overload taking a literal value. These overloads are unused by NHibernate but could be used by users referencing directly these utilities.\n - Any direct use of the `ObjectToSQLString` methods for building SQL queries on the user side.\n\n### Patches\nReleases 5.4.9 and 5.5.2.\n\n### Workarounds\n - Ensure the application does not use the features listed above.\n - For discriminator usages, ensure the discriminator values in the mappings do not contain quotes for string discriminators. Furthermore, for types which `ToString` conversion can be altered to include SQL injections through adequate hacking of the current culture settings, either change for another type, or ensure the used values cannot allow culture exploits, or ensure the application performs sanity checks of the current culture settings. Types sensitive to culture include integers for negative values, dates, times and datetimes, floats and decimals.\n\n### References\n - https://github.com/nhibernate/nhibernate-core/issues/3516\n - https://github.com/nhibernate/nhibernate-core/pull/3517\n - https://github.com/nhibernate/nhibernate-core/pull/3547 ",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "NuGet",
      "name" : "NHibernate"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "5.4.9"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "NuGet",
      "name" : "NHibernate"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "5.5.0"
      }, {
        "fixed" : "5.5.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/nhibernate/nhibernate-core/security/advisories/GHSA-fg4q-ccq8-3r5q"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-39677"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nhibernate/nhibernate-core/issues/3516"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nhibernate/nhibernate-core/pull/3517"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nhibernate/nhibernate-core/pull/3547"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nhibernate/nhibernate-core/commit/b4a69d1a5ff5744312478d70308329af496e4ba9"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/nhibernate/nhibernate-core"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-89" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-07-08T14:20:33Z",
    "nvd_published_at" : "2024-07-08T15:15:22Z"
  }
}