GHSA-wq9x-qwcq-mmgf: Diesel Diesel Vulnerable To Binary Protocol Vulnerability

HIGH
CVSS 8.1
CWE-89
Published
Advisory Summary

GHSA-wq9x-qwcq-mmgf is a HIGH (CVSS 8.1) diesel vulnerable to binary protocol vulnerability (CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')) affecting Diesel libraries in the crates.io ecosystem. The issue involves diesel vulnerable to binary protocol misinterpretation caused by truncating or overflowing casts. Remediation is available by upgrading affected packages to version 2.2.3.

GHSA-wq9x-qwcq-mmgf at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-wq9x-qwcq-mmgf
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Affected Product Diesel
Package Ecosystem crates.io
Published Date
Last Updated

Security Impact

CVSS: 8.1

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:H/I:H/A:H).

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 High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix GHSA-wq9x-qwcq-mmgf

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

diesel fixed: 2.2.3
Upgrade diesel to 2.2.3
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 diesel

How to Check if You Are Affected

To determine whether your application is affected by GHSA-wq9x-qwcq-mmgf, inspect your project dependencies for Diesel:

inspect dependencies for diesel

Analyze the terminal output to locate any version of Diesel in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.2.3), 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 Diesel, 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

The following presentation at this year's DEF CON was brought to our attention on the Diesel Gitter Channel: > SQL Injection isn't Dead: Smuggling Queries at the Protocol Level > <http://web.archive.org/web/20240812130923/https://media.defcon.org/DEF%20CON%2032/DEF%20CON%2032%20presentations/DEF%20CON%2032%20-%20Paul%20Gerste%20-%20SQL%20Injection%20Isn't%20Dead%20Smuggling%20Queries%20at%20the%20Protocol%20Level.pdf> > (Archive link for posterity.) Essentially, encoding a value larger than 4GiB can cause the length prefix in the protocol to overflow, causing the server to interpret the rest of the string as binary protocol commands or other data. It appears Diesel _does_ perform truncating casts in a way that could be problematic, for example: <https://github.com/diesel-rs/diesel/blob/ae82c4a5a133db65612b7436356f549bfecda1c7/diesel/src/pg/connection/stmt/mod.rs#L36> This code has existed essentially since the beginning, so it is reasonable to assume that all published versions `<= 2.2.2` are affected. ## Mitigation The prefered migration to the outlined problem is to update to a Diesel version newer than 2.2.2, which includes fixes for the problem. As always, you should make sure your application is validating untrustworthy user input. Reject any input over 4 GiB, or any input that could _encode_ to a string longer than 4 GiB. Dynamically built queries are also potentially problematic if it pushes the message size over this 4 GiB bound. For web application backends, consider adding some middleware that limits the size of request bodies by default. ## Resolution Diesel now uses `#[deny]` directives for the following Clippy lints: * [`cast_possible_truncation`](https://rust-lang.github.io/rust-clippy/master/#/cast_possible_truncation) * [`cast_possible_wrap`](https://rust-lang.github.io/rust-clippy/master/#/cast_possible_wrap) * [`cast_sign_loss`](https://rust-lang.github.io/rust-clippy/master/#/cast_sign_loss) to prevent casts that will lead to precision loss or other trunctations. Additionally we performed an audit of the relevant code. A fix is included in the `2.2.3` release.

GHSA-wq9x-qwcq-mmgf Affected Diesel Versions

1 component(s)
Fixed Versions:
2.2.3
Product / Package Ecosystem Affected Versions Fixed Version
diesel
crates.io
< 2.2.3
2.2.3

References

Frequently Asked Questions

