Email me

Rust advisories / rand

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.

Craterand
TypeUnsound
Affected versionsFrom 0.7.0 before 0.8.6; from 0.9.0 before 0.9.3; from 0.10.0 before 0.10.1.
Fixed in0.10.1, 0.8.6, 0.9.3
SeverityLow (GitHub rating)
Published2026-04-09
Last changed2026-07-17
Also known asGHSA-cq8v-f236-94qc
Affected functionsrand::rng, rand::thread_rng

What to do

  1. See which version you have: cargo tree -i rand (it also shows which of your dependencies pulls it in).
  2. 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 example rand = "0.9.3") or update the dependency that pulls it in.
  3. 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 log and thread_rng features are enabled
  • A custom logger is defined
  • The custom logger accesses rand::rng() (previously rand::thread_rng()) and calls any TryRng (previously RngCore) methods on ThreadRng
  • 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 getrandom crate) 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

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?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