{"ecosystem":"cargo","package":"sqlx","version":null,"bugs":[{"id":946,"ecosystem":"cargo","package_name":"sqlx","affected_version":"0.0.0-0","fixed_version":"0.8.1","bug_id":"osv:RUSTSEC-2024-0363","title":"Binary Protocol Misinterpretation caused by Truncating or Overflowing Casts","description":"The following presentation at this year's DEF CON was brought to our attention on the SQLx Discord:\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.)\n\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 SQLx _does_ perform truncating casts in a way that could be problematic, \nfor example: <https://github.com/launchbadge/sqlx/blob/6f2905695b9606b5f51b40ce10af63ac9e696bb8/sqlx-postgres/src/arguments.rs#L163>\n\nThis code has existed essentially since the beginning, \nso it is reasonable to assume that all published versions `<= 0.8.0` are affected.\n\n## Mitigation\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\n[`Encode::size_hint()`](https://docs.rs/sqlx/latest/sqlx/trait.Encode.html#method.size_hint) \ncan be used for sanity checks, but do not assume that the size returned is accurate. \nFor example, the `Json<T>` and `Text<T>` adapters have no reasonable way to predict or estimate the final encoded size, \nso they just return `size_of::<T>()` instead.\n\nFor web application backends, consider adding some middleware that limits the size of request bodies by default.\n\n## Resolution\n\n`sqlx 0.8.1` has been released with the fix: <https://github.com/launchbadge/sqlx/blob/main/CHANGELOG.md#081---2024-08-23>\n\nPostgres users are advised to upgrade ASAP as a possible exploit has been demonstrated:\n<https://github.com/launchbadge/sqlx/issues/3440#issuecomment-2307956901>\n\nMySQL and SQLite do not _appear_ to be exploitable, but upgrading is recommended nonetheless.","severity":"medium","status":"fixed","source":"osv","source_url":"https://crates.io/crates/sqlx","labels":["GHSA-xmrp-424f-vfpx"],"created_at":"2026-04-19 04:32:20.180300+00:00","updated_at":"2026-04-19 04:32:20.180300+00:00"},{"id":945,"ecosystem":"cargo","package_name":"sqlx","affected_version":null,"fixed_version":"0.8.1","bug_id":"osv:GHSA-xmrp-424f-vfpx","title":"SQLx Binary Protocol Misinterpretation caused by Truncating or Overflowing Casts","description":"The following presentation at this year's DEF CON was brought to our attention on the SQLx Discord:\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.)\n\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 SQLx _does_ perform truncating casts in a way that could be problematic, \nfor example: <https://github.com/launchbadge/sqlx/blob/6f2905695b9606b5f51b40ce10af63ac9e696bb8/sqlx-postgres/src/arguments.rs#L163>\n\nThis code has existed essentially since the beginning, \nso it is reasonable to assume that all published versions `<= 0.8.0` are affected.\n\n## Mitigation\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\n[`Encode::size_hint()`](https://docs.rs/sqlx/latest/sqlx/trait.Encode.html#method.size_hint) \ncan be used for sanity checks, but do not assume that the size returned is accurate. \nFor example, the `Json<T>` and `Text<T>` adapters have no reasonable way to predict or estimate the final encoded size, \nso they just return `size_of::<T>()` instead.\n\nFor web application backends, consider adding some middleware that limits the size of request bodies by default.\n\n## Resolution\n\nWork has started on a branch to add `#[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\nand to manually audit the code that they flag.\n\nA fix is expected to be included in the `0.8.1` release (still WIP as of writing).\n","severity":"medium","status":"fixed","source":"osv","source_url":"https://github.com/launchbadge/sqlx/issues/3440","labels":["RUSTSEC-2024-0363"],"created_at":"2026-04-19 04:32:20.179076+00:00","updated_at":"2026-04-19 04:32:20.179076+00:00"}],"total":2,"_cache":"hit"}