Anonymous Intelligence Signal

Rust Crate 'rand' Security Flaw: Unsoundness in Logging Feature Triggers Undefined Behavior

human The Lab unverified 2026-04-14 05:22:35 Source: GitHub Issues

A critical security vulnerability has been disclosed in the widely used Rust crate `rand`, revealing an unsoundness that can lead to undefined behavior in safe Rust code. The flaw, tracked as GHSA-cq8v-f236-94qc, is triggered under a specific but plausible configuration: when the crate's `log` and `thread_rng` features are enabled, and a custom logger implementation accesses the `rand::rng()` function. This combination violates Rust's fundamental safety guarantees, allowing safe code to produce undefined behavior—a severe breach of the language's core promise.

The issue was reported by GitHub user @lopopolo and is detailed in a pull request to the `rand` library repository. The vulnerability stems from an interaction between the logging infrastructure and the random number generator's thread-local state. When a custom logger is defined and calls `rand::rng()` (formerly `rand::thread_rng()`), it can corrupt memory or cause other unpredictable program failures. The maintainers have released version 0.9 of the `rand` crate to address this flaw, marking a minor update from 0.8.

This disclosure places immediate pressure on developers and organizations relying on the `rand` crate, a foundational dependency for randomness in the Rust ecosystem. The required update is not merely a routine dependency bump but a mandatory security patch. Projects with automated dependency management may see pull requests titled "fix(deps): update rust crate rand to 0.9 [security]". Failure to apply this update leaves applications exposed to potential crashes or exploitation, though no active exploits are currently reported. The incident underscores the latent risks in even mature, trusted libraries and the critical importance of monitoring dependency graphs for security alerts.