Skip to content

Conversation

@abonander
Copy link
Collaborator

@abonander abonander commented Aug 15, 2024

Fixes #3440

Resolves https://rustsec.org/advisories/RUSTSEC-2024-0363.html

The last three commits may be cherry-picked against 6f29056 to see the exploit in action.

As of writing, only the Postgres driver actually appears to be exploitable before this patch, and appears to no longer be exploitable afterwards.

@FSMaxB
Copy link
Contributor

FSMaxB commented Aug 15, 2024

I know this might be undesirable because it costs performance, but the pattern that I usually follow for these kinds of casts is SmallerIntegerType::try_from(bigger_integer_value).unwrap_or_else(|| unreachable!("Can't fail because <insert reason>"))

@abonander
Copy link
Collaborator Author

For the most part, I'm trying to avoid panics because they've caused issues before. Trying to encode too large of a value is generally a recoverable error.

@abonander abonander force-pushed the validate-casts-dev branch 2 times, most recently from 36b57e5 to ac0448c Compare August 16, 2024 23:37
@abonander abonander changed the title WIP: validate for overflowing and truncating casts WIP: audit protocol handling Aug 17, 2024
@abonander abonander force-pushed the validate-casts-dev branch 2 times, most recently from ef70eae to e9ffde4 Compare August 20, 2024 10:10
@abonander abonander marked this pull request as ready for review August 23, 2024 03:00
@abonander abonander changed the title WIP: audit protocol handling fix: audit protocol handling Aug 23, 2024
@abonander abonander force-pushed the validate-casts-dev branch 2 times, most recently from 2d39649 to 612a767 Compare August 24, 2024 03:08
@abonander abonander force-pushed the validate-casts-dev branch 2 times, most recently from f020d88 to 13594ad Compare August 24, 2024 05:54
@abonander abonander merged commit 0aa0676 into main Aug 24, 2024
@abonander abonander deleted the validate-casts-dev branch August 24, 2024 06:39
stxkxs added a commit to stxkxs/crustacean that referenced this pull request Jan 14, 2026
upgrades sqlx from 0.7.4 to 0.8.6 to fix a critical security vulnerability
where encoding values larger than 4GiB could cause integer overflow in the
protocol length prefix, potentially allowing SQL injection at the protocol level.

vulnerability details:
- CVE: RUSTSEC-2024-0363
- affected versions: sqlx <= 0.8.0
- issue: binary protocol misinterpretation caused by truncating casts
- impact: possible SQL injection via protocol-level smuggling
- presentation: DEF CON 32 - "SQL Injection Isn't Dead"

fix included in sqlx 0.8.1+:
- added deny directives for clippy::cast_possible_truncation
- added deny directives for clippy::cast_possible_wrap
- added deny directives for clippy::cast_possible_loss
- manual audit and fixes for all flagged code

changes:
- update sqlx from 0.7 to 0.8 in Cargo.toml
- remove Cargo.lock from .gitignore (binary project needs reproducible builds)
- commit Cargo.lock to ensure exact secure versions are used

verification:
- all 110 tests passing
- release build successful
- no breaking API changes

references:
- https://rustsec.org/advisories/RUSTSEC-2024-0363
- launchbadge/sqlx#3441
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential vulnerability: overflowing and truncating casts

3 participants