What is GHSA-wq9x-qwcq-mmgf?
GHSA-wq9x-qwcq-mmgf is a security vulnerability in Diesel involving Diesel vulnerable to Binary Protocol Misinterpretation caused by Truncating or Overflowing Casts under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Which Diesel versions are affected?
Affected versions include releases prior to 2.2.3 across affected packages: diesel.
What version fixes GHSA-wq9x-qwcq-mmgf?
Upgrading to 2.2.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is diesel affected?
Yes, diesel is affected in releases prior to 2.2.3. Upgrade your dependency to 2.2.3 or later.
What is the CVSS score of GHSA-wq9x-qwcq-mmgf?
GHSA-wq9x-qwcq-mmgf has a CVSS v3.1 base score of 8.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with GHSA-wq9x-qwcq-mmgf?
GHSA-wq9x-qwcq-mmgf 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 crates.io dependencies for GHSA-wq9x-qwcq-mmgf?
Run the dependency tree command: 'inspect dependencies for diesel'. 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-wq9x-qwcq-mmgf",
  "modified" : "2024-08-23T18:51:20Z",
  "published" : "2024-08-23T18:51:20Z",
  "aliases" : [ ],
  "summary" : "Diesel vulnerable to Binary Protocol Misinterpretation caused by Truncating or Overflowing Casts",
  "details" : "The following presentation at this year's DEF CON was brought to our attention on the Diesel Gitter Channel:\n\n> SQL Injection isn't Dead: Smuggling Queries at the Protocol Level  \n> <http://web.archive.org/web/20240812130923/https://media.defcon.org/DEF%20CON%2032/DEF%20CON%2032%20presentations/DEF%20CON%2032%20-%20Paul%20Gerste%20-%20SQL%20Injection%20Isn't%20Dead%20Smuggling%20Queries%20at%20the%20Protocol%20Level.pdf>  \n> (Archive link for posterity.)\nEssentially, encoding a value larger than 4GiB can cause the length prefix in the protocol to overflow, \ncausing the server to interpret the rest of the string as binary protocol commands or other data.\n\nIt appears Diesel _does_ perform truncating casts in a way that could be problematic, \nfor example: <https://github.com/diesel-rs/diesel/blob/ae82c4a5a133db65612b7436356f549bfecda1c7/diesel/src/pg/connection/stmt/mod.rs#L36>\n\nThis code has existed essentially since the beginning, \nso it is reasonable to assume that all published versions `<= 2.2.2` are affected.\n\n## Mitigation\n\nThe prefered migration to the outlined problem is to update to a Diesel version newer than 2.2.2, which includes \nfixes for the problem. \n\nAs always, you should make sure your application is validating untrustworthy user input. \nReject any input over 4 GiB, or any input that could _encode_ to a string longer than 4 GiB. \nDynamically built queries are also potentially problematic if it pushes the message size over this 4 GiB bound.\n\nFor web application backends, consider adding some middleware that limits the size of request bodies by default.\n\n## Resolution\n\nDiesel now uses `#[deny]` directives for the following Clippy lints:\n\n* [`cast_possible_truncation`](https://rust-lang.github.io/rust-clippy/master/#/cast_possible_truncation)\n* [`cast_possible_wrap`](https://rust-lang.github.io/rust-clippy/master/#/cast_possible_wrap)\n* [`cast_sign_loss`](https://rust-lang.github.io/rust-clippy/master/#/cast_sign_loss)\n\nto prevent casts that will lead to precision loss or other trunctations. Additionally we performed an \naudit of the relevant code.\n\nA fix is included in the `2.2.3` release.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:P"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "diesel"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.2.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/diesel-rs/diesel/pull/4170"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/diesel-rs/diesel/commit/9eccd7d6d705ac53618bfd478152e32ec3b4536c"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/diesel-rs/diesel"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/diesel-rs/diesel/blob/ae82c4a5a133db65612b7436356f549bfecda1c7/diesel/src/pg/connection/stmt/mod.rs#L36"
  }, {
    "type" : "WEB",
    "url" : "https://rustsec.org/advisories/RUSTSEC-2024-0365.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-89" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-08-23T18:51:20Z",
    "nvd_published_at" : null
  }
}