Vulnerability HighRUSTSEC-2024-0365 · diesel
RUSTSEC-2024-0365: Binary Protocol Misinterpretation caused by Truncating or Overflowing Casts
Short answerA security vulnerability in the diesel crate: Binary Protocol Misinterpretation caused by Truncating or Overflowing Casts. GitHub rates it High. Fixed in 2.2.3: update to a fixed version.
| Crate | diesel |
|---|---|
| Type | Vulnerability (format-injection) |
| Affected versions | Before 2.2.3. |
| Fixed in | 2.2.3 |
| Severity | High (GitHub rating) |
| Published | 2024-08-23 |
| Last changed | 2025-10-28 |
| Also known as | GHSA-wq9x-qwcq-mmgf |
What to do
- See which version you have:
cargo tree -i diesel(it also shows which of your dependencies pulls it in). - Update within your version requirement:
cargo update -p diesel. If the fix is a newer major or minor than your requirement allows, raise it in Cargo.toml (for examplediesel = "2.2.3") or update the dependency that pulls it in. - Check again with
cargo audit, or paste your Cargo.lock into our Cargo.toml checker.
Details from the advisory
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:
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.
References
- Package: crates.io/crates/diesel
- Advisory: rustsec.org/advisories/RUSTSEC-2024-0365.html
- Web: github.com/diesel-rs/diesel/pull/4170
From the RustSec Advisory Database (CC0-1.0) via the OSV export, downloaded Oct 24, 2026. Severity score computed from the published CVSS vector.
Other advisories for diesel
- Vulnerability CriticalRUSTSEC-2021-0037 · 2021-03-05Fix a use-after-free bug in diesels Sqlite backend
- UnsoundRUSTSEC-2026-0111 · 2026-04-24Possible UTF-8 corruption in Diesels SQLite backend
- UnsoundRUSTSEC-2026-0134 · 2026-04-24Unsound access to padding bytes while serializing date/time values using the Mysql backend
- UnsoundRUSTSEC-2026-0135 · 2026-04-24Unsound transmute while debug/display printing batch Insert statements in Diesel's SQLite backend
- VulnerabilityRUSTSEC-2026-0136 · 2026-04-24Command injection in Diesel's implementation of `COPY FROM`/`COPY TO`
- VulnerabilityRUSTSEC-2026-0137 · 2026-04-24Possible unaligned data access for implementations of `SqliteAggregate`
- UnsoundRUSTSEC-2026-0172 · 2026-06-05Possible use after free when deserializing a SQLite database via `SqliteConnection::deserialize_readonly_database`
Up next
Same cratediesel: security historyEvery advisory for this crate, and whether it is safe to use today.Read it next →Did this answer your question?