Unsound LowRUSTSEC-2026-0097 · rand
RUSTSEC-2026-0097: Rand is unsound with a custom logger using `rand::rng()`
Short answerrand has an API that can cause undefined behaviour from safe code: Rand is unsound with a custom logger using `rand::rng()`. Fixed in 0.10.1, 0.8.6, 0.9.3.
| Crate | rand |
|---|---|
| Type | Unsound |
| Affected versions | From 0.7.0 before 0.8.6; from 0.9.0 before 0.9.3; from 0.10.0 before 0.10.1. |
| Fixed in | 0.10.1, 0.8.6, 0.9.3 |
| Severity | Low (GitHub rating) |
| Published | 2026-04-09 |
| Last changed | 2026-07-17 |
| Also known as | GHSA-cq8v-f236-94qc |
| Affected functions | rand::rng, rand::thread_rng |
What to do
- See which version you have:
cargo tree -i rand(it also shows which of your dependencies pulls it in). - Update within your version requirement:
cargo update -p rand. If the fix is a newer major or minor than your requirement allows, raise it in Cargo.toml (for examplerand = "0.9.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
It has been reported (by @lopopolo) that the rand library is unsound (i.e. that safe code using the public API can cause Undefined Behaviour) when all the following conditions are met:
- The
logandthread_rngfeatures are enabled - A custom logger is defined
- The custom logger accesses
rand::rng()(previouslyrand::thread_rng()) and calls anyTryRng(previouslyRngCore) methods onThreadRng - The
ThreadRng(attempts to) reseed while called from the custom logger (this happens every 64 kB of generated data) - Trace-level logging is enabled or warn-level logging is enabled and the random source (the
getrandomcrate) is unable to provide a new seed
TryRng (previously RngCore) methods for ThreadRng use unsafe code to cast *mut BlockRng<ReseedingCore> to &mut BlockRng<ReseedingCore>. When all the above conditions are met this results in an aliased mutable reference, violating the Stacked Borrows rules. Miri is able to detect this violation in sample code. Since construction of aliased mutable references is Undefined Behaviour, the behaviour of optimized builds is hard to predict.
References
- Package: crates.io/crates/rand
- Advisory: rustsec.org/advisories/RUSTSEC-2026-0097.html
- Web: github.com/rust-random/rand/pull/1763
From the RustSec Advisory Database (CC0-1.0) via the OSV export, downloaded Oct 24, 2026. Severity score computed from the published CVSS vector.
Up next
Same craterand: security historyEvery advisory for this crate, and whether it is safe to use today.Read it next →Did this answer your question?