GHSA-XJ2X-F8QW-37MR: GHSA-xj2x-f8qw-37mr: Denial of Service via Multi-Byte UTF-8 Slicing Panic in Rust bcrypt Crate
GHSA-xj2x-f8qw-37mr: Denial of Service via Multi-Byte UTF-8 Slicing Panic in Rust bcrypt Crate Vulnerability ID: GHSA-XJ2X-F8QW-37MR CVSS Score: 5.3 Published: 2026-12-03 A denial-of-service vulnerability exists in
GHSA-xj2x-f8qw-37mr: Denial of Service via Multi-Byte UTF-8 Slicing Panic in Rust bcrypt Crate
Vulnerability ID: GHSA-XJ2X-F8QW-37MR
CVSS Score: 5.3
Published: 2026-12-03
A denial-of-service vulnerability exists in versions 0.19.0 and 0.19.1 of the Rust bcrypt crate (tracked as GHSA-xj2x-f8qw-37mr and RUSTSEC-2026-0199). When parsing a 60-byte hash string containing multi-byte UTF-8 sequences positioned across internal slice offsets, the split_hash function performs direct string slicing across non-character boundaries. This violation of Rust's UTF-8 string invariants triggers an unhandled thread panic (str::slice_error_fail), enabling attackers who can supply or modify hash strings to crash authentication worker threads or terminate processes configured to abort on panic.
TL;DR
The Rust bcrypt crate (versions 0.19.0 and 0.19.1) fails to verify that input hash strings contain only ASCII characters before performing fixed-index string slicing in split_hash. Passing a 60-byte string with multi-byte UTF-8 characters spanning byte offsets 1, 3, 4, 6, 7, or 22 triggers an immediate runtime panic, resulting in a denial of service. Users should upgrade to version 0.19.2, which rejects non-ASCII input strings prior to slicing.
β οΈ Exploit Status: POC
Technical Details
- Advisory ID: GHSA-xj2x-f8qw-37mr / RUSTSEC-2026-0199
- CWE Classification: CWE-248 (Uncaught Exception)
- CVSS v3.1 Score: 5.3 Medium (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L)
- Affected Component: bcrypt crate (split_hash, bcrypt::verify, HashParts::from_str)
- Affected Versions: >= 0.19.0, < 0.19.2
- Patched Version: 0.19.2
- Primary Impact: Denial of Service via unhandled Rust runtime panic (str::slice_error_fail)
- Exploit Status: Public PoC available in official regression test suite
Affected Systems
- Rust bcrypt crate (crates.io/crates/bcrypt) versions >= 0.19.0, < 0.19.2
-
bcrypt: >= 0.19.0, < 0.19.2 (Fixed in:
0.19.2)
Code Analysis
Commit: 084bedd
Reject non-ASCII 60-byte hash strings in split_hash to avoid UTF-8 character boundary slicing panics and update fuzz target.
diff --git a/fuzz/fuzz_targets/verify.rs b/fuzz/fuzz_targets/verify.rs
index 1117034..b0e0bfb 100644
--- a/fuzz/fuzz_targets/verify.rs
+++ b/fuzz/fuzz_targets/verify.rs
@@ -1,6 +1,10 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
-fuzz_target!(|data: &[u8]| {
- let _ = bcrypt::hash(&data, 4);
+fuzz_target!(|data: (&[u8], &str)| {
+ // Exercise the hash-string parser by feeding both arbitrary
+ // password bytes and arbitrary &str inputs to verify().
+ // The &str input is what reaches split_hash; this is the
+ // surface that #62 (and its regression) lived in.
+ let _ = bcrypt::verify(data.0, data.1);
});
diff --git a/src/lib.rs b/src/lib.rs
index 7edc627..391cb62 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -190,10 +190,12 @@ fn _hash_password(
/// cost, salt and hash
#[cfg(any(feature = "alloc", feature = "std"))]
fn split_hash(hash: &str) -> BcryptResult<HashParts> {
- // A valid bcrypt hash is always exactly 60 bytes:
- if hash.len() != 60 {
+ // A valid bcrypt hash is always exactly 60 ASCII bytes. Rejecting
+ // non-ASCII up front avoids panics from `&str` slicing through the
+ // middle of a multi-byte UTF-8 character (regression of #62).
+ if hash.len() != 60 || !hash.is_ascii() {
return Err(BcryptError::InvalidHash(
- "the hash format is malformed; expected 60 bytes",
+ "the hash format is malformed; expected 60 ASCII bytes",
));
}
Exploit Details
- GitHub: Official regression test containing the 60-byte multi-byte UTF-8 reproduction string ($2b$04$aaaaaaaaaaaaaaaaaaaaaΒ£aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) that triggers str::slice_error_fail.
Mitigation Strategies
- Upgrade the Rust bcrypt crate to version 0.19.2 or higher to enforce upfront ASCII validation in split_hash.
- Pre-validate all hash strings using hash.len() == 60 && hash.is_ascii() before passing them to bcrypt::verify or HashParts::from_str if immediate dependency updates are not feasible.
- Integrate cargo-audit into CI/CD pipelines to automatically detect vulnerable crate versions tracked under RUSTSEC-2026-0199.
Remediation Steps:
- Update Cargo.toml to specify bcrypt = ">= 0.19.2".
- Execute
cargo update -p bcryptto update Cargo.lock to version 0.19.2. - Rebuild and redeploy all dependent binaries and services.
- Run
cargo auditagainst Cargo.lock to confirm RUSTSEC-2026-0199 is no longer flagged.
References
- GitHub Security Advisory: GHSA-xj2x-f8qw-37mr
- RustSec Advisory Database: RUSTSEC-2026-0199
- GitHub Pull Request #103: Reject non-ASCII hashes in split_hash
- Fix Commit 084bedde0aa5501c6d6a0287f6d6857e793fde85
- rust-bcrypt Release v0.19.2
- Historical Issue #62: Character boundary panic in split_hash
- Historical PR #95: Refactoring of split_hash in v0.19.0
Read the full report for GHSA-XJ2X-F8QW-37MR on our website for more details including interactive diagrams and full exploit analysis.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.